0

I have two pages in my application, I am passing one certain value from one page to another:

Class Level Definition: (From the sending class)

 BuyGold50 BG5 = null;

In onCreate() of the same class:

 BG5 = new BuyGold50();

In a certain function of the first activity--Before calling intent to second Activity

 BG5.SetPrice(Gold);

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

Code of the BuyGold50 class

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);
    }

}

Log Cat

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

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

変化する

 tv.setText(X);

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

int を引数として setText に渡すと、内部的に、Android はその ID を持つ文字列を探します。存在しない場合はスローしますResources$NotFoundException

于 2013-07-30T12:08:58.463 に答える
1

でエラーが発生しましcom.Geet.BuyGold50.onCreate(BuyGold50.java:21)た。これについては、logcat を参照してください。この例外は、最初のアクティビティでString名前を指定して渡した が見つからなかったために発生しました。Gold

于 2013-07-30T12:13:06.857 に答える