[问题] 新手求助

楼主: qqaaz (知足常乐)   2014-03-24 16:58:25
如有违板规 烦请提醒
============================
我是刚学习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设计画面中都没看到其他叉叉的错误警告
麻烦各位了 谢谢
楼主: qqaaz (知足常乐)   2014-03-24 17:00:00
在猜会不会是AVD设定问题..但也尝试过好几种设定都不行
作者: cooper6334 (库波)   2014-03-24 17:27:00
Eclipse是IDE,你学的是Android
作者: cooper6334 (库波)   2014-03-24 17:29:00
八成是你xml有问题才会findViewById找不到
楼主: qqaaz (知足常乐)   2014-03-24 17:33:00
谢谢提示 我研究看看XML设定
楼主: qqaaz (知足常乐)   2014-03-24 17:35:00
可以请问怎么判断出findViewById找不到的?
作者: cooper6334 (库波)   2014-03-24 17:36:00
nullpointerexception
楼主: qqaaz (知足常乐)   2014-03-24 17:39:00
谢谢
作者: cooper6334 (库波)   2014-03-24 17:43:00
有AndroidDev板,那边比较适合
楼主: qqaaz (知足常乐)   2014-03-24 17:49:00
谢谢你 如果有违板规 非常抱歉
作者: cooper6334 (库波)   2014-03-24 17:51:00
其实主要是因为这边根本没人XD

Links booklink

Contact Us: admin [ a t ] ucptt.com