-3

这是我在开始 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();
        }
    }); 

你能帮助我吗?

4

3 回答 3

1

你还没有初始化arc。先创建arc的对象,然后试试。

arc = new ApiRestClient();

在使用之前添加上面的代码行arc

于 2013-01-18T13:07:32.003 回答
1

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

arc = new ApiRestClient();
arc.get("uebersicht.json", params, new JsonHttpResponseHandler() {
    public void onSuccess(String response) {
        text.setText(response);
        pDialog.dismiss();
    }
}); 
于 2013-01-18T13:06:22.463 回答
0

第 1 步:阅读堆栈跟踪

第 2 步:识别异常

第 3 步:识别导致异常的类、方法和行

第 4 步:找到修复程序

第 5 步:如果找不到修复程序,请提出一个问题,提及前面所有 4 个步骤的结果

于 2013-01-18T15:01:08.333 回答