首先,我是菜鸟。我可能没有正确处理 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
看起来我让网络在主线程上下载了一些东西。但我觉得我不会...