致命异常:AsyncTask#1

时间:2013-10-15 23:54:16

标签: java android android-asynctask splash-screen

抱歉,我对Android很新,所以请耐心等待。我正在尝试设置一个在加载JSON时显示的启动画面。当我启动应用程序时,Splash屏幕第一次显示几秒钟,然后崩溃。每当我尝试在此之后启动应用程序时,它甚至在没有显示启动画面的情况下崩溃。

从BaseActivity.java中检索JSONTask类

    public class RetreiveJSONTask extends AsyncTask<String, Void, String> {

    protected String doInBackground(String... urls) {
        Log.d("RetrieveJSONTask", "Begin fetching text.");
        return fetchJSON(urls[0]);
    }

    protected void onPostExecute(String JSON) {

    }

FetchJSON方法:

public String fetchJSON(String URL) {
    StringBuilder builder = new StringBuilder();
    AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
    HttpGet httpGet = new HttpGet(URL);
    // Download JSON file from LocalResearch
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(content));
            String line;
            // Write line-by-line to StringBuilder
            while ((line = reader.readLine()) != null) 
            {
                Log.d(this.toString(), line);
                builder.append(line);
            }
        } else {
            Log.e(this.toString(), URL );
            Log.e(this.toString(), "Failed to download file");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (client != null)
        client.close();
    return builder.toString();
}

SplashActivity onCreate方法:

public static ArrayList<Item> downloadedItems = new ArrayList<Item>();

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    new RetreiveJSONTask() {


        protected void onPostExecute(String JSON)
        {
            downloadedItems = parseJSON ( JSON );

            Intent i = new Intent(SplashActivity.this, MagazinePagesActivity.class);
            startActivity(i);

            // Closes the splash screen
            finish();
        }
    }.execute(sourceURL());
}

第一次崩溃的错误记录:

10-15 19:43:13.504: D/RetrieveJSONTask(769): Begin fetching text.
10-15 19:43:13.673: V/SlidingMenu(769): setting padding!
10-15 19:43:13.744: D/libEGL(769): loaded /system/lib/egl/libEGL_emulation.so
10-15 19:43:13.754: D/(769): HostConnection::get() New Host Connection established 0x2a0ef958, tid 769
10-15 19:43:13.793: D/libEGL(769): loaded /system/lib/egl/libGLESv1_CM_emulation.so
10-15 19:43:13.804: D/libEGL(769): loaded /system/lib/egl/libGLESv2_emulation.so
10-15 19:43:13.874: W/EGL_emulation(769): eglSurfaceAttrib not implemented
10-15 19:43:13.884: D/OpenGLRenderer(769): Enabling debug mode 0
10-15 19:43:13.984: V/CustomViewBehind(769): behind INVISIBLE
10-15 19:43:13.984: W/View(769): requestLayout() improperly called by android.widget.ListView{417003e0 VFED.VC. ......ID 0,0-366,738 #102000a android:id/list} during layout: running second layout pass
10-15 19:43:15.644: W/dalvikvm(769): threadid=11: thread exiting with uncaught exception (group=0x41465700)
10-15 19:43:15.794: E/AndroidRuntime(769): FATAL EXCEPTION: AsyncTask #1
10-15 19:43:15.794: E/AndroidRuntime(769): java.lang.RuntimeException: An error occured     while executing doInBackground()
10-15 19:43:15.794: E/AndroidRuntime(769):  at     android.os.AsyncTask$3.done(AsyncTask.java:299)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-15 19:43:15.794: E/AndroidRuntime(769):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.lang.Thread.run(Thread.java:841)
10-15 19:43:15.794: E/AndroidRuntime(769): Caused by: java.lang.NullPointerException
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.net.URI.parseURI(URI.java:353)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.net.URI.<init>(URI.java:204)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.net.URI.create(URI.java:725)
10-15 19:43:15.794: E/AndroidRuntime(769):  at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
10-15 19:43:15.794: E/AndroidRuntime(769):  at com.dailybruin.bruinframework.base.BaseActivity.fetchJSON(BaseActivity.java:112)
10-15 19:43:15.794: E/AndroidRuntime(769):  at com.dailybruin.bruinframework.base.BaseActivity$RetreiveJSONTask.doInBackground(BaseActivity.java:163)
10-15 19:43:15.794: E/AndroidRuntime(769):  at com.dailybruin.bruinframework.base.BaseActivity$RetreiveJSONTask.doInBackground(BaseActivity.java:1)
10-15 19:43:15.794: E/AndroidRuntime(769):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-15 19:43:15.794: E/AndroidRuntime(769):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-15 19:43:15.794: E/AndroidRuntime(769):  ... 4 more

提前致谢!

1 个答案:

答案 0 :(得分:0)

我似乎传递给fetchJSON的URL为null。