我有这样做fb代码:
private void fbLike_optionA() {
Bundle params1 = new Bundle();
params1.putString("object", "http://samples.ogp.me/226075010839791");
/* make the API call */
new Request(Session.getActiveSession(), "/me/og.likes", params1,
HttpMethod.POST, new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
String a = "1";
}
}).executeAsync();
}
由于假(?)url?,是错误
"http://samples.ogp.me/226075010839791"
我屯并得到这个错误:
06-09 12:36:58.791: E/AndroidRuntime(1030): FATAL EXCEPTION: AsyncTask #5
06-09 12:36:58.791: E/AndroidRuntime(1030): java.lang.RuntimeException: An error occured while executing doInBackground()
06-09 12:36:58.791: E/AndroidRuntime(1030): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-09 12:36:58.791: E/AndroidRuntime(1030): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.lang.Thread.run(Thread.java:841)
06-09 12:36:58.791: E/AndroidRuntime(1030): Caused by: java.lang.IllegalStateException: Cannot execute task: the task is already running.
06-09 12:36:58.791: E/AndroidRuntime(1030): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:575)
06-09 12:36:58.791: E/AndroidRuntime(1030): at android.os.AsyncTask.execute(AsyncTask.java:534)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.facebook.RequestAsyncTask.executeOnSettingsExecutor(RequestAsyncTask.java:186)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.facebook.Request.executeBatchAsync(Request.java:1838)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.facebook.Request.executeBatchAsync(Request.java:1813)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.facebook.Request.executeBatchAsync(Request.java:1790)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.facebook.Request.executeAsync(Request.java:1562)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.zoomer.general.ImageAdapter.fbLike_optionA(ImageAdapter.java:508)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.zoomer.general.ImageAdapter.access$0(ImageAdapter.java:479)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.zoomer.general.ImageAdapter$LikeFbPostAsyncTask.doInBackground(ImageAdapter.java:735)
06-09 12:36:58.791: E/AndroidRuntime(1030): at com.zoomer.general.ImageAdapter$LikeFbPostAsyncTask.doInBackground(ImageAdapter.java:1)
06-09 12:36:58.791: E/AndroidRuntime(1030): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-09 12:36:58.791: E/AndroidRuntime(1030): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-09 12:36:58.791: E/AndroidRuntime(1030): ... 4 more
06-09 12:36:59.106: E/WindowManager(1030): Activity com.zoomer.offers.OffersListActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{427e3368 V.E..... R....... 0,0-640,1230} that was originally added here
06-09 12:36:59.106: E/WindowManager(1030): android.view.WindowLeaked: Activity com.zoomer.offers.OffersListActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{427e3368 V.E..... R....... 0,0-640,1230} that was originally added here
06-09 12:36:59.106: E/WindowManager(1030): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:454)
06-09 12:36:59.106: E/WindowManager(1030): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:258)
06-09 12:36:59.106: E/WindowManager(1030): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:73)
06-09 12:36:59.106: E/WindowManager(1030): at android.app.Dialog.show(Dialog.java:287)
06-09 12:36:59.106: E/WindowManager(1030): at com.zoomer.general.ImageAdapter$4.onClick(ImageAdapter.java:311)
06-09 12:36:59.106: E/WindowManager(1030): at android.view.View.performClick(View.java:4475)
06-09 12:36:59.106: E/WindowManager(1030): at android.view.View$PerformClick.run(View.java:18786)
06-09 12:36:59.106: E/WindowManager(1030): at android.os.Handler.handleCallback(Handler.java:730)
06-09 12:36:59.106: E/WindowManager(1030): at android.os.Handler.dispatchMessage(Handler.java:92)
06-09 12:36:59.106: E/WindowManager(1030): at android.os.Looper.loop(Looper.java:137)
06-09 12:36:59.106: E/WindowManager(1030): at android.app.ActivityThread.main(ActivityThread.java:5493)
06-09 12:36:59.106: E/WindowManager(1030): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 12:36:59.106: E/WindowManager(1030): at java.lang.reflect.Method.invoke(Method.java:525)
06-09 12:36:59.106: E/WindowManager(1030): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
06-09 12:36:59.106: E/WindowManager(1030): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
06-09 12:36:59.106: E/WindowManager(1030): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
我建议你使用这个库(details here):
dependencies {
compile 'com.shamanland:facebook-like-button:0.1.8'
}
这个库实现了&#39; like&#39;使用基于facebook plugin的WebView
和基于<iframe>
的行动。
查看屏幕截图:
答案 1 :(得分:0)
AsyncTask的这种方法引发了异常:
public final AsyncTask<Params, Progress, Result> executeOnExecutor(Executor exec, Params... params) {
if (mStatus != Status.PENDING) {
switch (mStatus) {
case RUNNING:
throw new IllegalStateException("Cannot execute task:"
+ " the task is already running.");
case FINISHED:
throw new IllegalStateException("Cannot execute task:"
+ " the task has already been executed "
+ "(a task can be executed only once)");
}
}
mStatus = Status.RUNNING;
onPreExecute();
mWorker.mParams = params;
exec.execute(mFuture);
return this;
}
所以这意味着你尝试执行已经运行的任务。