Android中的NoClassdefFoundError

时间:2011-05-09 14:05:33

标签: android

我在我的应用程序中实现了twitter和facebook,但是活动在SettingActivity上返回错误为NoClassFoundError,但我的活动已经在清单中,应该是什么原因? 请帮帮我。

错误:

05-09 19:32:42.485: ERROR/AndroidRuntime(903): java.lang.NoClassDefFoundError: org.shopzilla.android.moretab.SettingActivity
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at org.shopzilla.android.moretab.More$1.onClick(More.java:46)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at android.view.View.performClick(View.java:2485)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at android.view.View$PerformClick.run(View.java:9080)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at android.os.Handler.handleCallback(Handler.java:587)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at android.os.Looper.loop(Looper.java:123)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at android.app.ActivityThread.main(ActivityThread.java:3683)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at java.lang.reflect.Method.invokeNative(Native Method)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at java.lang.reflect.Method.invoke(Method.java:507)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 19:32:42.485: ERROR/AndroidRuntime(903):     at dalvik.system.NativeStart.main(Native Method)

代码:

package org.shopzilla.android.moretab;

import java.util.List;

import net.xeomax.FBRocket.FBRocket;
import net.xeomax.FBRocket.Facebook;
import net.xeomax.FBRocket.LoginListener;
import net.xeomax.FBRocket.ServerErrorException;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.shopzilla.android.common.R;
import org.shopzilla.android.facebook.FacebookActivity;
import org.shopzilla.android.facebook.FacebookWebOAuthActivity;
import org.shopzilla.android.twitter.TwitterActivity;
import org.shopzilla.android.twitter.TwitterWebOAuthActivity;

import twitter4j.http.RequestToken;

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

public class SettingActivity extends Activity implements LoginListener{
     String bytesSent;
        HttpClient httpclient;
        int count1;
        // List with parameters and their values
        List<NameValuePair> nameValuePairs;
        TextView mText;
        Button btn_facebook;
        Button btn_twitter;
        FBRocket fbRocket;
        RequestToken rToken;
        String oauthVerifier;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_setting);

        Button btn_twitter = (Button)findViewById(R.id.btn_more_setting_twitter);
        Button btn_facebook = (Button)findViewById(R.id.btn_More_setting_facebook);
        btn_twitter.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(SettingActivity.this,TwitterActivity.class);
                startActivity(intent);
                //displayTwitterAuthorization();

            }
        });

        btn_facebook.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                /*Intent intent = new Intent(SettingActivity.this,FacebookActivity.class);
                startActivity(intent);*/
                shareFacebook();
                //displayFacebookAuthorization();
                //shareFacebook();
            }
        });



    }
    public void shareFacebook() {
        fbRocket = new FBRocket(SettingActivity.this, "ShopZilla",
        "172619129456913");

        if (fbRocket.existsSavedFacebook()) {
        fbRocket.loadFacebook();
        } else {
        fbRocket.login(R.layout.facebook);
        }
        }

        public void onLoginFail() {
        fbRocket.displayToast("Login failed!");
        fbRocket.login(R.layout.facebook);
        }

        public void onLoginSuccess(Facebook facebook) {
        // TODO Auto-generated method stub
        fbRocket.displayToast("Login success!");

        try {
        facebook.setStatus("This is your status");
        fbRocket.displayDialog("Status Posted Successfully!! "
        + facebook.getStatus());
        } catch (ServerErrorException e) {
        if (e.notLoggedIn()) {
        fbRocket.login(R.layout.facebook);
        } else {
        System.out.println(e);
        }
        }
        }



}

2 个答案:

答案 0 :(得分:0)

确保将每个活动添加到清单文件中:

<activity android:name="org.shopzilla.android.moretab.SettingActivity" />

答案 1 :(得分:0)

尝试将文件夹“libs”(而不是“lib”)添加到项目中。然后将所有twitter的库添加到此文件夹并再次运行。