Please tell me the cause of the Android putExtra code execution error

Asked 1 years ago, Updated 1 years ago, 82 views

Blockquote

int to save the value of) change and there was an error in the process by which you store the value and activity to the value of an App is forced exit in the process I think. I don't know the cause. Please let me know. Generous spacing gives healthier and value which is an error in value also went with the ID code and switching activity, the app will be forcibly shut down.

Main Activity Java

EditText editTextNo = (EditText) findViewById(R.id.editTextNo) ; String strNo = editTextNo.getText().toString() ; if (!strNo.isEmpty() && strNo.matches("[0-9]*$")) { // check numbers by RegEx. intent.putExtra("contact_no", Integer.parseInt(strNo)) ; } } else { intent.putExtra("contact_no", 0) ; }

[0-9]*$"))

Contact Activity Java

TextView textNo = (TextView)findViewById(R.id.editTextNo); int num = intent.getIntExtra("contact_no",0); textNo.setText(Integer.toString(num));

< Error values >

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.putextratest, PID: 12684 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.putextratest/com.example.putextratest.ContactActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3333) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7464) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.putextratest.ContactActivity.onCreate(ContactActivity.java:19) at android.app.Activity.performCreate(Activity.java:7990) at android.app.Activity.performCreate(Activity.java:7979) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3308) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:216)  at android.app.ActivityThread.main(ActivityThread.java:7464)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955) 

android code errorcode error

2022-09-21 11:17

1 Answers

EditText editTextNo = (EditText) findViewById(R.id.editTextNo) 

TextView textNo = (TextView)findViewById(R.id.editTextNo);

Both have the same ID as editTextNo.

TextView ID appears to be a typo.


2022-09-21 11:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.