我想: 使用Jsoup lib解析url,从url获取一些数据,然后在其他方法中使用它们。
@Override
protected void onPostExecute(Object result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if(pdialog.isShowing())
pdialog.cancel();
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
pdialog = new ProgressDialog(context);
pdialog.setCancelable(false);
pdialog.setMessage("Loading");
pdialog.show();
}
@Override
protected Object doInBackground(Object... params) {
try {
doc = Jsoup.connect("http://www.interdag.ru/afisha").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
我怎样才能获得Jsoup.connect()。get()结果?
此代码返回错误:
12-29 06:34:45.214: E/WindowManager(1462): Activity com.example.afisha.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40fc2db8 that was originally added here
12-29 06:34:45.214: E/WindowManager(1462): android.view.WindowLeaked: Activity com.example.afisha.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40fc2db8 that was originally added here
12-29 06:34:45.214: E/WindowManager(1462): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:343)
12-29 06:34:45.214: E/WindowManager(1462): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:245)
12-29 06:34:45.214: E/WindowManager(1462): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
12-29 06:34:45.214: E/WindowManager(1462): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
12-29 06:34:45.214: E/WindowManager(1462): at android.view.Window$LocalWindowManager.addView(Window.java:537)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.Dialog.show(Dialog.java:274)
12-29 06:34:45.214: E/WindowManager(1462): at com.example.afisha.GetData.onPreExecute(GetData.java:46)
12-29 06:34:45.214: E/WindowManager(1462): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
12-29 06:34:45.214: E/WindowManager(1462): at android.os.AsyncTask.execute(AsyncTask.java:511)
12-29 06:34:45.214: E/WindowManager(1462): at com.example.afisha.GetData.getData(GetData.java:65)
12-29 06:34:45.214: E/WindowManager(1462): at com.example.afisha.MainActivity.onCreate(MainActivity.java:23)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.Activity.performCreate(Activity.java:4465)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-29 06:34:45.214: E/WindowManager(1462): at android.os.Handler.dispatchMessage(Handler.java:99)
12-29 06:34:45.214: E/WindowManager(1462): at android.os.Looper.loop(Looper.java:137)
12-29 06:34:45.214: E/WindowManager(1462): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-29 06:34:45.214: E/WindowManager(1462): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 06:34:45.214: E/WindowManager(1462): at java.lang.reflect.Method.invoke(Method.java:511)
12-29 06:34:45.214: E/WindowManager(1462): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-29 06:34:45.214: E/WindowManager(1462): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-29 06:34:45.214: E/WindowManager(1462): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
doc = Jsoup.connect("http://www.interdag.ru/afisha").get();
替换为
return Jsoup.connect("http://www.interdag.ru/afisha").get();
在执行后返回的对象是你可以使用它的结果。