嗨,我在导入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);
}
}
我在其他帖子中已经看到了针对此问题的一些解决方案,但不适用于我的情况。有什么建议么?
最佳答案
如果您使用的是Android Studio,则将此行放入build.gradle文件中
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
关于java - java.lang.NoClassDefFoundError:android.support.v7.appcompat.R $ styleable错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33465149/