Android错误致命异常:主要

时间:2013-01-18 13:04:20

标签: android fatal-error

这是我在启动aysncronic任务时遇到的错误。

01-18 12:21:40.379: E/AndroidRuntime(1102): FATAL EXCEPTION: main
01-18 12:21:40.379: E/AndroidRuntime(1102): java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.edocsyl.spesen/ch.edocsyl.spesen.SpesenActivity}: java.lang.NullPointerException
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.os.Looper.loop(Looper.java:137)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.ActivityThread.main(ActivityThread.java:5039)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at java.lang.reflect.Method.invokeNative(Native Method)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at java.lang.reflect.Method.invoke(Method.java:511)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at dalvik.system.NativeStart.main(Native Method)
01-18 12:21:40.379: E/AndroidRuntime(1102): Caused by: java.lang.NullPointerException
01-18 12:21:40.379: E/AndroidRuntime(1102):     at ch.edocsyl.spesen.SpesenActivity.onCreate(SpesenActivity.java:87)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.Activity.performCreate(Activity.java:5104)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-18 12:21:40.379: E/AndroidRuntime(1102):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-18 12:21:40.379: E/AndroidRuntime(1102):     ... 11 more

我的代码:

public class SpesenActivity extends Activity {

ProgressDialog pDialog;
static ApiRestClient arc;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_spesen);

    final TextView text = (TextView) findViewById(R.id.textView1);

    RequestParams params = new RequestParams();
    //params.put("username", "james");

    pDialog = new ProgressDialog(SpesenActivity.this);
    pDialog.setMessage("Loading...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();

    arc.get("uebersicht.json", params, new JsonHttpResponseHandler() {
        public void onSuccess(String response) {
            text.setText(response);
            pDialog.dismiss();
        }
    }); 

你能帮助我吗?

3 个答案:

答案 0 :(得分:1)

您应该在使用之前初始化arc

arc = new ApiRestClient();
arc.get("uebersicht.json", params, new JsonHttpResponseHandler() {
    public void onSuccess(String response) {
        text.setText(response);
        pDialog.dismiss();
    }
}); 

答案 1 :(得分:1)

您尚未初始化arc。首先创建弧的对象,然后尝试它。

arc = new ApiRestClient();

在使用arc之前添加以上代码行。

答案 2 :(得分:0)

第1步:阅读stacktrace

第2步:确定异常

步骤3:识别导致异常的类,方法和行

第4步:找到修复

第5步:如果您无法找到解决方法,请提出一个问题,提及前4个步骤的结果