The question:
If someone could help me with this. I downloaded AndroidSDK and everything else needed for android programming, and I faced some problems with (funny to say) hello world.
I just do not get the thing with tarketSdkVersion setting in AppManifest. Whenever it is not set to “13” (just noticed 8 which is my minSdkVersion is working also) application has “Unfortunately application stopped working” screen with this in LogCat:
07-01 01:26:47.820: E/AndroidRuntime(902): FATAL EXCEPTION: main
07-01 01:26:47.820: E/AndroidRuntime(902): Process: pl.bbZoftware.eclipsestandalone, PID: 902
07-01 01:26:47.820: E/AndroidRuntime(902): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.bbZoftware.eclipsestandalone/pl.bbZoftware.eclipsestandalone.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.os.Handler.dispatchMessage(Handler.java:102)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.os.Looper.loop(Looper.java:136)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.main(ActivityThread.java:5026)
07-01 01:26:47.820: E/AndroidRuntime(902): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 01:26:47.820: E/AndroidRuntime(902): at java.lang.reflect.Method.invoke(Method.java:515)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-01 01:26:47.820: E/AndroidRuntime(902): at dalvik.system.NativeStart.main(Native Method)
07-01 01:26:47.820: E/AndroidRuntime(902): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-01 01:26:47.820: E/AndroidRuntime(902): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.Activity.setContentView(Activity.java:1930)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-01 01:26:47.820: E/AndroidRuntime(902): at pl.bbZoftware.eclipsestandalone.MainActivity.onCreate(MainActivity.java:14)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.Activity.performCreate(Activity.java:5242)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-01 01:26:47.820: E/AndroidRuntime(902): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-01 01:26:47.820: E/AndroidRuntime(902): ... 11 more
07-01 01:26:55.340: I/Process(902): Sending signal. PID: 902 SIG: 9
I do not get if this is intentional, I got some SDK errors or something else.
I was googling for answers but coulnt find any. Tell me if I should add some more info from project, looking for your answers.
EDIT: Forgot to add, I got an android device with 4.4.2 KitKat so I wanted to make project target set to 20. That is how I noticed this errors.
EDIT2:
@Override
protected 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="pl.bbZoftware.eclipsestandalone.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
EDIT3:
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.bbZoftware.eclipsestandalone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="13" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
I just found where the problem was.
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.
Method 2
Just remove android:targetSdkVersion
from AndroidManifest.xml
Make following changes:
From
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
To:
<uses-sdk android:minSdkVersion="8" />
Method 3
Most probably you are making mistake on activity_main.xml
Also target for 4.4.2 Kitkat is 19. Have a check in this android api levels page.
Method 4
ChangetargetSdkVersion
in [project directory]appbuild.gradle
to something less than or equal to 19. Change:
defaultConfig {
applicationId '....'
minSdkVersion 8
targetSdkVersion 21
}
To:
defaultConfig {
applicationId '....'
targetSdkVersion 19
}
Method 5
Android API 20 gives compilation issues. Make sure to be using the API 19 and set it as a Targeted SDK during development.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0