gpt4 book ai didi

android - NoClassDefoundError while class is exist in the program

转载 作者:行者123 更新时间:2023-11-30 04:27:31 24 4
gpt4 key购买 nike

我有一个问题,当我运行下面的程序时,我发现了 NoClassDefaunderError,但是这个程序中存在那个类。我不明白为什么 DVM 会出现这个错误:

程序是:

package com.codecarpet.fbconnect.sample;

import java.util.Collections;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.codecarpet.fbconnect.FBDialog;
import com.codecarpet.fbconnect.FBDialog.FBDialogDelegate;
import com.codecarpet.fbconnect.FBFeedActivity;
import com.codecarpet.fbconnect.FBLoginButton;
import com.codecarpet.fbconnect.FBLoginButton.FBLoginButtonStyle;
import com.codecarpet.fbconnect.FBPermissionActivity;
import com.codecarpet.fbconnect.FBRequest;
import com.codecarpet.fbconnect.FBRequest.FBRequestDelegate;
import com.codecarpet.fbconnect.FBSession;
import com.codecarpet.fbconnect.FBSession.FBSessionDelegate;


public class MainActivity extends Activity {

// /////////////////////////////////////////////////////////////////////////////////////////////////
// This application will not work until you enter your Facebook application's API key here:

private static final String kApiKey = "<YOUR API KEY>";

// Enter either your API secret or a callback URL (as described in documentation):
private static final String kApiSecret = "<YOUR SECRET KEY>";
private static final String kGetSessionProxy = null; // "<YOUR SESSION CALLBACK)>";
private static final int PERMISSIONREQUESTCODE = 1;
private static final int MESSAGEPUBLISHED = 2;
// /////////////////////////////////////////////////////////////////////////////////////////////////

private FBSession _session;
private FBLoginButton _loginButton;
private TextView _label;
private Button _permissionButton;
private Button _feedButton;
private Handler mHandler;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mHandler = new Handler();

if (kGetSessionProxy != null) {
_session = FBSession.getSessionForApplication_getSessionProxy(kApiKey, kGetSessionProxy, new FBSessionDelegateImpl());
} else {
_session = FBSession.getSessionForApplication_secret(kApiKey, kApiSecret, new FBSessionDelegateImpl());
}

setContentView(R.layout.main);

_label = (TextView) findViewById(R.id.label);
_permissionButton = (Button) findViewById(R.id.permissionButton);
_permissionButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
askPermission();
}
});

_feedButton = (Button) findViewById(R.id.feedButton);
_feedButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
publishFeed();
}
});

_loginButton = (FBLoginButton) findViewById(R.id.login);
_loginButton.setStyle(FBLoginButtonStyle.FBLoginButtonStyleWide);
_loginButton.setSession(_session);

_session.resume(this);

}

// /////////////////////////////////////////////////////////////////////////////////////////////////

private void askPermission() {
Intent intent = new Intent(this, FBPermissionActivity.class);
intent.putExtra("permissions", new String[]{"publish_stream"});
this.startActivityForResult(intent, PERMISSIONREQUESTCODE );
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode){
case PERMISSIONREQUESTCODE:
if (resultCode == 1)
_permissionButton.setVisibility(View.INVISIBLE);
default:
return;
}

}

private void publishFeed() {
Intent intent = new Intent(this, FBFeedActivity.class);
intent.putExtra("userMessagePrompt", "Example prompt");
intent.putExtra("attachment", "{\"name\":\"Facebook Connect for Android\",\"href\":\"http://code.google.com/p/fbconnect-android/\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}");
this.startActivityForResult(intent, MESSAGEPUBLISHED);
}

// /////////////////////////////////////////////////////////////////////////////////////////////////

private class FBDialogDelegateImpl extends FBDialogDelegate {

@Override
public void didFailWithError(FBDialog dialog, Throwable error) {
_label.setText(error.toString());
}

}

private void checkPermission() {
String fql = "select publish_stream from permissions where uid == " + String.valueOf(_session.getUid());
Map<String, String> params = Collections.singletonMap("query", fql);
FBRequest.requestWithDelegate(new FBHasPermissionRD()).call("facebook.fql.query", params);
}

private class FBSessionDelegateImpl extends FBSessionDelegate {

@Override
public void session_didLogin(FBSession session, Long uid) {
// we check if the user already has the permissions before displaying permission button
checkPermission();

mHandler.post(new Runnable() {
public void run() {
_feedButton.setVisibility(View.VISIBLE);
}
});

String fql = "select uid,name from user where uid == " + session.getUid();

Map<String, String> params = Collections.singletonMap("query", fql);
FBRequest.requestWithDelegate(new FBRequestDelegateImpl()).call("facebook.fql.query", params);
}



@Override
public void sessionDidLogout(FBSession session) {
mHandler.post(new Runnable() {
public void run() {
_label.setText("");
_permissionButton.setVisibility(View.INVISIBLE);
_feedButton.setVisibility(View.INVISIBLE);
}
});
}

}

private class FBRequestDelegateImpl extends FBRequestDelegate {

@Override
public void request_didLoad(FBRequest request, Object result) {

String name = null;

if (result instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) result;
try {
JSONObject jo = jsonArray.getJSONObject(0);
name = jo.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
}
_label.setText("Logged in as " + name);
}

@Override
public void request_didFailWithError(FBRequest request, Throwable error) {
_label.setText(error.toString());
}
}

private class FBHasPermissionRD extends FBRequestDelegate {

@Override
protected void request_didFailWithError(FBRequest request,
Throwable error) {
super.request_didFailWithError(request, error);
}

@Override
public void request_didLoad(FBRequest request, Object result) {
int hasPermission = 0;

if (result instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) result;
try {
JSONObject jo = jsonArray.getJSONObject(0);
hasPermission = jo.getInt("publish_stream");
if (hasPermission == 0)
{
mHandler.post(new Runnable() {
public void run() {
_permissionButton.setVisibility(View.VISIBLE);
}
});
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}

错误是:

11-22 11:33:02.510: ERROR/AndroidRuntime(3213): java.lang.NoClassDefFoundError: com.codecarpet.fbconnect.sample.MainActivity$FBSessionDelegateImpl
11-22 11:33:02.510: ERROR/AndroidRuntime(3213): at com.codecarpet.fbconnect.sample.MainActivity.onCreate(MainActivity.java:77)

提前致谢...

最佳答案

给出项目中的绝对路径。如果您无法执行此操作,请在您当前的项目中添加 facebook api 的所有文件。清理并运行它之后...!!!

关于android - NoClassDefoundError while class is exist in the program,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8222728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com