0

我的应用程序中有两个页面,我将一个特定值从一个页面传递到另一个页面:

类级别定义:(来自发送类)

 BuyGold50 BG5 = null;

在同一类的 onCreate() 中:

 BG5 = new BuyGold50();

在第一个Activity的某个函数中--调用intent到第二个Activity之前

 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
4

3 回答 3

1

改变

 tv.setText(X);

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

如果您将 int 作为参数传递给 setText,则在内部,android 将查找具有该 id 的字符串。如果它不存在,它将抛出Resources$NotFoundException

于 2013-07-30T12:08:58.463 回答
1

您正在尝试将 int 值设置为

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

所以试着像这样给 int 值

.setText(""+intvalue) or Toast.makeText(context,""+intvalue,..)
于 2013-07-30T12:10:29.880 回答
1

错误发生在com.Geet.BuyGold50.onCreate(BuyGold50.java:21),请参阅您的 logcat。由于未找到您在第一个活动中String命名的 a ,因此发生此异常。Gold

于 2013-07-30T12:13:06.857 回答