我开发了一款可以在 FB 上分享视频的游戏,之前运行良好,但我不知道现在怎么会出现此错误。我也得到了所有许可,现在它没有给我任何许可。 在 FB RequestAsyncTask 类中,我对 AlertDialog 进行了一些修改,以显示上传视频的过程。
这是我执行 AsyncTask 的地方
Request request = new Request(session, "me/videos", postParam, HttpMethod.POST, callback);
RequestAsyncTask reqTask = new RequestAsyncTask(Result.this, request);
reqTask.execute();
和 Logcat
04-19 18:40:47.048: I/System.out(20093): no of permission it has = 0
04-19 18:40:47.963: D/AndroidRuntime(20093): Shutting down VM
04-19 18:40:47.963: W/dalvikvm(20093): threadid=1: thread exiting with uncaught exception (group=0x418cb700)
04-19 18:40:47.968: E/AndroidRuntime(20093): FATAL EXCEPTION: main
04-19 18:40:47.968: E/AndroidRuntime(20093): java.lang.IllegalStateException: Cannot execute task: the task is already running.
04-19 18:40:47.968: E/AndroidRuntime(20093): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:575)
04-19 18:40:47.968: E/AndroidRuntime(20093): at android.os.AsyncTask.execute(AsyncTask.java:534)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.RequestAsyncTask.executeOnSettingsExecutor(RequestAsyncTask.java:205)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.Request.executeBatchAsync(Request.java:1094)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.RequestBatch.executeAsyncImpl(RequestBatch.java:225)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.RequestBatch.executeAsync(RequestBatch.java:204)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.AuthorizationClient.validateSameFbidAndFinish(AuthorizationClient.java:279)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.AuthorizationClient.completeAndValidate(AuthorizationClient.java:215)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.AuthorizationClient$GetTokenAuthHandler.getTokenCompleted(AuthorizationClient.java:536)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.AuthorizationClient$GetTokenAuthHandler$1.completed(AuthorizationClient.java:514)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.GetTokenClient.callback(GetTokenClient.java:121)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.GetTokenClient.handleMessage(GetTokenClient.java:107)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.GetTokenClient.access$0(GetTokenClient.java:100)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.facebook.GetTokenClient$1.handleMessage(GetTokenClient.java:43)
04-19 18:40:47.968: E/AndroidRuntime(20093): at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 18:40:47.968: E/AndroidRuntime(20093): at android.os.Looper.loop(Looper.java:137)
04-19 18:40:47.968: E/AndroidRuntime(20093): at android.app.ActivityThread.main(ActivityThread.java:5295)
04-19 18:40:47.968: E/AndroidRuntime(20093): at java.lang.reflect.Method.invokeNative(Native Method)
04-19 18:40:47.968: E/AndroidRuntime(20093): at java.lang.reflect.Method.invoke(Method.java:525)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
04-19 18:40:47.968: E/AndroidRuntime(20093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
04-19 18:40:47.968: E/AndroidRuntime(20093): at dalvik.system.NativeStart.main(Native Method)
04-19 18:40:59.128: I/Process(20093): Sending signal. PID: 20093 SIG: 9
04-19 18:40:59.463: I/dalvikvm(20943): Turning on JNI app bug workarounds for target SDK version 10...
如果有人想查看代码的任何其他部分,请告诉我,我会给你。我需要尽快调试并上传到 Google Play
编辑
这是我使用 fb post 的完整代码,将项目替换为新项目后它可以正常工作,但在我更改 FB Developer 上的应用程序名称后,它会请求许可,这是正常的,然后它又开始给我同样的错误。
package com.yceo.anlatbana;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import org.json.JSONObject;
import com.yceo.anlatbana.R;
import com.facebook.HttpMethod;
import com.facebook.LoggingBehavior;
import com.facebook.Request;
import com.facebook.RequestAsyncTask;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.Settings;
import com.facebook.Session.StatusCallback;
import com.yceo.anlatbana.util.ListViewAdapter;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
public class Result extends Activity {
static final String APP_ID = "dont wanna show";
Session session;
private boolean pendingRequest;
static final String PENDING_REQUEST_BUNDLE_KEY = "com.yceo.anlatbana:PendingRequest";
static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
private TextView result;
private Button re_play;
private Button save_video;
private Button watch_video;
private Button share_video;
private ImageView score_top;
private ImageView score;
public static int isSaved = 0;
public static int doubleClick = 0;
public static int sentAlready = 0;
public static int width;
public static int height;
int resultPoint;
private Typeface font_score;
String path = VideoViewTest.videoPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
this.session = createSession();
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
re_play= (Button) findViewById(R.id.result_button_replay);
save_video= (Button) findViewById(R.id.result_button_save_video);
result = (TextView) findViewById(R.id.result_result_tw);
watch_video= (Button) findViewById(R.id.result_button_play_video);
share_video= (Button) findViewById(R.id.result_button_share_video);
score_top= (ImageView) findViewById(R.id.iw_result_point_top);
score= (ImageView) findViewById(R.id.img_score);
font_score=Typeface.createFromAsset(getAssets(),"font/PATAGONIA.TTF");
int trueNumber = VideoViewTest.true_answers.size();
int falseNumber = VideoViewTest.false_answers.size();
resultPoint = ((trueNumber*9) - (falseNumber*2));
result.setText(String.valueOf(resultPoint));
result.setTypeface(font_score);
result.setTextSize(TypedValue.COMPLEX_UNIT_PX, (int)(width*0.05));
RelativeLayout.LayoutParams lp_result_button1 = new RelativeLayout.LayoutParams(((int)(width*0.1)), ((int)(width*0.1)));
lp_result_button1.setMargins(((int)(width*0.035)), 0, ((int)(width*0.035)), 0);
lp_result_button1.addRule(RelativeLayout.LEFT_OF, R.id.result_button_save_video);
RelativeLayout.LayoutParams lp_result_button2 = new RelativeLayout.LayoutParams(((int)(width*0.1)), ((int)(width*0.1)));
lp_result_button2.setMargins(((int)(width*0.035)), 0, ((int)(width*0.035)), 0);
lp_result_button2.addRule(RelativeLayout.LEFT_OF, R.id.result_result_tw);
RelativeLayout.LayoutParams lp_result_button3 = new RelativeLayout.LayoutParams(((int)(width*0.1)), ((int)(width*0.1)));
lp_result_button3.setMargins(((int)(width*0.035)), 0, ((int)(width*0.035)), 0);
lp_result_button3.addRule(RelativeLayout.CENTER_HORIZONTAL);
RelativeLayout.LayoutParams lp_result_button4 = new RelativeLayout.LayoutParams(((int)(width*0.1)), ((int)(width*0.1)));
lp_result_button4.setMargins(((int)(width*0.035)), 0, ((int)(width*0.035)), 0);
lp_result_button4.addRule(RelativeLayout.RIGHT_OF, R.id.result_result_tw);
RelativeLayout.LayoutParams lp_result_button5 = new RelativeLayout.LayoutParams(((int)(width*0.1)), ((int)(width*0.1)));
lp_result_button5.setMargins(((int)(width*0.035)), 0, ((int)(width*0.035)), 0);
lp_result_button5.addRule(RelativeLayout.RIGHT_OF, R.id.result_button_play_video);
re_play.setLayoutParams(lp_result_button1);
save_video.setLayoutParams(lp_result_button2);
result.setLayoutParams(lp_result_button3);
watch_video.setLayoutParams(lp_result_button4);
share_video.setLayoutParams(lp_result_button5);
score_top.setLayoutParams(new LinearLayout.LayoutParams(((int)(width*0.0654545)), ((int)(width*0.0341818))));
score.setLayoutParams(new LinearLayout.LayoutParams(((int)(width*0.1)), ((int)(width*0.1))));
LinearLayout.LayoutParams lp_result_llw = new LinearLayout.LayoutParams(((int)(width/2)-((int)(width*0.16))), LayoutParams.WRAP_CONTENT);
lp_result_llw.setMargins(((int)(width*0.15)), 0, ((int)(width*0.01)), 0);
LinearLayout.LayoutParams lp_result_rlw = new LinearLayout.LayoutParams(((int)(width/2)-((int)(width*0.16))), LayoutParams.WRAP_CONTENT);
lp_result_rlw.setMargins(((int)(width*0.01)), 0, ((int)(width*0.15)), 0);
final ListView correct_answer_lw = (ListView) findViewById(R.id.result_correct_lw);
final ListView wrong_answer_lw = (ListView) findViewById(R.id.result_wrong_lw);
correct_answer_lw.setLayoutParams(lp_result_llw);
wrong_answer_lw.setLayoutParams(lp_result_rlw);
ListViewAdapter adapter_correct_lw = new ListViewAdapter(
this,
R.layout.item_correct_answer,
R.id.item_correct,
VideoViewTest.true_answers,
height);
correct_answer_lw.setAdapter(adapter_correct_lw);
adapter_correct_lw.notifyDataSetChanged();
ListViewAdapter adapter_wrong_lw = new ListViewAdapter(
this,
R.layout.item_wrong_answer,
R.id.item_wrong,
VideoViewTest.false_answers,
height);
wrong_answer_lw.setAdapter(adapter_wrong_lw);
adapter_wrong_lw.notifyDataSetChanged();
re_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
onBackPressed();
VideoViewTest.true_answers.clear();
VideoViewTest.false_answers.clear();
}
});
save_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Video Kaydedildi", Toast.LENGTH_SHORT).show();
isSaved = 1;
}
});
watch_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in = new Intent(getBaseContext(), AndroidVideoPlayer.class);
startActivity(in);
}
});
share_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickHandler(v);
if (doubleClick==0 && sentAlready==0) {
share_it();
doubleClick=1;
sentAlready=1;
}
else
Toast.makeText(getBaseContext(), "Already shared on Facebook", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if (VideoViewTest.videoPath != null) {
if (isSaved == 0) {
File file = new File(VideoViewTest.videoPath);
if(file.exists())
file.delete();
finish();
}
}
finish();
doubleClick = 0;
sentAlready = 0;
}
@Override
protected void onPause() {
doubleClick=0;
// Log.i("pause", "oldu");
super.onPause();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (this.session.onActivityResult(this, requestCode, resultCode, data)
&& pendingRequest && this.session.getState().isOpened()) {
share_it();
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
pendingRequest = savedInstanceState.getBoolean(
PENDING_REQUEST_BUNDLE_KEY, pendingRequest);
}
@Override
protected void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putBoolean(PENDING_REQUEST_BUNDLE_KEY, pendingRequest);
}
@Override
protected void onResume() {
super.onResume();
}
private Session createSession() {
Session session = Session.getActiveSession();
if (session == null || session.getState().isClosed()) {
session = new Session.Builder(getApplicationContext()).setApplicationId(APP_ID).build();
Session.setActiveSession(session);
}
return session;
}
public void clickHandler(View v) {
if (!session.isOpened()) {
StatusCallback callback = new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
// TODO Auto-generated method stub
if (exception != null) {
Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_SHORT).show();
Result.this.session = createSession();
}
}
};
pendingRequest = true;
this.session.openForRead(new Session.OpenRequest(this).setCallback(callback));
}
}
public void share_it() {
if (session.isOpened()) {
if (session != null) {
List<String> permission = session.getPermissions();
System.out.println("no of permission it has = " + permission.size());
for (int i = 0; i < permission.size(); i++) {
System.out.println("Permission " + i + " => " + permission.get(i));
}
if (permission.size() == 0) {
pendingRequest = true;
Session.NewPermissionsRequest publishPermission = new Session.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(publishPermission);
}
else {
final Bundle postParam = new Bundle();
String dataMsg = "AnlatBana Game Video";
byte[] data = null;
// InputStream is = null;
File file=new File(path);
/* try {
is = new FileInputStream(path);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/ try {
// data = readBytes(is);
data = getBytesFromFile(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/* Bitmap bi = BitmapFactory.decodeFile(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParam.putByteArray("picture", data);
*/
postParam.putString("message", dataMsg);
postParam.putString("description", scoreDescription());
// postParam.putString("title", "title");
postParam.putString("contentType", "video/quicktime");
postParam.putByteArray("video.mov", data);
final Request.Callback callback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
String postId = null;
try {
JSONObject graphObject = response.getGraphObject().getInnerJSONObject();
postId = graphObject.getString("id");
} catch (Exception ex) {
System.out.println("Error Occured fetching grapho objecyt " + ex.getMessage());
}
}
};
Request request = new Request(Session.getActiveSession(), "me/videos", postParam, HttpMethod.POST, callback);
RequestAsyncTask reqTask = new RequestAsyncTask(Result.this, request);
reqTask.execute();
/* Request request = new Request(session, "me/photos", postParam, HttpMethod.POST, callback);
RequestAsyncTask reqTask = new RequestAsyncTask(request);
reqTask.execute();
*/
}
}
}
}
/* public byte[] readBytes(InputStream inputStream) throws IOException {
// This dynamically extends to take the bytes you read.
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
// This is storage overwritten on each iteration with bytes.
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
// We need to know how may bytes were read to write them to the byteBuffer.
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
// And then we can return your byte array.
return byteBuffer.toByteArray();
}
*/
@SuppressWarnings("resource")
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
System.out.println("\nDEBUG: FileInputStream is " + file);
// Get the size of the file
long length = file.length();
System.out.println("DEBUG: Length of " + file + " is " + length + "\n");
/*
* You cannot create an array using a long type. It needs to be an int
* type. Before converting to an int type, check to ensure that file is
* not loarger than Integer.MAX_VALUE;
*/
if (length > Integer.MAX_VALUE) {
System.out.println("File is too large to process");
return null;
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while ((offset < bytes.length) && ((numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)) {
offset += numRead;
/* progressBar.setProgress((int) ((offset / (float) length) * 100));
Log.i("asd", String.valueOf(progressBar.getProgress()));
*/ }
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file " + file);
}
is.close();
return bytes;
}
public String scoreDescription() {
String message = null;
if (resultPoint < 0) {
message = String.valueOf(resultPoint) + " Puan" + " - Yok artık!!!";
}
if (0 <= resultPoint && resultPoint < 10) {
message = String.valueOf(resultPoint) + " Puan" + " - Daha çok çalışman lazım";
}
if (10 <= resultPoint && resultPoint < 20) {
message = String.valueOf(resultPoint) + " Puan" + " - Fena değil";
}
if (20 <= resultPoint && resultPoint < 25) {
message = String.valueOf(resultPoint) + " Puan" + " - Güzel skor";
}
if (25 <= resultPoint) {
message = String.valueOf(resultPoint) + " Puan" + " - Çok hızlısın";
}
return message;
}
}
最佳答案
AsyncTask 只能执行一次。您是否在代码的其他地方调用了 execute?
关于android - 无法执行任务 : the task is already running,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23172042/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)