I have a class that were extending FragmentActivity and importing android library v4. Now that I want to implement Navigation Drawer in my activity, I'd like to extend ActionBarActivity. And since ActionBarActivity also implements FragmentActivity, I've been told that I could still use fragments in my class with ActionBarActivity.
So I start working with ActionBarActivity, first by importing the v7 library. I copied the file from
C:\Program Files\Android Developer Tools\sdk\extras\android\support\v7
to the libs folder in my app folder on workspace.
Now my Eclipse detects no errors with my class extending ActionBarActivity. However when I run it, it crashes.
Here's some information found at my LogCat (I wonder if it coulp help at any point):
03-27 16:30:12.113: E/AndroidRuntime(8130): FATAL EXCEPTION: main
03-27 16:30:12.113: E/AndroidRuntime(8130): Process: com.anggrian.readee, PID: 8130
03-27 16:30:12.113: E/AndroidRuntime(8130): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
03-27 16:30:12.113: E/AndroidRuntime(8130): at com.anggrian.readee.MainActivity.onCreate(MainActivity.java:37)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.Activity.performCreate(Activity.java:5231)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.access$800(ActivityThread.java:145)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.os.Handler.dispatchMessage(Handler.java:102)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.os.Looper.loop(Looper.java:136)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.main(ActivityThread.java:5081)
03-27 16:30:12.113: E/AndroidRuntime(8130): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 16:30:12.113: E/AndroidRuntime(8130): at java.lang.reflect.Method.invoke(Method.java:515)
03-27 16:30:12.113: E/AndroidRuntime(8130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
03-27 16:30:12.113: E/AndroidRuntime(8130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-27 16:30:12.113: E/AndroidRuntime(8130): at dalvik.system.NativeStart.main(Native Method)
I wonder if I could get any help, thanks!
#Raghunandan here's my styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- MY OWN THEME -->
<style name="DarkGreyTheme" parent="#android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/DarkGreyActionBar</item>
</style>
<style name="DarkGreyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#b6b6b6</item>
</style>
<!-- MY OWN THEME -->
<style name="OrangeTheme" parent="#android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/OrangeActionBar</item>
</style>
<style name="OrangeActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#ff6400</item>
</style>
</resources>
the AppTheme is not used in AndroidManifest.xml so just ignore them. I used to use #android:style/Theme.Holo.Light in my custom themes but since I already extending ActionBarActivity in my main class, LogCat indicates I need to use AppCompat Theme.
java.lang.NoClassDefFoundError:
android.support.v7.appcompat.R$styleable
AppCompat is a library project with resources. You need to reference AppCompat in your Android project.
You could also check this a similar one i answered before. Found it now
No resource found that matches the given name '#style/Theme.AppCompat.Light'
You can follow the steps # Adding libraries with resources in the below link
https://developer.android.com/tools/support-library/setup.html
Donwload the support library from sdk manager
Import library project to workspace. Can be found #
sdk>/extras/android/support/v7/appcompat/
After importing
Right click on your Android Project. Goto Properties. Choose Android. Click Add and choose AppCompact. Click OK. You should see a green tick upon success.
After Referencing
You are done.
In Eclipse: File->Import->Existing Android Code into Workspace-> Next. Go to Browse and locate the project "C:\Program Files\Android Developer Tools\sdk\extras\android\support\v7" (in your case) and import it.
Then right click on your project -> Properties. Go to Android section on top left. In the bottom window called "Library" click Add and choose the support project you've just imported.
Make sure you import the ActionBar from import android.support.v7.app.ActionBarActivity and not from the import android.app.ActionBar.
Add suppor library jar using the Java Build Path
I had the same problem and tried whole bunch of things (themes, importing external appcompat jars etc).
The only one helped to me:
1) manually copy android-support-v4.jar and android-support-v7-appcompat.jar to the lib folder of the project;
2) right click on the project -> Properties -> Libraries -> Add JARs (not external jars) - > select jars from the lib folder (which we copied on step 1) -> Order and Export tap -> Uncheck old support libraries and check new, which we just added. -> OK.
Related
I know that this question has been asked before, but the provided answers did not solve my case, so I'll ask for an individual solution.
My code
My AndroidManifest.xml looks like this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".KategorieAuswahl"
android:label="#string/title_activity_kategorie_auswahl" >
</activity>
<activity
android:name=".ZeigeFragen"
android:label="#string/title_activity_zeige_fragen" >
</activity>
</application>
And my styles.xml looks like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
I want my App to open in fullscreen and to hide the TitleBar. The first thing I did was to add a android:theme="#android:style/Theme.NoTitleBar.Fullscreen" attribute to the <application>-Tag of my AndroidManifest.xml.
This leads to the error You need to use a Theme.AppCompat theme (or descendant) with this activity. Here is the full stacktrace:
05-27 21:24:26.889 2121-2121/de.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.test.myapp/de.test.myapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at de.test.myapp.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
There are multiple questions on stackoverflow referencing this error.
Approach #1
One solution suggests to change the Java inheritance from ActionBarActivity to Activity and leave the manifest as it is.
So I updated my the <style> element in my styles.xml and removed the DarkActionBar part:
<style name="AppTheme" parent="Theme.AppCompat.Light">
This still gives me the same error.
Approach #2
The next solution suggests to change my styles.xml's parent attribute from
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to <style name="AppTheme" parent="Theme.AppCompat">
This makes it possible to use android:theme="#style/Theme.AppCompat.NoActionBar" for my <activity>, but I don't see an option to make it fullscreen then.
Approach #3
Another solution soggests to add <item name="android:windowNoTitle">true</item> to my <style> element but this doesn't change anything at all.
Conclusion
I really tried a lot, but nothing seems to work. Anyway I have problems understanding the theme inheritance chain and when I may use .NoTitleBar and .Fullscreen.
After all I don't care which theme to use, as long I can make the app fullscreen without a title bar. Can you help me to pick the right attributes?
extend ActionBarActivity or the new one, and use Theme.AppCompat.NoActionBar, now in your Activity
if (Build.VERSION.SDK_INT < 16) {
Activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}else{
Activity.getWindow().getDecorView().
setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
Hope it helps..
I updated my support library from r20 to r21, now when I run my app I get this error in super.onCreate of my main activity :
java.lang.NoSuchFieldError: android.support.v7.appcompat.R$styleable.Theme_windowActionBar
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:145)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:139)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at (packageName).Main.onCreate(Main.java:64)
at android.app.Activity.performCreate(Activity.java)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.access$700(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
my theme.xml :
<style name="AppBaseTheme" parent="Theme.AppCompat">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item> ... </item>
</style>
in manifest :
android:theme="#style/AppTheme"
what is the problem ?
thanks
It happened same to me when I update SDK. If you have version 21 of library "Android Support Library" this bug occurs. I don't know what is the reason but last release make this bug.
You can solve it by downloading previous version of "Android Support Library" (r20) from here: https://dl-ssl.google.com/android/repository/support_r20.zip, and using it in your project.
You are welcome!
I have compared support_v7_appcompat (version 20) with support_v7_appcompat (version 21). In res/values/attrs.xml (version 21), windowActionBar attributes are not in <declare-styleable name="Theme">
if you use intellij => you have to add in /project strutures/modules/ => YOURSDK\extras\android\support\v7\appcompat and add after in your project
like that you have always the last support
I'm new to android programming and started a sample hello world program, but stuck with below error:
07-05 13:52:20.830: W/dalvikvm(898): threadid=1: thread exiting with uncaught exception (group=0xb2ac4d70)
07-05 13:52:20.850: E/AndroidRuntime(898): FATAL EXCEPTION: main
07-05 13:52:20.850: E/AndroidRuntime(898): Process: com.example.helloandroid, PID: 898
07-05 13:52:20.850: E/AndroidRuntime(898): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.os.Handler.dispatchMessage(Handler.java:102)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.os.Looper.loop(Looper.java:136)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.main(ActivityThread.java:5026)
07-05 13:52:20.850: E/AndroidRuntime(898): at java.lang.reflect.Method.invokeNative(Native Method)
07-05 13:52:20.850: E/AndroidRuntime(898): at java.lang.reflect.Method.invoke(Method.java:515)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-05 13:52:20.850: E/AndroidRuntime(898): at dalvik.system.NativeStart.main(Native Method)
07-05 13:52:20.850: E/AndroidRuntime(898): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.Activity.setContentView(Activity.java:1930)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.example.helloandroid.MainActivity.onCreate(MainActivity.java:13)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.Activity.performCreate(Activity.java:5242)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
Manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.helloandroid.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.Java
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello" />
</RelativeLayout>
Please help me to find out where I'm going wrong, I am currently on Android 4.3, API 18,
I've tried Android 4.0.3 API 15, Android 4.4W API 20; I have also tried editing sdk as below, but no luck.
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
4.4W is Android Wear SDK. (dont target to android wear device)
try changing target sdk version to 19
As mentioned in another answer:
Do not use API Level of 20 and Platform 4.4W, as Android Virtual Device. With Level 19 and Platform 4.2.2 set on ADV everything runs as it should.
I had the same issue. But sdk version was not the cause for this exception.
In the AndroidManifest.xml file you have the theme has ActionBar in it.
android:theme="#style/AppTheme" >
Change the above line to
android:theme="#android:style/Theme.DeviceDefault" >
That will fix the exception.
4.4W is Android Wear SDK.
This error is because the device you are targeting is Android Wear which has a different design pattern.
If you are developing a mobile application, change your AVD and target any API below 20 or choose API 20 (L preview).
Or if you are really targeting for Android Wear, change your app design.
Am using Android Studio beta 0.8.6 with java 7.
I had the same issue. And fixed it this way.
In the AndroidManifest.xml file you have the theme has ActionBar in it.
android:theme="#style/AppTheme" >
Change the above line to
android:theme="#android:style/Theme.DeviceDefault" >
That will fix the exception.
As mentioned by Gangadhar in prev answer ,sdk version was not the cause for this exception.
And tested it with helloWorld app.
I got this error because I tried to run the mobile part of a wear project on the Samsung Gear device. After switching from "mobile" to "wear" in the run configurations, everything worked (API level 20 and platform 4.4W is indeed the right choice in this case).
I got this problem when trying to create the project in Eclipse.
I had to add the following to the manifest file:
<uses-feature android:name="android.hardware.type.watch" />
go to values/styles.xml and set the styles as follow:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
Also, in folders res/values-v11 and res/values-v14, and all folders in values-vxx change the styles.xml file as follows:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
You have not to add action bar themes as they are not compatible with wear devices.
Change target sdk version to 19
Install API level 19 and platform 4.4.2
Use API level 19 & platform 4.4.2 while running application in AVD.
I have struggle a lot to fix the issue. Nothing work for me except the changes I made in AndroidManifest.xml.
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="21" />
Remove android:targetSdkVersion, it worked for me, you can also try.
I've a View with a custom theme as explained here and that solves the issue described but causes the following error when i call visible() on ActivityController.
android.content.res.Resources$NotFoundException: Resource ID #0x7f0c0000
at android.content.res.Resources.getValue(Resources.java:1118)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2304)
at android.content.res.Resources.getLayout(Resources.java:934)
at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:115)
at com.myCompany.myApp.activities.LogActivity.onCreateOptionsMenu(LogActivity.java:36)
at android.app.Activity.onCreatePanelMenu(Activity.java:2504)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:147)
at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199)
at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:285)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:413)
at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:775)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:198)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:37)
at org.robolectric.shadows.ShadowLooper.post(ShadowLooper.java:207)
at org.robolectric.shadows.ShadowHandler.postDelayed(ShadowHandler.java:56)
at android.os.Handler.postDelayed(Handler.java)
at android.view.ViewRootImpl$RunQueue.executeActions(ViewRootImpl.java:6230)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1239)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:664)
at org.robolectric.shadows.ShadowHandler.routeMessage(ShadowHandler.java:125)
at org.robolectric.shadows.ShadowHandler.access$100(ShadowHandler.java:25)
at org.robolectric.shadows.ShadowHandler$1.run(ShadowHandler.java:110)
at org.robolectric.util.Scheduler$PostedRunnable.run(Scheduler.java:162)
at org.robolectric.util.Scheduler.runOneTask(Scheduler.java:107)
at org.robolectric.util.Scheduler.advanceTo(Scheduler.java:92)
at org.robolectric.util.Scheduler.advanceToLastPostedRunnable(Scheduler.java:68)
at org.robolectric.util.Scheduler.unPause(Scheduler.java:25)
at org.robolectric.shadows.ShadowLooper.unPause(ShadowLooper.java:228)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:267)
at org.robolectric.util.ActivityController.visible(ActivityController.java:201)
at com.myCompany.myApp.test.activities.LogActivityTest.setUp(LogActivityTest.java:50)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:230)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:172)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Here is the syle.xml file which contains the custom theme
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="Theme.RobolectricCompatible" parent="#style/Theme.Base.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">false</item>
</style>
and this is the activity block in which I set the theme
<activity
android:name=".activities.LogActivity"
android:label="#string/log_activity_title"
android:parentActivityName="com.myApp.activities.MainActivity"
android:theme="#style/Theme.RobolectricCompatible" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.myApp.activities.MainActivity" />
</activity>
I've another Activity which uses Theme.Base.AppCompat.Light.DarkActionBar theme and I can test it correctly, but if I change the theme to Theme.RobolectricCompatible it shows the same behavior.
Finally this is what Eclipse output when I run the tests:
DEBUG: Loading resources for com.myCompany.myApp from C:\Users\luca\Android\myAppTest\..\myApp\res...
DEBUG: Loading resources for android.support.v7.appcompat from C:\Users\luca\Android\myAppTest\..\myApp\..\android-support-v7-appcompat\res...
DEBUG: Loading resources for android from jar:C:\Users\luca\.m2\repository\org\robolectric\android-all\4.3_r2-robolectric-0\android-all-4.3_r2-robolectric-0.jar!/res...
Please note that the paths point to the right res directories.
Without calling visible() I don't get any error but I need to test some menuItem s which are initialized inside onCreateOptionsMenu() which, in turn, is called inside visible() ( I've already tried to call the method by myself passing a TestMenu object but it didn't work (and is also deprecated))
I'm using robolectric 2.2 but I've also tried with 2.3-SNAPSHOT
I'd really appreciate any help because I've run out of ideas.
The problem is because you use support library and robolectric is not compatible with it. The same happens with ActionBarSherlock.
Luckily the problem has already it's solution. This worked for me.
According to sneuberger-amazon's post on https://github.com/robolectric/robolectric/issues/:
The problem is that Robolectric provides a ShadowMenuInflater, but it does not provide a ShadowSupportMenuInflater (which is what
appcompat uses).
You can fix this by creating a
org.robolectric.shadows.ShadowSupportMenuInflater class with contents:
package org.robolectric.shadows;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import android.support.v7.internal.view.SupportMenuInflater;
import android.view.Menu;
#Implements(SupportMenuInflater.class)
public class ShadowSupportMenuInflater extends ShadowMenuInflater {
#Implementation
public void inflate(int menuRes, Menu menu) {
super.inflate(menuRes, menu);
}
}
Put this class in your own project's org.robolectric.shadows package.
That way Robolectric will find it when looking for a shadow for
SupportMenuInflater, so that all your tests will get it automatically
(no need to add a shadow Config to every test).
With Robolectric 2.3, try annotating your test class with
#Config(qualifiers = "v10")
I'm trying to implement the new v7 Support Library ActionBar. However, I can't get it to run properly.
Here's the exception
07-25 09:30:01.704: E/AndroidRuntime(9175): FATAL EXCEPTION: main
07-25 09:30:01.704: E/AndroidRuntime(9175): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:98)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
07-25 09:30:01.704: E/AndroidRuntime(9175): at com.cidaut.termoweb.MainActivity.onCreate(MainActivity.java:23)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.Activity.performCreate(Activity.java:5133)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.os.Looper.loop(Looper.java:137)
07-25 09:30:01.704: E/AndroidRuntime(9175): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-25 09:30:01.704: E/AndroidRuntime(9175): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 09:30:01.704: E/AndroidRuntime(9175): at java.lang.reflect.Method.invoke(Method.java:525)
07-25 09:30:01.704: E/AndroidRuntime(9175): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-25 09:30:01.704: E/AndroidRuntime(9175): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 09:30:01.704: E/AndroidRuntime(9175): at dalvik.system.NativeStart.main(Native Method)
The problem happens at the super.onCreate(bundle) call at onCreate().
Here's all my theming related XML:
styled.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Termoweb" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarItemBackground">#drawable/selectable_background_termoweb</item>
<item name="popupMenuStyle">#style/PopupMenu.Termoweb</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Termoweb</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Termoweb</item>
<item name="actionDropDownStyle">#style/DropDownNav.Termoweb</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Termoweb</item>
<item name="actionModeBackground">#drawable/cab_background_top_termoweb</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_termoweb</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Termoweb</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">#style/Theme.Termoweb.Widget</item>
</style>
<style name="ActionBar.Solid.Termoweb" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/ab_solid_termoweb</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_termoweb</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_termoweb</item>
<item name="progressBarStyle">#style/ProgressBar.Termoweb</item>
</style>
<style name="ActionBar.Transparent.Termoweb" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/ab_transparent_termoweb</item>
<item name="progressBarStyle">#style/ProgressBar.Termoweb</item>
</style>
<style name="PopupMenu.Termoweb" parent="#style/Widget.AppCompat.ListView.Menu">
<item name="popupBackground">#drawable/menu_dropdown_panel_termoweb</item>
</style>
<style name="DropDownListView.Termoweb" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="listSelector">#drawable/selectable_background_termoweb</item>
</style>
<style name="ActionBarTabStyle.Termoweb" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="background">#drawable/tab_indicator_ab_termoweb</item>
</style>
<style name="DropDownNav.Termoweb" parent="#style/Widget.AppCompat.Spinner">
<item name="background">#drawable/spinner_background_ab_termoweb</item>
<item name="popupBackground">#drawable/menu_dropdown_panel_termoweb</item>
<item name="dropDownSelector">#drawable/selectable_background_termoweb</item>
</style>
<style name="ProgressBar.Termoweb" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="progressDrawable">#drawable/progress_horizontal_termoweb</item>
</style>
<style name="ActionButton.CloseMode.Termoweb" parent="#style/Widget.AppCompat.ActionButton.CloseMode">
<item name="background">#drawable/btn_cab_done_termoweb</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Termoweb.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Termoweb</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Termoweb</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cidaut.termoweb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Termoweb" >
<activity
android:name="com.cidaut.termoweb.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
So, how I solved this problem:
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 doesn't worked - clean and rebuild project.
I have done the following and worked for me.
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"
>
Good Luck ;)
In addition to BoredT's answer I added this line to res/values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
Follow steps from Adding libraries with resources -> Eclipse http://developer.android.com/tools/support-library/setup.html :
follow all the steps (use copy project in workspace)
add android.library.reference.1=../android-support-v7-appcompat to your project.properties
use android:theme="#style/Theme.AppCompat" I used it in application tag you can apply to individual activities as well
Rebuild all!
I think you should change your target version to 18 in the manifest.
android:targetSdkVersion="18"
This is how I solve the problem: rebuild the adroid-support-v7-appcompat library project in your eclipse workspace. Then build your own project again.
How to import a project as a library in android studio? Follow the tips blog as a reference:
http://showlabor.blogspot.com.br/2013/05/actionbarsherlock-in-android-studio-01.html
The next question, also helped a lot:
Error implementing Support Library Action Bar
The following image shows the structure of the imported project. That is copied to the root of my project and placed in the directory 'libraries':
https://dl.dropboxusercontent.com/u/67269258/Tuto/tree.PNG
In addition to mounting the above structure. In 'settings.glade' I had to add the new project:
include ':FreeMusic', ':libraries:ActionBarCompat:appcompat'
Inside the library project, added the file 'build.gradle'
It is located in: libraries/ActionBarCompat/appcompat
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile files(
'libs/android-support-v4.jar',
'libs/android-support-v7-appcompat.jar'
)
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
In 'build.gradle' (internal project) of my project.
dependencies {
compile project(':libraries:ActionBarCompat:appcompat')
}
In android manifest added the necessary theme:
<activity
android:theme="#style/Theme.AppCompat"
android:name="es.hol.soundmedia.MainActivity"
After all this work. Perhaps an easier way to set this up, but for me the account is working.
Unfortunately I can not show the result, because I'm being blocked, but I hope the instructions help.
For those that don't like needing manual user effort in Eclipse in order to do a build from checkout, the magical change that Eclipse makes is to add a line to project.properties like:
android.library.reference.1=../android-support-v7-appcompat
This is enough to build your application from ant. You can do this in the source yourself, or via the Eclipse user interface - either way you can check it in to your version control system and successfully build from a fresh checkout of the source without requiring manual steps.
But you can instead make the path a sub-directory of your own project if that suits better, E.g.
android.library.reference.1=android-support-v7-appcompat
... and ...
cp -r $SDK/extras/android/support/v7/appcompat android-support-v7-appcompat
Note that Eclipse will still show various warnings until the sub-directory is also added [manually!] to Eclipse's workspace as a project. But an ant build will successfully build without using Eclipse.
Check for R.java for appcompat v7 jar is present in your generated folders of your application