I want to change activity with startActivity(intent), but i got a NullpointerException.
I try everything what I read in the web.
My Code
public void starteFehler(int fall){
Intent fehler = new Intent(this, Fehlermeldung.class);
fehler.putExtra("fall", fall);
startActivity(fehler);
}
LogCat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.vtas_kassenterminal, PID: 27284
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:4622)
at android.app.Activity.startActivityForResult(Activity.java:4579)
at android.app.Activity.startActivity(Activity.java:4940)
at android.app.Activity.startActivity(Activity.java:4908)
at com.example.vtas_kassenterminal.Startbildschirm.starteFehler(Startbildschirm.java:172)
at com.example.vtas_kassenterminal.Startbildschirm$4.onResponse(Startbildschirm.java:142)
at com.example.vtas_kassenterminal.Startbildschirm$4.onResponse(Startbildschirm.java:128)
at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:83)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:106)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Here is the Fehlermedlung.class
public class Fehlermeldung extends AppCompatActivity {
private long zeit;
public int fall;
private Handler handler;
Parameter parameter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fehlermeldung);
zeit = parameter.dauerFehl;
TextView textView_meldung = findViewById(R.id.textView_meldung);
TextView textView_id = findViewById(R.id.textView_id);
TextView textView_loesung = findViewById(R.id.textView_loesung);
handler = new Handler();
final Intent startbildschirm = new Intent(this, Startbildschirm.class);
Runnable goBack = new Runnable() {
@Override
public void run() {
startActivity(startbildschirm);
}
};
fall = getIntent().getIntExtra("fall", 0);
switch (fall){
case 0: textView_meldung.setText("Interner Fehler");
textView_id.setText("");
textView_loesung.setText("Bitte sprechen Sie das Personal am Empfang an.");
handler.postDelayed(goBack, zeit);
break;
case -1:textView_meldung.setText("Benutzer unbekannt");
textView_id.setText("ID: XXXXXXX");
textView_loesung.setText("Bitte sprechen Sie das Personal am Empfang an.");
handler.postDelayed(goBack, zeit);
break;
case -2:textView_meldung.setText("Chip ID bereits vorhanden");
textView_id.setText("");
textView_loesung.setText("Bitte nutzen Sie eine andere Chip ID.");
handler.postDelayed(goBack, zeit);
break;
case -3:textView_meldung.setText("Keine Serververbindung möglich.");
textView_id.setText("");
textView_loesung.setText("Bitte versuchen Sie es zu einem späteren Zeitpunkt erneut oder sprechen das Personal am Empfang an.");
handler.postDelayed(goBack, zeit);
break;
}
}
}
In this line, it seems zeit = parameter.dauerFehl;
parameter is null.
I think u are not initialized Parameter class in your Fehlermedlung.class u should intialize
Parameter parm=new Parameter ();
parm..dauerFehl;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.