简体   繁体   中英

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable error

Hi i have a problem with importing support.v7.appcompat. I imported android.support.v7.app.AppCompatActivity to my libs folder, but when i start running i get this log:

11-01 17:35:42.669: E/AndroidRuntime(1873): FATAL EXCEPTION: main
11-01 17:35:42.669: E/AndroidRuntime(1873): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:109)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at morisson.Notowaniagieldowe.MainActivity.onCreate(MainActivity.java:17)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.Activity.performCreate(Activity.java:5104)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.os.Looper.loop(Looper.java:137)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at android.app.ActivityThread.main(ActivityThread.java:5041)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at java.lang.reflect.Method.invokeNative(Native Method)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at java.lang.reflect.Method.invoke(Method.java:511)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-01 17:35:42.669: E/AndroidRuntime(1873):     at dalvik.system.NativeStart.main(Native Method)

and here is my MainActivity:

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;


public class MainActivity extends AppCompatActivity {




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);



        // Get the ViewPager and set it's PagerAdapter so that it can display items
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(new SampleFragmentPagerAdapter(getSupportFragmentManager(), 
            MainActivity.this));

        // Give the TabLayout the ViewPager
        TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
        tabLayout.setupWithViewPager(viewPager);

    }

}

I have seen some solution for this problem in other posts but it does not work for my case. Any suggestions?

If you are using Android Studio then put this line inside your build.gradle file

    dependencies {
    compile "com.android.support:appcompat-v7:21.0.+"
}

If you are using Eclipse

  • Delete the jar from the libs folder.
  • Import the sdk\\extras\\android\\support\\v7\\appcompat\\ project in your eclipse workspace.
  • Ensure that the android-support-v4.jar is the same in your project.
  • Add the appcompat as a library to your project.

Ensure that your in yout Manifest.xml your activity has the correct theme

<activity
    android:name="***.*****.******"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light"
     >

And if your are using Android Studio

Put this line inside your build.gradle file

dependencies {
  compile "com.android.support:appcompat-v7:21.0.+"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM