如何解决这个问题:java.lang.NoClassDefFoundError:android.support.v4.app.FragmentActivity

时间:2013-08-08 08:56:55

标签: android

我有一个使用ActionBarSherlock和Facebook SDK 3.0.2的应用程序。 在我导入ActionBarSherlock并在我的应用程序中实现它之后,我遇到了这些问题。 首先,android_support_v4库冲突了。然后我删除它并指向只有一个jar文件。我的应用安装了。 其次,当应用程序运行包含ABS的MainActivity时,应用程序强制关闭并出现错误:java.lang.NoClassDefFoundError:android.support.v4.app.FragmentActivity

这里有什么问题:

package vn.com.onesoft.bigvl.main.activity;

import java.util.ArrayList;

import vn.bigone.main.MainActivity;
import vn.com.onesoft.bigvl.R;
import vn.com.onesoft.bigvl.chat.ChatActivity;
import vn.com.onesoft.bigvl.context.GameContext;
import vn.com.onesoft.bigvl.gps.GPSTracker;
import vn.com.onesoft.bigvl.main.ui.ActionManager;
import vn.com.onesoft.bigvl.main.ui.BigVLListViewAdapter;
import vn.com.onesoft.bigvl.main.ui.BigVLListViewItem;
import vn.com.onesoft.bigvl.main.ui.IListViewItem;
import vn.com.onesoft.bigvl.message.MessageSender;
import vn.com.onesoft.bigvl.message.out.MGetContactListReq;
import vn.com.onesoft.bigvl.message.out.MVLGetFollowListReq;
import vn.com.onesoft.bigvl.message.out.MVLGetFriendListInMobileContactReq;
import vn.com.onesoft.bigvl.message.out.MVLListGameReq;
import vn.com.onesoft.bigvl.message.out.MVLUpdateLocationReq;    
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;

@SuppressLint("ShowToast")
public class ActivityMain extends SherlockActivity implements ActionBar.TabListener {

@Override
protected void onResume() {
    //
    super.onResume();
    GameContext.activity = this;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bvl_activity_main);
    GameContext.activity = this;

    this.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // TODO tab1
    ActionBar.Tab tab1 = getSupportActionBar().newTab();
    tab1.setText("Kết nối");
    tab1.setIcon(R.drawable.ket_noi);
    tab1.setTabListener(this);
    getSupportActionBar().addTab(tab1);
    // TODO tab2
    ActionBar.Tab tab2 = getSupportActionBar().newTab();
    tab2.setText("Kết nối");
    tab2.setIcon(R.drawable.chat);
    tab2.setTabListener(this);
    getSupportActionBar().addTab(tab2);
    // TODO tab3
    ActionBar.Tab tab3 = getSupportActionBar().newTab();
    tab3.setText("Kết nối");
    tab3.setIcon(R.drawable.game);
    tab3.setTabListener(this);
    getSupportActionBar().addTab(tab3);
    // TODO tab4
    ActionBar.Tab tab4 = getSupportActionBar().newTab();
    tab4.setText("Kết nối");
    tab4.setIcon(R.drawable.blog);
    tab4.setTabListener(this);
    getSupportActionBar().addTab(tab4);

    final ListView listview = (ListView) findViewById(R.id.listViewConnectivityFriends);
    listview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            //
            BigVLListViewAdapter lvAdapter = (BigVLListViewAdapter) parent
                    .getAdapter();
            BigVLListViewItem item = (BigVLListViewItem) lvAdapter
                    .getItem(position);
            item.getLvAction().onClick();
        }
    });

    ArrayList<BigVLListViewItem> lvItems = new ArrayList<BigVLListViewItem>();

    lvItems.add(new BigVLListViewItem(R.drawable.danh_ba, "Danh bạ",
            new IListViewItem() {

                @Override
                public void onClick() {
                    MVLGetFriendListInMobileContactReq mobileContactReq = new MVLGetFriendListInMobileContactReq();
                    MessageSender.sendMessage(mobileContactReq);
                }
            }));
    lvItems.add(new BigVLListViewItem(R.drawable.danh_sach_ban,
            "Danh sách bạn", new IListViewItem() {

                @Override
                public void onClick() {
                    //
                    Intent intent = new Intent(GameContext.activity,
                            MainActivity.class);
                    GameContext.activity.startActivity(intent);
                }
            }));

    lvItems.add(new BigVLListViewItem(R.drawable.theo_doi_ban,
            "Danh sách theo dõi", new IListViewItem() {

                @Override
                public void onClick() {
                    // TODO Auto-generated method stub
                    MVLGetFollowListReq mvlGetFollowListReq = new MVLGetFollowListReq(
                            0);
                    MessageSender.sendMessage(mvlGetFollowListReq);
                }
            }));

    lvItems.add(new BigVLListViewItem(R.drawable.ket_noi,
            "Yêu cầu kết bạn", new IListViewItem() {

                @Override
                public void onClick() {
                    // TODO Auto-generated method stub

                }
            }));

    final ListView listview2 = (ListView) findViewById(R.id.listViewConnectivitySearch);
    listview2.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            //
            BigVLListViewAdapter lvAdapter = (BigVLListViewAdapter) parent
                    .getAdapter();
            BigVLListViewItem item = (BigVLListViewItem) lvAdapter
                    .getItem(position);
            item.getLvAction().onClick();
        }
    });
    ArrayList<BigVLListViewItem> lvItem2s = new ArrayList<BigVLListViewItem>();

    lvItem2s.add(new BigVLListViewItem(R.drawable.tim_kiem,
            "Tìm quanh đây", new IListViewItem() {

                @Override
                public void onClick() {
                    GPSTracker gps = new GPSTracker(GameContext.activity);
                    MVLUpdateLocationReq mvlUpdateLocationReq = new MVLUpdateLocationReq(
                            gps.getLatitude(), gps.getLongitude());
                    MessageSender.sendMessage(mvlUpdateLocationReq);
                }
            }));

    listview.setAdapter(new BigVLListViewAdapter(lvItems));

    listview2.setAdapter(new BigVLListViewAdapter(lvItem2s));
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub
    switch (tab.getPosition()) {
    case 0:
        ActionManager.showAction(ActionManager.ACTION_KET_NOI);
        MGetContactListReq mGetContactListReq = new MGetContactListReq(
                0);
        MessageSender.sendMessage(mGetContactListReq);
        break;

    case 1:
        ActionManager.showAction(ActionManager.ACTION_CHAT);
        Intent intent = new Intent(
                GameContext.activity.getApplicationContext(),
                ChatActivity.class);
        startActivity(intent);
        Toast.makeText(GameContext.activity, "Request sent", 1).show();
        break;
    case 2:
        ActionManager.showAction(ActionManager.ACTION_GAMES);
        MVLListGameReq mListGameReq = new MVLListGameReq();
        MessageSender.sendMessage(mListGameReq);
        break;
    case 3:

        break;

    default:
        break;
    }
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}

}

2 个答案:

答案 0 :(得分:0)

右键点击您的项目 - &gt;构建路径 - &gt;配置构建路径 - &gt;订单和导出标签。

确保选中“Android私有库”进行导出。

如果您已从libs /文件夹中添加了任何库,请将其删除,因为它们会自动添加到“Android私有库”部分中。

或试试这个:Libraries do not get added to APK anymore after upgrade to ADT 22

答案 1 :(得分:0)

当我试图包含一个罐子时,我有几次这个问题。 这个问题的分步教程帮助了我:

Adding a library/JAR to an Eclipse Android project