为什么我的应用程序在获取和解析JSON数据时会强制关闭?

时间:2013-05-06 02:10:36

标签: android json android-listview android-asynctask android-adapter

首先,我是一个菜鸟。我可能没有正确处理AsyncTask,但这就是我在这里的原因!

我正在尝试创建一个获取,解析和显示JSON数据值的活动。目前我使用Twitter作为占位符,但我将使用Youtube的GData。我真的不太了解Android的JSON库或Async Task,所以这些是我寻找问题的第一个地方。我找不到任何自己。

注意:我在清单中有互联网访问权限。

这是我的活动课程。

public class MainActivity extends ListActivity {

    List<String> videos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        videos = new ArrayList<String>();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new LoadVideos().execute("http://twitter.com/statuses/user_timeline/zacpac2020.json");
    }

    private class LoadVideos extends AsyncTask<String, Integer, String> {

        @Override
        protected String doInBackground(String... params) {
            final ListView listview = (ListView) findViewById(R.id.listview);

            StringBuilder builder = new StringBuilder();
            HttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(params[0]);
            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;
                    while ((line = reader.readLine()) != null) {
                        builder.append(line);
                    }
                } else {
                    Log.e("JSON Parsing", "Failed to download the JSON file.");
                    System.err.println("Failed to download JSON file.");
                }
            } catch (ClientProtocolException e) {
                e.printStackTrace();
                System.err.println("ClientProtocolException in LoadVideos");
            } catch (IOException e) {
                e.printStackTrace();
                System.err.println("ClientProtocolException in LoadVideos");
            }

            String data = builder.toString();
            try {
                JSONArray jsonArray = new JSONArray(data);
                Log.i("Parse JSON", 
                        "Number of entries: " + jsonArray.length());
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    videos.add(jsonObject.toString());
                }
            } catch(Exception e) {
                e.printStackTrace();
            }

            final ArrayAdapter<String> arrayAdapter =      
                    new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1, videos);
            listview.setAdapter(arrayAdapter);

            return "All Done!";
        }
    }

}

LogCat输出

请注意,此输出可能来自之前的运行:

05-05 18:29:10.192: D/dalvikvm(11237): Debugger has detached; object registry had 1 entries
05-05 20:25:26.066: D/AndroidRuntime(15976): Shutting down VM
05-05 20:25:26.066: W/dalvikvm(15976): threadid=1: thread exiting with uncaught exception (group=0x41640930)
05-05 20:25:26.073: E/AndroidRuntime(15976): FATAL EXCEPTION: main
05-05 20:25:26.073: E/AndroidRuntime(15976): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aer.biblealive/com.aer.biblealive.MainActivity}: android.os.NetworkOnMainThreadException
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.ActivityThread.access$600(ActivityThread.java:154)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.os.Looper.loop(Looper.java:137)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.ActivityThread.main(ActivityThread.java:5235)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at dalvik.system.NativeStart.main(Native Method)
05-05 20:25:26.073: E/AndroidRuntime(15976): Caused by: android.os.NetworkOnMainThreadException
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at com.aer.biblealive.MainActivity.onCreate(MainActivity.java:45)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.Activity.performCreate(Activity.java:5104)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-05 20:25:26.073: E/AndroidRuntime(15976):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
05-05 20:25:26.073: E/AndroidRuntime(15976):    ... 11 more
05-05 20:26:56.433: D/AndroidRuntime(16674): Shutting down VM
05-05 20:26:56.433: W/dalvikvm(16674): threadid=1: thread exiting with uncaught exception (group=0x41640930)
05-05 20:26:56.433: E/AndroidRuntime(16674): FATAL EXCEPTION: main
05-05 20:26:56.433: E/AndroidRuntime(16674): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aer.biblealive/com.aer.biblealive.MainActivity}: android.os.NetworkOnMainThreadException
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.ActivityThread.access$600(ActivityThread.java:154)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.os.Looper.loop(Looper.java:137)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.ActivityThread.main(ActivityThread.java:5235)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at dalvik.system.NativeStart.main(Native Method)
05-05 20:26:56.433: E/AndroidRuntime(16674): Caused by: android.os.NetworkOnMainThreadException
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at com.aer.biblealive.MainActivity.onCreate(MainActivity.java:45)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.Activity.performCreate(Activity.java:5104)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-05 20:26:56.433: E/AndroidRuntime(16674):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
05-05 20:26:56.433: E/AndroidRuntime(16674):    ... 11 more
05-05 20:43:01.972: D/AndroidRuntime(17355): Shutting down VM
05-05 20:43:01.972: W/dalvikvm(17355): threadid=1: thread exiting with uncaught exception (group=0x41640930)
05-05 20:43:01.995: E/AndroidRuntime(17355): FATAL EXCEPTION: main
05-05 20:43:01.995: E/AndroidRuntime(17355): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aer.biblealive/com.aer.biblealive.MainActivity}: android.os.NetworkOnMainThreadException
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.ActivityThread.access$600(ActivityThread.java:154)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.os.Looper.loop(Looper.java:137)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.ActivityThread.main(ActivityThread.java:5235)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at dalvik.system.NativeStart.main(Native Method)
05-05 20:43:01.995: E/AndroidRuntime(17355): Caused by: android.os.NetworkOnMainThreadException
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at com.aer.biblealive.MainActivity$1.run(MainActivity.java:50)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at java.lang.Thread.run(Thread.java:856)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at com.aer.biblealive.MainActivity.onCreate(MainActivity.java:83)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.Activity.performCreate(Activity.java:5104)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-05 20:43:01.995: E/AndroidRuntime(17355):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
05-05 20:43:01.995: E/AndroidRuntime(17355):    ... 11 more
05-05 21:02:50.448: D/AndroidRuntime(18004): Shutting down VM
05-05 21:02:50.448: W/dalvikvm(18004): threadid=1: thread exiting with uncaught exception (group=0x41640930)
05-05 21:02:50.448: E/AndroidRuntime(18004): FATAL EXCEPTION: main
05-05 21:02:50.448: E/AndroidRuntime(18004): android.app.SuperNotCalledException: Activity {com.aer.biblealive/com.aer.biblealive.MainActivity} did not call through to super.onCreate()
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2264)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.app.ActivityThread.access$600(ActivityThread.java:154)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.os.Looper.loop(Looper.java:137)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at android.app.ActivityThread.main(ActivityThread.java:5235)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-05 21:02:50.448: E/AndroidRuntime(18004):    at dalvik.system.NativeStart.main(Native Method)
05-05 21:06:36.831: D/libEGL(18374): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
05-05 21:06:36.870: D/libEGL(18374): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
05-05 21:06:36.878: D/libEGL(18374): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
05-05 21:06:37.542: D/OpenGLRenderer(18374): Enabling debug mode 0
05-05 21:06:37.558: I/Choreographer(18374): Skipped 54 frames!  The application may be doing too much work on its main thread.
05-05 21:16:18.816: D/libEGL(18958): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
05-05 21:16:18.855: D/libEGL(18958): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
05-05 21:16:18.855: D/libEGL(18958): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
05-05 21:16:19.300: D/OpenGLRenderer(18958): Enabling debug mode 0
05-05 21:16:19.300: I/Choreographer(18958): Skipped 38 frames!  The application may be doing too much work on its main thread.
05-05 21:16:20.487: E/JSON Parsing(18958): Failed to download the JSON file.
05-05 21:16:20.503: W/System.err(18958): org.json.JSONException: End of input at character 0 of 
05-05 21:16:20.527: W/System.err(18958):    at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
05-05 21:16:20.527: W/System.err(18958):    at org.json.JSONTokener.nextValue(JSONTokener.java:97)
05-05 21:16:20.527: W/System.err(18958):    at org.json.JSONArray.<init>(JSONArray.java:87)
05-05 21:16:20.534: W/System.err(18958):    at org.json.JSONArray.<init>(JSONArray.java:103)
05-05 21:16:20.534: W/System.err(18958):    at com.aer.biblealive.MainActivity$LoadVideos.doInBackground(MainActivity.java:145)
05-05 21:16:20.534: W/System.err(18958):    at com.aer.biblealive.MainActivity$LoadVideos.doInBackground(MainActivity.java:1)
05-05 21:16:20.534: W/System.err(18958):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-05 21:16:20.534: W/System.err(18958):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-05 21:16:20.534: W/System.err(18958):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-05 21:16:20.534: W/System.err(18958):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-05 21:16:20.534: W/System.err(18958):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-05 21:16:20.534: W/System.err(18958):    at java.lang.Thread.run(Thread.java:856)
05-05 21:16:20.534: W/dalvikvm(18958): threadid=11: thread exiting with uncaught exception (group=0x41640930)
05-05 21:16:20.534: E/AndroidRuntime(18958): FATAL EXCEPTION: AsyncTask #1
05-05 21:16:20.534: E/AndroidRuntime(18958): java.lang.RuntimeException: An error occured while executing doInBackground()
05-05 21:16:20.534: E/AndroidRuntime(18958):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.lang.Thread.run(Thread.java:856)
05-05 21:16:20.534: E/AndroidRuntime(18958): Caused by: java.lang.NullPointerException
05-05 21:16:20.534: E/AndroidRuntime(18958):    at com.aer.biblealive.MainActivity$LoadVideos.doInBackground(MainActivity.java:158)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at com.aer.biblealive.MainActivity$LoadVideos.doInBackground(MainActivity.java:1)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-05 21:16:20.534: E/AndroidRuntime(18958):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-05 21:16:20.534: E/AndroidRuntime(18958):    ... 4 more
05-05 21:35:41.362: D/AndroidRuntime(19655): Shutting down VM
05-05 21:35:41.362: W/dalvikvm(19655): threadid=1: thread exiting with uncaught exception (group=0x41640930)
05-05 21:35:41.394: E/AndroidRuntime(19655): FATAL EXCEPTION: main
05-05 21:35:41.394: E/AndroidRuntime(19655): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aer.biblealive/com.aer.biblealive.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ActivityThread.access$600(ActivityThread.java:154)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.os.Looper.loop(Looper.java:137)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ActivityThread.main(ActivityThread.java:5235)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at dalvik.system.NativeStart.main(Native Method)
05-05 21:35:41.394: E/AndroidRuntime(19655): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:335)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.Activity.setContentView(Activity.java:1881)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at com.aer.biblealive.MainActivity.onCreate(MainActivity.java:37)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.Activity.performCreate(Activity.java:5104)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-05 21:35:41.394: E/AndroidRuntime(19655):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
05-05 21:35:41.394: E/AndroidRuntime(19655):    ... 11 more

最新的崩溃:

05-05 21:42:59.503: D/AndroidRuntime(20362): Shutting down VM
05-05 21:42:59.503: W/dalvikvm(20362): threadid=1: thread exiting with uncaught exception (group=0x41640930)
05-05 21:42:59.511: E/AndroidRuntime(20362): FATAL EXCEPTION: main
05-05 21:42:59.511: E/AndroidRuntime(20362): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aer.biblealive/com.aer.biblealive.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ActivityThread.access$600(ActivityThread.java:154)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.os.Looper.loop(Looper.java:137)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ActivityThread.main(ActivityThread.java:5235)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at dalvik.system.NativeStart.main(Native Method)
05-05 21:42:59.511: E/AndroidRuntime(20362): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:335)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.Activity.setContentView(Activity.java:1881)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at com.aer.biblealive.MainActivity.onCreate(MainActivity.java:41)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.Activity.performCreate(Activity.java:5104)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-05 21:42:59.511: E/AndroidRuntime(20362):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
05-05 21:42:59.511: E/AndroidRuntime(20362):    ... 11 more

看起来我在主线程上有网络下载的东西。但我不认为我......

1 个答案:

答案 0 :(得分:1)

由于您的活动是ListActivity,因此会出现以下错误:

  

java.lang.RuntimeException:无法启动活动ComponentInfo {com.aer.biblealive / com.aer.biblealive.MainActivity}:java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为'android.R .id.list'

确保您的R.layout.activity_main列表视图如下:

<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

重要位为android:id属性。

您也可以将extends ListActivity更改为extends Activity并自行处理ListView(正如您似乎正在做的那样)。