在活动之间传递整数值 - Android

时间:2017-04-26 20:56:50

标签: java android

其他卡住的帖子很遗憾无法帮助我。 当我点击按钮同时检查简单的radiobutton时,应用程序停止工作。我不能去看另一个活动。

发件人方:

btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if(radiobutton_arm_triceps_easy.isChecked()) {
                String dene = "my example test";
                int myValue=2;
                Intent intent = new Intent(getApplicationContext(), exercise_arm_triceps_execute.class);
                intent.putExtra("attempt1", myValue );
                startActivity(intent);
            }
        }
    });

接收方:

int receiveValue=getIntent().getIntExtra("attempt1",0);
    textshow.setText(receiveValue);

logcat的

04-26 16:52:06.320 31527-31527/com.example.kerem.tutorial_project E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.example.kerem.tutorial_project, PID: 31527
                                                                            java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kerem.tutorial_project/com.example.kerem.tutorial_project.exercise_arm_triceps_execute}: android.content.res.Resources$NotFoundException: String resource ID #0x2
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                                                                                at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:136)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                             Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2
                                                                                at android.content.res.Resources.getText(Resources.java:244)
                                                                                at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
                                                                                at android.widget.TextView.setText(TextView.java:3888)
                                                                                at com.example.kerem.tutorial_project.exercise_arm_triceps_execute.onCreate(exercise_arm_triceps_execute.java:28)
                                                                                at android.app.Activity.performCreate(Activity.java:5231)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                                at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:136) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                                at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                                at dalvik.system.NativeStart.main(Native Method) 

1 个答案:

答案 0 :(得分:1)

使用

textshow.setText(String.valueOf(receiveValue));