Android 滑块中的 NoClassDefFoundError 错误

NoClassDefFoundError error in Android Slider

我正在创建一个带有滑块的应用程序,它工作正常,然后我添加了另一个视图并为新添加的视图实现了一个 OnClickListener() 之后,当我打开我的应用程序时出现以下错误

Process: com.spintum.preexam, PID: 31905
java.lang.NoClassDefFoundError: com.spintum.preexam.CustomList$DrawerItemHolder
        at com.spintum.preexam.CustomList.getView(CustomList.java:38)
        at android.widget.AbsListView.obtainView(AbsListView.java:2338)
        at android.widget.ListView.makeAndAddView(ListView.java:1812)
        at android.widget.ListView.fillDown(ListView.java:698)
        at android.widget.ListView.fillFromTop(ListView.java:759)
        at android.widget.ListView.layoutChildren(ListView.java:1645)
        at android.widget.AbsListView.onLayout(AbsListView.java:2149)
        at android.view.View.layout(View.java:15125)
        at android.view.ViewGroup.layout(ViewGroup.java:4862)
        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:931)
        at android.view.View.layout(View.java:15125)
        at android.view.ViewGroup.layout(ViewGroup.java:4862)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
        at android.view.View.layout(View.java:15125)
        at android.view.ViewGroup.layout(ViewGroup.java:4862)
        at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
        at android.view.View.layout(View.java:15125)
        at android.view.ViewGroup.layout(ViewGroup.java:4862)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
        at android.view.View.layout(View.java:15125)
        at android.view.ViewGroup.layout(ViewGroup.java:4862)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2317)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2023)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
        at android.view.Choreographer.doCallbacks(Choreographer.java:591)
        at android.view.Choreographer.doFrame(Choreographer.java:560)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5292)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
        at dalvik.system.NativeStart.main(Native Method)

其中logcat显示NoClassDefFound错误的class如下

public class CustomList extends ArrayAdapter<DrawerItem> {

  Context context;
  List<DrawerItem> drawerItemList;
  int layoutResID;

  public CustomList(Context context, int layoutResourceID,
              List<DrawerItem> listItems) {
        super(context, layoutResourceID, listItems);
        this.context = context;
        this.drawerItemList = listItems;
        this.layoutResID = layoutResourceID;

  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        DrawerItemHolder drawerHolder;
        View view = convertView;
         if (view == null) {
              LayoutInflater inflater = ((Activity) context).getLayoutInflater();
              drawerHolder = new DrawerItemHolder();
              view = inflater.inflate(layoutResID, parent, false);
              drawerHolder.ItemName = (TextView) view.findViewById(R.id.drawer_item_text);
              drawerHolder.icon = (ImageView) view.findViewById(R.id.drawer_item_icon);
              view.setTag(drawerHolder);
         } else {
              drawerHolder = (DrawerItemHolder) view.getTag();
         }
         DrawerItem dItem = (DrawerItem) this.drawerItemList.get(position);
        drawerHolder.icon.setImageDrawable(view.getResources().getDrawable(
                    dItem.getImgResID()));
        drawerHolder.ItemName.setText(dItem.getItemName());
         return view;
  }

  private static class DrawerItemHolder {
        TextView ItemName;
        ImageView icon;
    }
}

错误显示在 drawerHolder = new DrawerItemHolder(); 行中。 我没有对此 class 进行任何更改,因此我认为问题可能是由我在原始 activity 中添加的充当片段容器的额外视图引起的。 activity的代码如下

public class Home extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mPlanetTitles;
private static int pos;
List<DrawerItem> dataList = new ArrayList<DrawerItem>();
View statistics,test,syllabus,share;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    this.getActionBar().setBackgroundDrawable(
            getResources().getDrawable(R.color.background));
    this.overridePendingTransition(R.layout.fade_in, R.layout.fade_out);
    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    statistics=findViewById(R.id.statistics_container);
    test=findViewById(R.id.test_container);
    syllabus=findViewById(R.id.syllabus_container);
    share=findViewById(R.id.share_container);
    statistics.setOnClickListener(mBottomDrawerListener);
    syllabus.setOnClickListener(mBottomDrawerListener);
    test.setOnClickListener(mBottomDrawerListener);
    share.setOnClickListener(mBottomDrawerListener);
    TextView image=(TextView)findViewById(R.id.statistics_image);
    TextView text=(TextView)findViewById(R.id.statistics);
    image.setTextColor(Color.parseColor("#03a9f4"));
    text.setTextColor(Color.parseColor("#03a9f4"));

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);
    int width = getResources().getDisplayMetrics().widthPixels;
    DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerList.getLayoutParams();
    //params.width = (width * 75) / 100;
    mDrawerList.setLayoutParams(params);
    // set up the drawer's list view with items and click listener
    /*
     * mDrawerList.setAdapter(new ArrayAdapter<String>(this,
     * R.layout.list_item, mPlanetTitles));
     */
    dataList.add(new DrawerItem("Home", R.drawable.home));
    dataList.add(new DrawerItem("Intelligence Questionnaire",
            R.drawable.bulb));
    dataList.add(new DrawerItem("Change Country", R.drawable.location));
    dataList.add(new DrawerItem("LeaderBoard", R.drawable.cup));
    dataList.add(new DrawerItem("How to play", R.drawable.help));
    dataList.add(new DrawerItem("Exam Tips", R.drawable.tip));
    mDrawerList.setAdapter(new CustomList(Home.this, R.layout.list_item,dataList));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close /* "close drawer" description for accessibility */) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }
        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
        selectItem(0);
    }
    Typeface iconfont=FontManager.getTypeface(getApplicationContext(),FontManager.FONTAWESOME);
    FontManager.markAsIconContainer(findViewById(R.id.btm_nav_bar),iconfont);
}
public View.OnClickListener mBottomDrawerListener=new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        FragmentManager fragmentManager=getFragmentManager();
        setBlackText(v);
        TextView image,text;
        switch (v.getId()){
            case R.id.statistics_container:
                fragmentManager.beginTransaction().replace(R.id.content_frame,new HomePage()).commit();
                image=(TextView)v.findViewById(R.id.statistics_image);
                text=(TextView)v.findViewById(R.id.statistics);
                image.setTextColor(Color.parseColor("#03a9f4"));
                text.setTextColor(Color.parseColor("#03a9f4"));
                break;
            case R.id.syllabus_container:
                image=(TextView)v.findViewById(R.id.syllabus_image);
                text=(TextView)v.findViewById(R.id.syllabus_btm);
                image.setTextColor(Color.parseColor("#03a9f4"));
                text.setTextColor(Color.parseColor("#03a9f4"));
                break;
            case R.id.test_container:
                image=(TextView)v.findViewById(R.id.test_image);
                text=(TextView)v.findViewById(R.id.Tests);
                image.setTextColor(Color.parseColor("#03a9f4"));
                text.setTextColor(Color.parseColor("#03a9f4"));
                break;
            case R.id.share_container:
                image=(TextView)v.findViewById(R.id.share_image);
                text=(TextView)v.findViewById(R.id.share_btm);
                image.setTextColor(Color.parseColor("#03a9f4"));
                text.setTextColor(Color.parseColor("#03a9f4"));
                break;

        }
}
};
public void setBlackText(View v){
    TextView img[]=new TextView[4];
    TextView t1,t2,t3,t4;
    img[0]=(TextView)findViewById(R.id.statistics_image);
    t4=(TextView)findViewById(R.id.statistics);
    img[1]=(TextView)findViewById(R.id.test_image);
    t1=(TextView)findViewById(R.id.Tests);
    img[2]=(TextView)findViewById(R.id.syllabus_image);
    t2=(TextView)findViewById(R.id.syllabus_btm);
    img[3]=(TextView)findViewById(R.id.share_image);
    t3=(TextView)findViewById(R.id.share_btm);
    for(TextView singleTextView:img){
        singleTextView.setTextColor(Color.parseColor("#000000"));
    }
    t1.setTextColor(Color.parseColor("#000000"));
    t2.setTextColor(Color.parseColor("#000000"));
    t3.setTextColor(Color.parseColor("#000000"));
    t4.setTextColor(Color.parseColor("#000000"));
}
/*
 * @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater
 * inflater = getMenuInflater(); inflater.inflate(R.menu.activity_main,
 * menu); return super.onCreateOptionsMenu(menu); }
 * 
 * Called whenever we call invalidateOptionsMenu()
 * 
 * @Override public boolean onPrepareOptionsMenu(Menu menu) { // If the nav
 * drawer is open, hide action items related to the content view boolean
 * drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
 * //menu.findItem(R.id.action_websearch).setVisible(!drawerOpen); return
 * super.onPrepareOptionsMenu(menu); }
 */

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // Handle action buttons
    switch (item.getItemId()) {
    case 1:
        // create intent to perform web search for this planet
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
        // catch event that there's no activity to handle intent
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Toast.makeText(this, R.string.app_not_available,
                    Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements
        ListView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        selectItem(position);
    }
}

private void selectItem(int position) {
    // update the main content by replacing fragments
    /*
     * Fragment fragment = new HomePage(); Bundle args = new Bundle();
     * args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
     * fragment.setArguments(args);
     */
    pos = position;
    FragmentManager fragmentManager = getFragmentManager();
    switch (pos) {
    case 0:
        fragmentManager.beginTransaction().replace(R.id.content_frame, new Fragment_Statistics()).commit();
        break;
    case 1:
        break;
    case 2:
        fragmentManager.beginTransaction().replace(R.id.content_frame, new Country()).commit();
    case 3:break;
    case 4:break;
    case 5:break;
    }
    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getActionBar().setTitle(mTitle);
}

/**
 * When using the ActionBarDrawerToggle, you must call it during
 * onPostCreate() and onConfigurationChanged()...
 */

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Pass any configuration change to the drawer toggls
    mDrawerToggle.onConfigurationChanged(newConfig);
}
}

Homeactivity中使用的DrawerItemclass如下

public class DrawerItem {

String ItemName;
int imgResID;

public DrawerItem(String itemName, int imgResID) {
      super();
      ItemName = itemName;
      this.imgResID = imgResID;
}

public String getItemName() {
      return ItemName;
}
public void setItemName(String itemName) {
      ItemName = itemName;
}
public int getImgResID() {
      return imgResID;
}
public void setImgResID(int imgResID) {
      this.imgResID = imgResID;
}}

有人能看出我错在哪里吗?提前致谢..

DrawerItemHolder class 应该是 public,或者至少不应该是私有的。