I just instilled Android Studio and when I run the sample project hello world in the emulator it gives me my project has stopped and it doesn't work
myActivity.java
package b3du.im.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
public class MyActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
}
}
activity_my.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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MyActivity">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="b3du.im.myapplication" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
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>
logcat error
08-01 05:13:56.557 1884-1884/b3du.im.myapplication I/Process﹕ Sending signal. PID: 1884 SIG: 9
08-01 05:21:26.244 1944-1944/b3du.im.myapplication D/AndroidRuntime﹕ Shutting down VM
08-01 05:21:26.244 1944-1944/b3du.im.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb2cc9b20)
08-01 05:21:26.284 1944-1944/b3du.im.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: b3du.im.myapplication, PID: 1944
java.lang.RuntimeException: Unable to start activity ComponentInfo{b3du.im.myapplication/b3du.im.myapplication.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
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.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at b3du.im.myapplication.MyActivity.onCreate(MyActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
This is because you are using ActionBarActivity, which requires the AppCompat theme to be applied.
Either use that theme, Or use simple Activity. See a similar issue
as Stated by MysticMagic change ActionBarActivity to Activity or change your theme to AppCompat
explore package got to res-> values->style.xml and change style
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
Your issue is with AppTheme that you have set currently in you app.
Caused by: 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:108)
You are inheriting you from ActionBarActivity so you have to use Theme.AppCompat for your application. Change app base theme in styles.xml to
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
If you are facing issue in loading this theme than please follow the below link to resolve compilation issue.
Can't Find Theme.AppCompat.Light for New Android ActionBar Support
Related
I am following a tutorial on how to make a launcher but for some reason when I add this line of code to my main activity with in the manifest the app crashes saying that my app has stopped
android:theme="#android:style/Theme.Holo.Wallpaper.NoTitleBar"
10-18 15:04:25.245 18122-18122/com.example.harrops.h20droidlauncher E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.harrops.h20droidlauncher, PID: 18122
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.harrops.h20droidlauncher/com.example.harrops.h20droidlauncher.HomeLayout}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5598)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
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.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.harrops.h20droidlauncher.HomeLayout.onCreate(HomeLayout.java:13)
at android.app.Activity.performCreate(Activity.java:5459)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5598)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
if I remove the line of code the app runs just fine.
Any help would be great. Thanks as always in advance.
To change the Background use:
android:background=" "
You selected a wallpaper.
Try this instead
android:background="#b6db49">
Below you have said that you want to use the theme. So you have to go in the manifest and edit the theme there which is
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Wallpaper.NoTitleBar">
If You've begun Your project in Android Studio by default main activity extends
ActionBarActivity which requires the AppCompat theme. Change the Java inheritance from ActionBarActivity to Activity and leave the theme in the manifest as it is. Or use AppCompat theme.
I am attempting to try out the new Material Theme in Android.
I am currently stuck with this exception
03-06 09:35:50.177: D/AndroidRuntime(30607): Shutting down VM
03-06 09:35:50.178: E/AndroidRuntime(30607): FATAL EXCEPTION: main
03-06 09:35:50.178: E/AndroidRuntime(30607): Process: com.example.vivz, PID: 30607
03-06 09:35:50.178: E/AndroidRuntime(30607): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vivz/com.example.vivz.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.os.Handler.dispatchMessage(Handler.java:102)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.os.Looper.loop(Looper.java:135)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-06 09:35:50.178: E/AndroidRuntime(30607): at java.lang.reflect.Method.invoke(Native Method)
03-06 09:35:50.178: E/AndroidRuntime(30607): at java.lang.reflect.Method.invoke(Method.java:372)
03-06 09:35:50.178: E/AndroidRuntime(30607): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-06 09:35:50.178: E/AndroidRuntime(30607): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-06 09:35:50.178: E/AndroidRuntime(30607): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
03-06 09:35:50.178: E/AndroidRuntime(30607): at com.example.vivz.MainActivity.onCreate(MainActivity.java:10)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.Activity.performCreate(Activity.java:5933)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
03-06 09:35:50.178: E/AndroidRuntime(30607): ... 10 more
My main activity extends android.support.v7.app.ActionBarActivity
My res/values/styles.xml resembles this
<resources>
<style name="Theme.Styled" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
</resources>
My res/values-v21/styles.xml resembles this
<!-- Activity themes -->
<style name="Theme.Styled" parent="android:Theme.Material.Light">
</style>
My application is running on a Nexus 7 with Android 5.0.2
my manifest file looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vivz"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Styled" >
<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>
</application>
</manifest>
I can make my application start by deleting the styles.xml file from my res/values-v21 folder.
I do not understand whats wrong and why removing the reference to the one theme I actually want to use fixes the issue.
What have I missed in my rush to try out Material?
If you're using ActionBarActivity then you need to use the ThemeCompat styles. You can only use Theme.Material if you use "Activity" instead.
You CAN still use API 21 items like tinting and elevation natively, but in order to use the native material theme you must use the Activity class.
You can still use a Material UI style while using the AppCompat libraries, however: http://android-developers.blogspot.co.uk/2014/10/appcompat-v21-material-design-for-pre.html
You are attempting to use a feature (from the design library, for example) which was introduced after your target sdk. Therefore, you need to use a couple of libraries (design and appcompat), one of which is the AppCompat Theme (backwards app compatibility).
In your Manifest file, include in your application declaration
android:theme="#style/Theme.AppCompat"
Rebuild and your problem should be solved.
I am developing an expandable list view application on which i want to add action bar.
It seems for action bar visibility I need to extend ActionBarActivity Class, but to run my Expandable list activity I should extend activity class.
So, I changed following code
from
public class Time extends Activity {
to
public class Time extends ActionBarActivity {
assuming following hierarchy
java.lang.Object
↳ android.content.Context
↳ android.content.ContextWrapper
↳ android.view.ContextThemeWrapper
↳ android.app.Activity
↳ android.support.v4.app.FragmentActivity
↳ android.support.v7.app.ActionBarActivity
But,when i run my application now i get null pointer exception at super.onCreate(savedInstanceState);
Please check log here:
12-19 00:10:48.995 14128-14128/sudharshanapps.clock E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: sudharshanapps.clock, PID: 14128
java.lang.RuntimeException: Unable to start activity ComponentInfo{sudharshanapps.clock/sudharshanapps.clock.Time}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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)
Caused by: 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:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at sudharshanapps.clock.Time.onCreate(Time.java:247)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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)
Could you please suggest, what is missing here or any references or ideas where to look for.
Changed Manifest file from
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="Time across Globe"
android:theme="#style/AppTheme" >
to
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="Time across Globe"
android:theme="#style/Theme.AppCompat.Light" >
It solved the issue
When I run my app, I am taken to an Edit Configuration screen and it says, "Default Activity not found". I believe I got this error after I tried to import a library from another app I have.
I keep getting this error even after I rebuilt my project, restarted IntelliJ IDEA and file > Invalidated Cache. I did set a main activity so I'm not sure why it says that.
Here's the exception:
Process: com.example.Device, PID: 24635
java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.IllegalStateException: Unable to get package info for com.example.Device; is package not installed?
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
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)
Caused by: java.lang.IllegalStateException: Unable to get package info for com.example.Device; is package not installed?
at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:368)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:321)
at android.app.LoadedApk.makeApplication(LoadedApk.java:500)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
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)
I can run my application anyway even though the "configuration is not set" and all is well.
Are you capable to "select" the activity from the list of activities ?
There is an activity defined in AndroidManifest as the main activity (launcher)
If it shows Edit configuration Screen and Error as "Default activity not found" then go to your manifest file and in activity tag which will be your launching activity name should be like "packageName.MainActivty" instead of ".MainActivity" see below code for your reference
<activity
android:name="com.your.package.name.YourActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I've tried everything to try to get this to work. I am trying to get a tabbed window; I followed a tutorial and made sure every step was correct but every time I load it on to the AVD, it force closes. I am an amateur, so go easy on me! Any and all help will be appreciated.
Logcat:
06-24 20:49:29.564 1146-1146/com.michail.vector E/Trace﹕ error opening trace file: No such file or directory (2)
06-24 20:49:31.997 1146-1146/com.michail.vector E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michail.vector/com.michail.vector.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.michail.vector/com.michail.vector.SimpleVector}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
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.RuntimeException: Unable to start activity ComponentInfo{com.michail.vector/com.michail.vector.SimpleVector}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:1900)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)
at android.widget.TabHost.setCurrentTab(TabHost.java:358)
at android.widget.TabHost.addTab(TabHost.java:236)
at com.michail.vector.MainActivity.onCreate(MainActivity.java:40)
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)
Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
at android.app.TabActivity.onContentChanged(TabActivity.java:131)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:259)
at android.app.Activity.setContentView(Activity.java:1867)
at com.michail.vector.SimpleVector.onCreate(SimpleVector.java:10)
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.startActivityNow(ActivityThread.java:1900)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)
at android.widget.TabHost.setCurrentTab(TabHost.java:358)
at android.widget.TabHost.addTab(TabHost.java:236)
at com.michail.vector.MainActivity.onCreate(MainActivity.java:40)
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)
06-24 20:49:40.744 148-196/system_process E/PowerManagerService﹕ Excessive delay setting brightness: 193ms, mask=2
06-24 20:49:40.883 148-196/system_process E/PowerManagerService﹕ Excessive delay setting brightness: 141ms, mask=2
06-24 20:55:06.194 148-254/system_process E/ThrottleService﹕ problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
MainActivity.java:
package com.michail.vector;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Create a new tabHost
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
/** SINGLE VECTOR TAB **/
//Used to keep track of tab
TabSpec single = tabHost.newTabSpec("Single Vector");
//Change tab indicator name and icon if necessary
single.setIndicator("Single Vector");
//Intent: Description of an operation to be performed
Intent singleIntent = new Intent(this, SimpleVector.class);
//Uses intent to launch activity as the tab content
single.setContent(singleIntent);
/** TWO VECTOR TAB**/
TabSpec two = tabHost.newTabSpec("Two Vectors");
two.setIndicator("Two Vectors");
Intent TwoIntent = new Intent(this, TwoVectors.class);
two.setContent(TwoIntent);
//Add the tabs
tabHost.addTab(single);
tabHost.addTab(two);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabhost"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tab1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout
android:id="#+id/tab2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout>
</TabHost>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.michail.vector"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="#drawable/ic_launcher"
android:label="Vectors"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="Vectors" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SimpleVector" />
<activity android:name=".TwoVectors" />
</application>
</manifest>
If I need to provide any other classes associated or xml files, please just ask. I included what I thought was necessary to answer the question. Thanks in advance.
EDIT: Instead of tabs, I've decided to use a main screen with buttons. It's a simple design and I know that it'll work
Extending TabActivity should be done like below:
TabHost mTabHost = getTabHost();
Note that tabhost is depreciated and it is recommended to use TabLayout with fragments.
Hey i just had the same problem like you but i had to extend my MainActivity from TabActivity to Activity and clean my project. every thing runned just fine. try it