[問題] 新手求助

看板Eclipse作者 (知足常樂)時間10年前 (2014/03/24 16:58), 編輯推噓3(307)
留言10則, 2人參與, 最新討論串1/1
如有違板規 煩請提醒 ============================ 我是剛學習eclipes的新手 安裝完主程式 開啟第一個內建的app 成功輸出apk到手機 可以正常開啟那個hello world的原始app 開始學習第二步 製作button來改變"hello world"文字 完全照教學的步驟輸入程式碼 關鍵內容如下 ========================================================== MyButton=(Button)findViewById(R.id.button1); tv1=(TextView)findViewById(R.id.textview1); MyButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { tv1.setText("測試測試"); }} ); ========================================================== 但不管怎麼做 一開啟app就會跳 unfortunately xxx has stopped 以下是錯誤log 但我看不懂.. 請大家幫我看看出了什麼問題 03-24 04:41:22.210: W/dalvikvm(911): threadid=1: thread exiting with uncaught exception (group=0xb4a89ba8) 03-24 04:41:22.220: E/AndroidRuntime(911): FATAL EXCEPTION: main 03-24 04:41:22.220: E/AndroidRuntime(911): Process: hhhr.ff, PID: 911 03-24 04:41:22.220: E/AndroidRuntime(911): java.lang.RuntimeException: Unable to start activity ComponentInfo{hhhr.ff/hhhr.ff.MainActivity}: java.lang.NullPointerException 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.ActivityThread.access$800(ActivityThread.java:135) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.os.Handler.dispatchMessage(Handler.java:102) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.os.Looper.loop(Looper.java:136) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.ActivityThread.main(ActivityThread.java:5017) 03-24 04:41:22.220: E/AndroidRuntime(911): at java.lang.reflect.Method.invokeNative(Native Method) 03-24 04:41:22.220: E/AndroidRuntime(911): at java.lang.reflect.Method.invoke(Method.java:515) 03-24 04:41:22.220: E/AndroidRuntime(911): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 03-24 04:41:22.220: E/AndroidRuntime(911): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 03-24 04:41:22.220: E/AndroidRuntime(911): at dalvik.system.NativeStart.main(Native Method) 03-24 04:41:22.220: E/AndroidRuntime(911): Caused by: java.lang.NullPointerException 03-24 04:41:22.220: E/AndroidRuntime(911): at hhhr.ff.MainActivity.onCreate(MainActivity.java:24) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.Activity.performCreate(Activity.java:5231) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 03-24 04:41:22.220: E/AndroidRuntime(911): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 03-24 04:41:22.220: E/AndroidRuntime(911): ... 11 more ps.在eclipes設計畫面中都沒看到其他叉叉的錯誤警告 麻煩各位了 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.36.209.11

03/24 17:00, , 1F
在猜會不會是AVD設定問題..但也嘗試過好幾種設定都不行
03/24 17:00, 1F

03/24 17:27, , 2F
Eclipse是IDE,你學的是Android
03/24 17:27, 2F

03/24 17:29, , 3F
八成是你xml有問題才會findViewById找不到
03/24 17:29, 3F

03/24 17:33, , 4F
謝謝提示 我研究看看XML設定
03/24 17:33, 4F

03/24 17:35, , 5F
可以請問怎麼判斷出findViewById找不到的?
03/24 17:35, 5F

03/24 17:36, , 6F
nullpointerexception
03/24 17:36, 6F

03/24 17:39, , 7F
謝謝
03/24 17:39, 7F

03/24 17:43, , 8F
有AndroidDev板,那邊比較適合
03/24 17:43, 8F

03/24 17:49, , 9F
謝謝你 如果有違板規 非常抱歉
03/24 17:49, 9F

03/24 17:51, , 10F
其實主要是因為這邊根本沒人XD
03/24 17:51, 10F
文章代碼(AID): #1JB_EqnW (Eclipse)
文章代碼(AID): #1JB_EqnW (Eclipse)