Android应用程序强制关闭错误

时间:2012-04-08 19:21:42

标签: android forceclose

我已将Results类添加到Android Manifest,所以是的,您可以将其从列表中删除。 这是我设定方法的错误吗?

    package com.kenning.foreveralone;


    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.EditText;
    import android.widget.TextView;

    public class Results extends Activity{

        EditText fbFriends;
        TextView resulting;
        String value;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.rslt);
            TextView resulting = (TextView) findViewById(R.id.result);
            EditText fbFriends = (EditText) findViewById(R.id.noFacebookFriends);
            String value = fbFriends.getText().toString();
            resulting.setText("Your score is " + value);
        }



    }

当我开始上课时,似乎总是强行关闭我的应用程序。谁能告诉我我做错了什么?

这是日志猫:

04-08 20:05:24.169: E/AndroidRuntime(589): FATAL EXCEPTION: main
04-08 20:05:24.169: E/AndroidRuntime(589): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kenning.foreveralone/com.kenning.foreveralone.Results}: java.lang.NullPointerException
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.os.Looper.loop(Looper.java:123)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-08 20:05:24.169: E/AndroidRuntime(589):  at java.lang.reflect.Method.invokeNative(Native Method)
04-08 20:05:24.169: E/AndroidRuntime(589):  at java.lang.reflect.Method.invoke(Method.java:521)
04-08 20:05:24.169: E/AndroidRuntime(589):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-08 20:05:24.169: E/AndroidRuntime(589):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-08 20:05:24.169: E/AndroidRuntime(589):  at dalvik.system.NativeStart.main(Native Method)
04-08 20:05:24.169: E/AndroidRuntime(589): Caused by: java.lang.NullPointerException
04-08 20:05:24.169: E/AndroidRuntime(589):  at com.kenning.foreveralone.Results.onCreate(Results.java:20)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-08 20:05:24.169: E/AndroidRuntime(589):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-08 20:05:24.169: E/AndroidRuntime(589):  ... 11 more

2 个答案:

答案 0 :(得分:0)

你的OnCreate中某处有NullPointerException。我猜你的rslt.xml布局中的id是错误的,因此结果和fbFriends为null,或者fbFriends中没有任何文本,因此getText()返回null。

答案 1 :(得分:0)

这是onCreate中的空指针异常,那么为什么不尝试单步执行onCreate来查看哪个变量为空?

那就是说,我猜R.id.noFacebookFriends不属于R.layout.rslt