Eu escrevi esse codigo aqui
package com.rms.randow;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Boolean et = false;
int p = 0;
int tent = 0;
int resultado;
int min;
int max;
int value;
public void StartBotton(View v){
TextView result = v.findViewById(R.id.Txt1);
TextView t1 = v.findViewById(R.id.tm);
TextView t2 = v.findViewById(R.id.tx);
TextView t3 = v.findViewById(R.id.t1);
EditText nmin = v.findViewById(R.id.min);
EditText nmax = v.findViewById(R.id.max);
EditText nvalue = v.findViewById(R.id.value);
min = Integer.parseInt(nmin.getText().toString());
max = Integer.parseInt(nmax.getText().toString());
value = Integer.parseInt(nmax.getText().toString());
if(et==false){
Random rand = new Random();
resultado = rand.nextInt((max - min) + 1) + min;
t1.setVisibility(View.INVISIBLE);
t2.setVisibility(View.INVISIBLE);
nmin.setVisibility(View.INVISIBLE);
nmax.setVisibility(View.INVISIBLE);
t3.setVisibility(View.VISIBLE);
nvalue.setVisibility(View.VISIBLE);
et=true;
}else if(et==true){
while (p!=resultado) {
p = value;
if(p==resultado) {
result.setText("Parabens vc acertou, Tentativas: " + tent);
}else if (p<=resultado) {
tent++;
result.setText("Chute um valor maior");
} else {
tent++;
result.setText("Chute um valor menor");
}
}
}
}
}
Porem esta dando esse erro quando eu clico no botão
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rms.randow, PID: 10294
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:446)
at android.view.View.performClick(View.java:6256)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:441)
at android.view.View.performClick(View.java:6256)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.rms.randow.MainActivity.StartBotton(MainActivity.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:441)
at android.view.View.performClick(View.java:6256)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1219)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Se alguem poder me ajudar