2017-04-26 173 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

太棒了,如果有幫助,請考慮將答案標記爲已接受 –