我已经离开并试图解决这个崩溃数周,但我还没有发现问题。当我运行以下功能" GetAchievementsInformation()"在我的Libgdx游戏中,当调用堆栈中存在非本机帧时,应用程序崩溃并且#34;无法分离线程"
我在这里做错了吗?我的大多数其他facebook请求运行得很好(我有第二个提出相同的错误)
public FBRequest GetAchievementsRequest()
{
return new FBRequest(FBSession.getActiveSession(),"/"+ APP_ID + "/achievements", null,"GET");
}
FBRequestHandler GetAchievementsRequestHandler()
{
return new FBRequestHandler()
{
@Override
public void invoke(FBRequestConnection connection, NSObject data, NSError error)
{
if (error != null)
{
Gdx.app.log("error", error.toString());
logout();
return;
}
JSONArray achievements_data;
try {
achievements_data = NSObjectToJSONObject(data).getJSONArray("data");
for(int i=0;i<achievements_data.length();i++)
{
JSONObject achievement_data = achievements_data.getJSONObject(i);
JSONObject pointdata = achievement_data.getJSONObject("data");
String points_data = pointdata.get("points").toString();
int score = Integer.parseInt(points_data);
String url = achievement_data.get("url").toString();
JSONArray list = achievement_data.getJSONArray("image");
String image_url = list.getJSONObject(0).get("url").toString();
achievementManager.AddInformationToAchievement(url, score,image_url);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Gdx.app.log("request", "get achieved achievements");
GetAchievedAchievementsRequest().start(GetAchievedAchievementRequestHandler());
}
};
}
public FBRequest GetAchievedAchievementsRequest()
{
return new FBRequest(FBSession.getActiveSession(),"/me/achievements", null, "GET");
}
FBRequestHandler GetAchievedAchievementRequestHandler()
{
return new FBRequestHandler()
{
@Override
public void invoke(FBRequestConnection connection, NSObject data,NSError error)
{
if (error != null)
{
Gdx.app.log("error", error.toString());
logout();
return;
}
JSONArray achievements_data;
try
{
achievements_data = NSObjectToJSONObject(data).getJSONArray("data");
for(int i=0;i<achievements_data.length();i++)
{
JSONObject achievement_data = achievements_data.getJSONObject(i).getJSONObject("data");
JSONObject achievement_sub_data = achievement_data.getJSONObject("achievement");
String url = achievement_sub_data.get("url").toString();
achievementManager.UnlockedAchievement(url);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
achievementManager.SetupAchievementsFinished(); //finished loading after this
}
};
}
public void GetAchievementInformation()
{
Gdx.app.log("request", "Getting achievement information");
GetAchievementsRequest().start(GetAchievementsRequestHandler());
}
JSONObject NSObjectToJSONObject(NSObject object)
{
JSONObject json = null;
String jsonString64 = NSJSONSerialization.createJSONData(object, NSJSONWritingOptions.PrettyPrinted).toBase64EncodedString(NSDataBase64EncodingOptions.None);
String jsonString = Base64Coder.decodeString(jsonString64);
Gdx.app.log("json", "to json:" + jsonString);
try {
json = new JSONObject(jsonString);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return json;
}
答案 0 :(得分:0)
通过添加:connection.dispose();
来修复内存泄漏我不确定为什么这不是我做的其他请求的问题。但在这里它导致了崩溃。