2013-07-30 63 views
0

我在我的應用程序兩頁,我從一個頁面傳遞一個特定值到另一個:將值從一個活動傳遞到另一個活動,使用Object並獲取資源未找到錯誤。

職業等級定義:(從發送級別)

BuyGold50 BG5 = null; 

在的onCreate()同一類:

BG5 = new BuyGold50(); 

在第一個活動的特定功能 - 在調用意圖第二活動

BG5.SetPrice(Gold); 

======================================== ========================================

BuyGold50類的代碼

public class BuyGold50 extends Activity { 

    public static String B; 
    static int X; 

    public void SetPrice(String Price) { 
     B = Price; 
     X = Integer.parseInt(B); 
    } 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.buy_gold50); 
     TextView tv = (TextView) findViewById(R.id.textView1); 
     tv.setText(X); 
    } 

} 

登錄貓

07-30 11:59:07.304: E/AndroidRuntime(615): FATAL EXCEPTION: main 
07-30 11:59:07.304: E/AndroidRuntime(615): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Geet/com.Geet.BuyGold50}: android.content.res.Resources$NotFoundException: String resource ID #0xb34 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.os.Handler.dispatchMessage(Handler.java:99) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.os.Looper.loop(Looper.java:123) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.ActivityThread.main(ActivityThread.java:3683) 
07-30 11:59:07.304: E/AndroidRuntime(615): at java.lang.reflect.Method.invokeNative(Native Method) 
07-30 11:59:07.304: E/AndroidRuntime(615): at java.lang.reflect.Method.invoke(Method.java:507) 
07-30 11:59:07.304: E/AndroidRuntime(615): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
07-30 11:59:07.304: E/AndroidRuntime(615): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
07-30 11:59:07.304: E/AndroidRuntime(615): at dalvik.system.NativeStart.main(Native Method) 
07-30 11:59:07.304: E/AndroidRuntime(615): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0xb34 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.content.res.Resources.getText(Resources.java:201) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.widget.TextView.setText(TextView.java:2857) 
07-30 11:59:07.304: E/AndroidRuntime(615): at com.Geet.BuyGold50.onCreate(BuyGold50.java:21) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
07-30 11:59:07.304: E/AndroidRuntime(615): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
07-30 11:59:07.304: E/AndroidRuntime(615): ... 11 more 

回答

1

變化

tv.setText(X); 

tv.setText(String.valueOf(X)); 

如果你傳遞一個int參數的setText,在內部,Android將尋找與該ID的字符串。如果它不存在,它會拋出Resources$NotFoundException

+1

謝謝,它現在完美:) – user2613996

1

您試圖在

tetview.setText() or Toast.makeText(), which it will take as string resource id. 

設置int值,所以儘量在給int值這樣

.setText(""+intvalue) or Toast.makeText(context,""+intvalue,..) 
+0

非常感謝,我今天知道文本視圖只需要一個字符串值,知道吐司的東西! – user2613996

1

錯誤發生在com.Geet.BuyGold50.onCreate(BuyGold50.java:21),請參閱logcat for thi秒。 發生此異常是因爲您未在第一次活動中通過名爲GoldString這一事實。

+0

感謝您的指導! – user2613996

相關問題