Reputation: 543
I'm writing an app in Xamarin for Android, and all is going well, but all of a sudden, i'm getting this "java.lang.illegalStateExeption error when i run the program.
I have done nothing to the code that might have caused this, and i've even gone back to copies of the program that i've backed up, where i know there was nothing wrong, and it's still throwing the exception.
The exception is thrown on the first line of the OnCreate method, here:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState); // error thrown here
and this is the error:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
At the top of the Main activity, i DO declare an AppCompat theme, like this:
[Activity(Label = "FrogPoint", Theme = "@style/Theme.AppCompat.Light", LaunchMode = LaunchMode.SingleTask, ScreenOrientation = ScreenOrientation.Portrait)] //master copy
public class MainActivity : ActionBarActivity, IBeaconConsumer
{
this is driving me nuts, particularly as it's just started happening for no apparent reason. Every time the app runs, the error is thrown.
I have tried both with, and without, the following in the Android Manifest:
<activity android:name="MainActivity" android:theme="@style/Theme.AppCompat" android:label="@string/app_name"></activity>
It makes no difference.
Can anybody please help?
Here is the stack trace:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:102)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at frogpoint.droid.MainActivity.n_onCreate(Native Method)
at frogpoint.droid.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Upvotes: 2
Views: 2261
Reputation: 543
The problem was a corrupt Resource.Designer file. I deleted it from the project, then rebuilt the project and added the file back (it doesn't add it back to the project automatically). Then the problem was gone!
Upvotes: 2