I tried to develop a small game: clicker . The compilation is successful, the installation on the device is also successful. However, after clicking on the button, the application crashes. Please help. Here is the whole code:
package com.arslee07.eliteclicker; import android.annotation.SuppressLint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { public int clicks = 0; Button btnClick; TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnClick = (Button) findViewById(R.id.btnClick); View.OnClickListener oclBtnClick = new View.OnClickListener() { @SuppressLint("SetTextI18n") @Override public void onClick(View v) { clicks++; //clicks = Integer.parseInt(textView.getText().toString()); textView.setText("ELITE CLICKS: "+ clicks); } }; btnClick.setOnClickListener(oclBtnClick); } }
textView.setText(), since the object has not been initialized. The fact that you do not see an error or do not know where to look does not mean that it does not exist - pavlofff