0

I just new in android development. In fact I started it just earlier this afternoon. I follow the instruction in this link.

https://developer.android.com/training/basics/firstapp/creating-project.html

I just rename it as hello2.

Everything seems perfect except when I was trying to run it in AVD. My logcat keeps popping some errors. And the emulator display "Unfortunately, hello2 has stopped."

can somebody out there help me?

this is my java file

package com.example.hello2;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

this is my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hello2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <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>

and this is my logcat:

07-20 13:22:25.760: W/dalvikvm(960): threadid=1: thread exiting with uncaught exception (group=0xb3af1d70)
07-20 13:22:25.780: E/AndroidRuntime(960): FATAL EXCEPTION: main
07-20 13:22:25.780: E/AndroidRuntime(960): Process: com.example.hello2, PID: 960
07-20 13:22:25.780: E/AndroidRuntime(960): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hello2/com.example.hello2.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.os.Handler.dispatchMessage(Handler.java:102)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.os.Looper.loop(Looper.java:136)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.main(ActivityThread.java:5026)
07-20 13:22:25.780: E/AndroidRuntime(960):  at java.lang.reflect.Method.invokeNative(Native Method)
07-20 13:22:25.780: E/AndroidRuntime(960):  at java.lang.reflect.Method.invoke(Method.java:515)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-20 13:22:25.780: E/AndroidRuntime(960):  at dalvik.system.NativeStart.main(Native Method)
07-20 13:22:25.780: E/AndroidRuntime(960): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Activity.setContentView(Activity.java:1930)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.example.hello2.MainActivity.onCreate(MainActivity.java:13)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Activity.performCreate(Activity.java:5242)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-20 13:22:25.780: E/AndroidRuntime(960):  ... 11 more

I hope somebody can help me..

PS: sorry for the bad English.

Red_X
  • 51
  • 1
  • 1
  • 7

3 Answers3

1

As you are using ActionBarActivity and the target SDK set for your activity is not works with ActionBarActivity. Either change API version or only use extends "Activity" instead of "ActionBarActivity"

0

Which API are you targeting? You can check that in your manifest. If you are targeting API 20, change it to 19 and it should work.

Hope it helps.

AlexBalo
  • 1,258
  • 1
  • 11
  • 16
  • the issue was very simple, and it was a shame that I need to ask a question, I followed Simon's advice to get rid the targetSDKVersion. Actually, I didn't code the manifest file. It was automatically generated by the eclipse. I'm just confuse, why the eclipse generate a manifest file that has a bug? Why do I need to remove the targetSDKVersion? – Red_X Jul 21 '14 at 11:27
  • You need to have the targetSDKVersion and it must but the last available SDK version. But for now you should use 19 because 20 is still in beta and under development. You definitely need to declare targetSDK. Checkout the link http://developer.android.com/guide/topics/manifest/uses-sdk-element.html – AlexBalo Jul 21 '14 at 12:20
  • right now, the problem occurs again. -_- I really dont know what to do. I dont know what the problem is. – Red_X Jul 22 '14 at 11:18
  • I dont know whats wrong with my Eclipse, I'm using Eclipse Luna. My plugins are, Android L (API20, L preview), Android 4.4W(API20) – Red_X Jul 22 '14 at 12:16
  • But if you put targetSDK to 19 and minSdk to whatever you need to support...what happens? – AlexBalo Jul 22 '14 at 12:33
  • the error is still there, well, I'm going to download the API 19. Can I pm you? I really need some help. – Red_X Jul 27 '14 at 03:17
  • Yeah sure. Obviously if you don't have it...you need to download the API – AlexBalo Jul 27 '14 at 13:24
0

hey RED_x if we removed the target sdk version it worked for me 2 !! was there a problem later?

  • I think so? because when I start following some instruction for a simple program, I can't make it run. – Red_X Jul 27 '14 at 03:15