ActionBarActivity - NoClassDefFoundError exception
L

3

2

Already seen: NoClassDefFoundError Android with ActionBarActivity and ActionBarActivity catch an error on Phone

I am trying to use ActionBarCompact in my project. I have linked android-support-v7 project as well as its jar in my project following and checking the steps from lots of sources, but still I am unable to deal with the problem.

When I built my project, there is no error, but there is exception at runtime. Don't know why class is not detected. Please tell me what is wrong. Thanks.

Code:

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;

public class mainMenu extends ActionBarActivity implements ActionBar.OnNavigationListener {

    ActionBar actionbar;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menutab);

        actionbar = getSupportActionBar();
        actionbar.setTitle("Menu");
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        ArrayAdapter<CharSequence> mSpinnerAdapter = ArrayAdapter.createFromResource(this,R.array.menu_items, R.id.simpleText);
        actionbar.setListNavigationCallbacks(mSpinnerAdapter, this);
    }

    @Override
    public boolean onNavigationItemSelected(int arg0, long arg1)//item pos, itemid
    {
        switch (arg0) {
        case 0:
            System.out.println("selected: " + arg0);
            break;
        case 1:
            System.out.println("selected: " + arg0);
            break;
        case 2:
            System.out.println("selected: " + arg0);
            break;
        case 3:
            System.out.println("selected: " + arg0);
            break;
        default:
            break;
        }
        return true;
    }
}

------------Project Structure and Build Path-----------------

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Logcat

enter image description here

Lorusso answered 17/9, 2013 at 11:25 Comment(15)
What is the exception? Can you post the logcat?Felton
can you post the logcat? also you might have to change the order of buildArchival
@Felton i have posted logcatLorusso
I have android-support-v7-appcompat ticked off (in order and export). It's already included in private dependencies for me.Felton
@Felton but its not included in private dependencies in my project..Lorusso
Clean your project and re-run the app, it should fix it. BTW here the logcat is showing mainMenu is missing. Have you declared it in Manifest.Antipasto
Do you have it added to Projects tab?Felton
@anum90 btw what is your package doing in gen folder. Remove it from there. This should solve your problem.Antipasto
@UmerFarooq I have already included it in manifest file. Moreover, strangely I am getting [2013-09-17 16:59:57 - android-support-v7-appcompat] Could not find android-support-v7-appcompat.apk! in console when I run app.Lorusso
@Felton yes. you can refer to the pic posted.Lorusso
@UmerFarooq package was already present before. I didn't made it. It contains R.java and buildconfigLorusso
For me it's in both Android Dependencies and Private LibrariesFelton
@anum90 restart eclipse. Sometimes problems occur because of some conflicting libraries.Antipasto
check import carefully,class must be publicMotor
Maybe this can help you: #20925667Struble
A
5

Try this:

  • Import support library as a project from "sdk/extras/android/support/v7/appcompat".

  • Reference library in your project (for Eclipse, "Properties - Android - Add").

  • Build projects (for Eclipse, "Projects - Build All"). Make sure, you have "android.support.v7.appcompat"in your main project gen folder.

If it still doesn't solve your problem, restart eclipse.

then clean and rebuild project

If the problem persists, remove the support library from you computer and redownload it and follow above mentioned steps.

Antipasto answered 17/9, 2013 at 12:20 Comment(1)
Ok. I will let u know soon.Lorusso
L
0

Get the latest versions.

Caution: Be certain you import the ActionBar class (and related APIs) from the appropriate package:

If supporting API levels lower than 11: import android.support.v7.app.ActionBar and use getSupportActionBar()

If supporting only API level 11 and higher: import android.app.ActionBar and use getActionBar()

from Google ActionBar

Longing answered 12/4, 2014 at 4:43 Comment(0)
T
0

I had not the same cause as yours, but it might help someone else.

In ADT base on eclipse, with each new Android project generate is new directory appcompat_v7. I delete duplicates directories (appcompat_7_2, etc..), because all of them using the same versions od SDK.

Then in project.properties path to android.library.reference.1 provide path to non-existing directory.

Solution:

Go to Project properties -> Android -> choose right appcompat_vX directory and delete previouse one.

Tomblin answered 20/6, 2014 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.