这是一个与 Android 开发相关的问题。我在 Windows 7 64bits 中使用 ADT 和 Eclipse Indigo
首先我们有xml布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
</LinearLayout>
其次,我们有一个引用上述 xml 文件的类
package com.example.test_table;
import android.os.Bundle;
import android.app.Activity;
public class Home extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
}
第三名,我们在类 Home 的清单中得到了声明
<activity
android:name="com.example.test_table.Home"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
然后,当我尝试运行时,Eclipse 返回一个空指针异常。但是当我从 xml 布局文件中删除 EditText 时,应用程序可以工作。这个问题突然出现在我的电脑上,我正在尝试解决它。
日志猫:
02-27 22:42:39.051: E/AndroidRuntime(12164): FATAL EXCEPTION: main
02-27 22:42:39.051: E/AndroidRuntime(12164): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.test_table/com.example.test_table.Home}: java.lang.NullPointerException
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.access$600(ActivityThread.java:128)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.os.Looper.loop(Looper.java:137)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.main(ActivityThread.java:4514)
02-27 22:42:39.051: E/AndroidRuntime(12164): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 22:42:39.051: E/AndroidRuntime(12164): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-27 22:42:39.051: E/AndroidRuntime(12164): at dalvik.system.NativeStart.main(Native Method)
02-27 22:42:39.051: E/AndroidRuntime(12164): Caused by: java.lang.NullPointerException
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.sec.clipboard.ClipboardExManager.updateData(ClipboardExManager.java:241)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.widget.EditText.onFocusChanged(EditText.java:134)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.handleFocusGainInternal(View.java:3727)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.requestFocus(View.java:5420)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.requestFocus(View.java:5370)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.requestFocus(View.java:5348)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.parseRequestFocus(LayoutInflater.java:753)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.Activity.setContentView(Activity.java:1835)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.example.test_table.Home.onCreate(Home.java:11)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.Activity.performCreate(Activity.java:4465)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
02-27 22:42:39.051: E/AndroidRuntime(12164): ... 11 more
那么,我想知道是什么导致 ADT 停止识别 Edittext?