2017-04-26 167 views
0

不幸的是,其他卡住的帖子不能帮助我。 当我点击按钮,而简单的单选按钮被选中时,应用程序停止工作。我无法去看另一个活动。活动之间传递整数值 - Android

发送方:

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) 
+0

崩溃? show logcat – yanivtwin

+0

刚刚添加! – user3469764

+0

好吧,你可以编辑你的问题,现在显示:onCreate(exercise_arm_triceps_execute.java:28)显示该类的整个onCreate方法 – yanivtwin

回答

1

使用

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

感谢Martin!固定 – user3469764

+0

太棒了,如果有帮助,请考虑将答案标记为已接受 –