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

时间:2015-11-01 17:42:39

标签: java android import

您好我导入support.v7.appcompat有问题。我将android.support.v7.app.AppCompatActivity导入我的libs文件夹,但是当我开始运行时,我得到了这个日志:

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)

这是我的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);

    }

}

我在其他帖子中看到了这个问题的一些解决方案,但它对我的情况不起作用。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

如果您使用的是Android Studio,请将此行放在build.gradle文件中

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

答案 1 :(得分:0)

如果您使用的是Eclipse

  • 从libs文件夹中删除jar。
  • 在eclipse工作区中导入sdk \ extras \ android \ support \ v7 \ appcompat \ project。
  • 确保项目中的android-support-v4.jar相同。
  • 将appcompat作为库添加到项目中。

确保您在Manifest.xml中的活动具有正确的主题

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

如果您使用的是Android Studio

将此行放在build.gradle文件

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