0
的logcat:應用DecRa(過程com.Decra)已停止unexpectedly.Please再試
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.Decra/com.Decra.DecRaActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
代碼:
TextView dectv=(TextView)findViewById(R.id.dec);
TextView ratv=(TextView)findViewById(R.id.ra);
TextView result=(TextView)findViewById(R.id.result);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=new Button(this);
btn.setOnClickListener(this);
}
當啓動它的作用下與下面的錯誤關閉應用程序:
the application DecRa (process com.Decra) has stopped unexpectedly.Please try again.
並且在編譯時沒有錯誤呃,所以它必須是運行時錯誤。 但我不明白錯誤的含義!而我所瞭解的是其中一個錯誤是指findViewById
。
檢查Activity.java:1637 – theAlse
是什麼Activity.java:1637? –
是否存在dectv,ratv和結果集會?在每行後面放一個日誌,看看它有多遠! – theAlse