请帮助我,我无法弄清楚为什么会出现这个错误。就在一天前,它起作用了。我了解它的搜索和 id ist'n 存在,但 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
我在 R 类中搜索,它的 id 在EditText
那里并且不同于 0。那么为什么会出现这个错误?
代码更新
我已经打扫过了,什么都没有。活动它太大了,我添加了代码直到错误的行。所以我对所有 ID 都使用了上限,它工作了两周,现在它只在那个 ET 上给了我错误。