当前位置: 首页 > 知识库问答 >
问题:

Android.content.res.resurces$NotFoundException:字符串资源ID#0x0[重复]

麹繁
2023-03-14

请帮帮我,我想不出为什么这个错误。就在一天前它起作用了。我理解it serches for和id ist是存在的,但id在XML中。它在oncreate方法中给出了错误:

public class DoExamActivity extends Activity {
    private DatabaseHandler db;
    private EditText votoET;
    @Override
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.do_exam);
        Bundle bundle = getIntent().getExtras();

        db = new DatabaseHandler(getApplicationContext());

        try {
            transcript = new JSONObject(bundle.getString("transcript"));
            exam = new JSONObject(bundle.getString("exam"));
            teacher = new JSONObject(bundle.getString("teacher"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        votoET = (EditText) findViewById(R.id.examValueET); //here

这是他找不到的编辑文本的do_exam.xml。你可以看到id在那里!

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:layout_height="30dp"
                android:layout_gravity="left|center_vertical"
                android:layout_weight="1"
                android:background="@color/ios7orange"
                android:contentDescription="@string/textValueDescr"
                android:src="@drawable/rating_star" />

            <TextView
                android:layout_height="50dp"
                android:layout_weight="1" />

            <EditText
                android:id="@+id/examValueET"
                android:layout_height="40dp"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="10dp"
                android:layout_weight="5"
                android:background="@drawable/rounded_edittext"
                android:hint="@string/examValueHint"
                android:inputType="text"
                android:maxLines="1" />
        </TableRow>
11-13 07:04:15.457: E/AndroidRuntime(1091): FATAL EXCEPTION: main
11-13 07:04:15.457: E/AndroidRuntime(1091): java.lang.RuntimeException: Unable to start     activity ComponentInfo{com.utaa.iesami/com.utaa.iesami.activity.DoExamActivity}:     android.content.res.Resources$NotFoundException: String resource ID #0x0
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.ActivityThread.access$600(ActivityThread.java:141)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.os.Looper.loop(Looper.java:137)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.ActivityThread.main(ActivityThread.java:5103)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     java.lang.reflect.Method.invokeNative(Native Method)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     java.lang.reflect.Method.invoke(Method.java:525)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     dalvik.system.NativeStart.main(Native Method)
11-13 07:04:15.457: E/AndroidRuntime(1091): Caused by:     android.content.res.Resources$NotFoundException: String resource ID #0x0
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.content.res.Resources.getText(Resources.java:239)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.widget.TextView.setText(TextView.java:3844)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     com.utaa.iesami.activity.DoExamActivity.onCreate(DoExamActivity.java:61)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.Activity.performCreate(Activity.java:5133)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-13 07:04:15.457: E/AndroidRuntime(1091):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-13 07:04:15.457: E/AndroidRuntime(1091):     ... 11 more

代码更新

我已经打扫过了,什么都没有。它的活动太大了,我添加的代码直到行的错误。所以我对所有的ID都使用了大写,它工作了两个星期,现在它给我的错误只是在ET上。

共有1个答案

秦天宇
2023-03-14

我的错误。我弄错了行,错误来自textview.settext(int),其中我必须设置textview.settext(string.valueof(int))

 类似资料: