I'm Trying to add a toolbar to an activity. But I'm getting this error:
java.lang.NoClassDefFoundError: android.support.v7.app.ActionBarActivityDelegateBase$2
at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:304)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.loqooapps.Startup.Startup.onCreate(Startup.java:198)
at android.app.Activity.performCreate(Activity.java:5933)
The activity extends a Base Activity and in the Base activity which is abstract, I extend ActionBarActivity.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.startup);
ButterKnife.inject(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if(toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("DEMO");
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
baseApp = (App) this.getApplicationContext();
yumeInterface = YuMeInterface.getYuMeInterface();
yumeInterface.setHomeView(this);
boolean bInitSuccess = yumeInterface.initYuMeSDK();
if (!bInitSuccess) {
Log.e(TAG, "Error Initializing YuMe SDK.");
}
}
public abstract class MyBaseActivity extends ActionBarActivity{...}
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.1'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
This is my xml:
<android.support.v7 compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.1'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'.widget.Toolbar
android:id compile('com.android.support:support-v4:19.1.0') {
force = true
}="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/red"
android:elevation="3dp"
</android.support.v7.widget.Toolbar>
And this is my styles.xml:
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowDisablePreview">false</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
values-v21/styles.xml:
<style name=" compile('com.android.support:support-v4:19.1.0') {
force = true
}AppTheme" parent="AppBaseTheme">
</style>
compile('com.android.support:support-v4:19.1.0') {
force = true
}
The minsdk is set to 16 and the target is se compile('com.android.support:support-v4:19.1.0') { force = true }t to 21
build.gradle
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile('com.android.support:support-v4:19.1.0') {
force = true
}
Android Manifest:
<activity
android:name=".Startup.Startup"
android:screenOrientation="portrait"
android:theme="@style/AppBaseTheme"
The error in xml:
java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.getDrawable(Landroid/content/Context;I)Landroid/graphics/drawable/Drawable;
at android.support.v7.internal.widget.TintManager.getDrawable(TintManager.java:133)
at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:249)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:191)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:396)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:100)
at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:176)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
at android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:117)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:708)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:697)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:697)
at com.android.tools.idea.rendering.RenderService.render(RenderService.java:816)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
What gives?
The reason for my trouble pains is that all the support libs have to be the same version
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile ('com.android.support:recyclerview-v7:21.0.3') {
exclude group: 'com.android.support', module: 'support-v4'
}
//compile 'com.android.support:leanback-v17:21.0.3'
compile 'com.android.support:mediarouter-v7:21.0.3'
compile('com.android.support:support-v4:21.0.3') {
force = true
}
Above I was using....
compile('com.android.support:support-v4:19.1.0') {
force = true
}
quite simple and strange.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With