这是我的代码:
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.translate_activity);
mFromEditText = (EditText) findViewById(R.id.input);
mToEditText = (EditText) findViewById(R.id.translation);
mFromButton = (Button) findViewById(R.id.from);
mToButton = (Button) findViewById(R.id.to);
mTranslateButton = (Button) findViewById(R.id.button_translate);
mSwapButton = (Button) findViewById(R.id.button_swap);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
mStatusView = (TextView) findViewById(R.id.status);
//
// Install the language adapters on both the From and To spinners.
//
//****************this is line 132 from the error log************************************//
mFromButton.setOnClickListener(mClickListener);
mToButton.setOnClickListener(mClickListener);
mTranslateButton.setOnClickListener(this);
mSwapButton.setOnClickListener(this);
mFromEditText.selectAll();
connectToTranslateService();
}
******************************************************************************************
这是 log.txt (我得到的错误):
06-19 18:11:39.171: D/AndroidRuntime(1899): 关闭虚拟机 06-19 18:11:39.171: W/dalvikvm(1899): threadid=1: 线程以未捕获的异常退出 (group=0x40a71930) 06-19 18:11:39.191:E/AndroidRuntime(1899):致命异常:主要 06-19 18:11:39.191: E/AndroidRuntime(1899): java.lang.RuntimeException: 无法启动活动 ComponentInfo{org.example.SmsTranslate/org.example.SmsTranslate.TranslateActivity}: java.lang.NullPointerException 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.ActivityThread.access$600(ActivityThread.java:141) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.os.Handler.dispatchMessage(Handler.java:99) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.os.Looper.loop(Looper.java:137) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.ActivityThread.main(ActivityThread.java:5041) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 java.lang.reflect.Method.invokeNative(Native Method) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 java.lang.reflect.Method.invoke(Method.java:511) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 dalvik.system.NativeStart.main(Native Method) 06-19 18:11:39.191:E/AndroidRuntime(1899):原因:java.lang.NullPointerException 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 org.example.SmsTranslate.TranslateActivity.onCreate(TranslateActivity.java:132) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.Activity.performCreate(Activity.java:5104) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 06-19 18:11:39.191: E/AndroidRuntime(1899): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 06-19 18:11:39.191: E/AndroidRuntime(1899): ... 11 更多 ****************************************************** ***********************************