Android:支持库中的片段可以正常工作,但普通库却没有

时间:2013-03-01 16:31:18

标签: android android-support-library

我有以下代码......

import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
...
public class LevelSelectorFragmentActivity extends FragmentActivity {
  ...
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_level);
    this.mAdapter = new LevelFragmentPagerAdapter(this);
  }
  private static class LevelFragmentPagerAdapter extends FragmentPagerAdapter {

    public LevelFragmentPagerAdapter(FragmentActivity a) {
        super(a.getSupportFragmentManager());
    }

    @Override
    public Fragment getItem(int position) {
        return Level1Fragment.newInstance();
    }

    @Override
    public int getCount() {
        return NUMBER_OF_PAGES;
    }

  }
}

这很好但是当我将FragmentActivity格式更改为Activity并按如下方式更改导入时...

import org.gleason.superhockey.fragment.Level1Fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
public class LevelSelectorFragmentActivity extends Activity {

private static final int NUMBER_OF_PAGES = 2;
private LevelFragmentPagerAdapter mAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_level);
    this.mAdapter = new LevelFragmentPagerAdapter(this);
}

private static class LevelFragmentPagerAdapter extends FragmentPagerAdapter {

    public LevelFragmentPagerAdapter(Activity a) {
        super(a.getFragmentManager());
    }

    @Override
    public Fragment getItem(int position) {
        return Level1Fragment.newInstance();
    }

    @Override
    public int getCount() {
        return NUMBER_OF_PAGES;
    }

}

}

我得到以下ClassNotFound ......

  

java.lang.NoClassDefFoundError:org.gleason.superhockey.LevelSelectorFragmentActivity $ LevelFragmentPagerAdapter

举个例子,我正在使用this

有人能看到我错过的东西吗?

1 个答案:

答案 0 :(得分:-1)

您的库.jar可能位于错误的目录中,或者是两次添加到项目中。确保您的支持库.jar位于/ libs文件夹中。然后检查Build Path并从中删除支持库(如果它在那里)。清洁项目。