我在解析来自 am url 的内容时遇到异常。我得到的例外如下。
10-16 12:46:59.373: E/AndroidRuntime(4362): FATAL EXCEPTION: Thread-12
10-16 12:46:59.373: E/AndroidRuntime(4362): java.lang.NullPointerException
10-16 12:46:59.373: E/AndroidRuntime(4362): at com.android.gyan.SearchResults$4.run(SearchResults.java:162)
10-16 12:46:59.373: E/AndroidRuntime(4362): at java.lang.Thread.run(Thread.java:1019)
10-16 12:46:59.783: E/WindowManager(4362): Activity com.android.gyan.SearchResults has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4056d3b0 that was originally added here
10-16 12:46:59.783: E/WindowManager(4362): android.view.WindowLeaked: Activity com.android.gyan.SearchResults has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4056d3b0 that was originally added here
10-16 12:46:59.783: E/WindowManager(4362): at android.view.ViewRoot.<init>(ViewRoot.java:258)
10-16 12:46:59.783: E/WindowManager(4362): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
10-16 12:46:59.783: E/WindowManager(4362): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
10-16 12:46:59.783: E/WindowManager(4362): at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.Dialog.show(Dialog.java:241)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ProgressDialog.show(ProgressDialog.java:107)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ProgressDialog.show(ProgressDialog.java:95)
10-16 12:46:59.783: E/WindowManager(4362): at com.android.gyan.SearchResults.ParsingCall(SearchResults.java:147)
10-16 12:46:59.783: E/WindowManager(4362): at com.android.gyan.SearchResults.onCreate(SearchResults.java:137)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-16 12:46:59.783: E/WindowManager(4362): at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 12:46:59.783: E/WindowManager(4362): at android.os.Looper.loop(Looper.java:130)
10-16 12:46:59.783: E/WindowManager(4362): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-16 12:46:59.783: E/WindowManager(4362): at java.lang.reflect.Method.invokeNative(Native Method)
10-16 12:46:59.783: E/WindowManager(4362): at java.lang.reflect.Method.invoke(Method.java:507)
10-16 12:46:59.783: E/WindowManager(4362): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-16 12:46:59.783: E/WindowManager(4362): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-16 12:46:59.783: E/WindowManager(4362): at dalvik.system.NativeStart.main(Native Method)
我用来解析的是这个。
public void ParsingCall(final String urlFirst) {
final Bundle b = new Bundle();
progressDialog = ProgressDialog.show(SearchResults.this, " ",
"Searching.....", true, false);
progressDialog.setIcon(-1);
progressDialog.setIcon(R.drawable.logo);
new Thread(new Runnable() {
public void run() {
LyricsData dataContent = null;
dataContent = LyricsParse.Parse(urlFirst);
Message msg = new Message();
{
{
if(dataContent.contentList != null) {
b.putStringArrayList("contentList",
dataContent.contentList);
}else {
//dataContent.contentList[0] = {"No value"};
b.putString("contentList",
"No value");
}
if(dataContent.optionNameArrayList != null)
b.putStringArrayList("optionNameArrayList",
dataContent.optionNameArrayList);
else
b.putString("optionNameArrayList",
"No value");
}
}
msg.setData(b);
handler.sendMessage(msg);
}
}).start();
}
我还编写了一个处理程序,它将获取消息并从中获取数据并将这些设置为我在活动中拥有的视图。请注意,并非每次都会出现此异常。它变得非常罕见。