4

I'm new to Android Programming. I'm following the guide on Android Developers to get started with Android.

When trying to run simple Hello World App on the Emulator, the emulator shows "Unfortunately, My First App has stopped.", where My First App is name of the App.

This is my AndroidManifest file:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myfirstapp.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>

This is my mainactivity file:

package com.example.myfirstapp;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @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);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

This is the LogCat:

06-13 23:56:44.148: I/Process(1209): Sending signal. PID: 1209 SIG: 9
06-13 23:56:45.828: W/dalvikvm(1249): VFY: unable to resolve static field 1559 (ActionBarWindow) in Landroid/support/v7/appcompat/R$styleable;
06-13 23:56:45.828: D/dalvikvm(1249): VFY: replacing opcode 0x62 at 0x0004
06-13 23:56:45.848: D/AndroidRuntime(1249): Shutting down VM
06-13 23:56:45.848: W/dalvikvm(1249): threadid=1: thread exiting with uncaught exception (group=0xb2a6fba8)
06-13 23:56:45.878: E/AndroidRuntime(1249): FATAL EXCEPTION: main
06-13 23:56:45.878: E/AndroidRuntime(1249): Process: com.example.myfirstapp, PID: 1249
06-13 23:56:45.878: E/AndroidRuntime(1249): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:18)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.Activity.performCreate(Activity.java:5231)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.os.Handler.dispatchMessage(Handler.java:102)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.os.Looper.loop(Looper.java:136)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at android.app.ActivityThread.main(ActivityThread.java:5017)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at java.lang.reflect.Method.invokeNative(Native Method)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at java.lang.reflect.Method.invoke(Method.java:515)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-13 23:56:45.878: E/AndroidRuntime(1249):     at dalvik.system.NativeStart.main(Native Method)
06-13 23:56:53.678: I/Process(1249): Sending signal. PID: 1249 SIG: 9

This is the activity_main file:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.myfirstapp.MainActivity"
    tools:ignore="MergeRootFrame" />
nbro
  • 15,395
  • 32
  • 113
  • 196
Engineer
  • 161
  • 1
  • 5
  • 17

3 Answers3

3

change apptheme to Theme.AppCompat in your manifest.xml

<application
...
 android:theme="@style/Theme.AppCompat"> 

This worked initially but later on after making the theme back to AppTheme worked too

Engineer
  • 161
  • 1
  • 5
  • 17
user1736258
  • 99
  • 1
  • 8
  • probably is the version of Android you are using – user1736258 Jun 14 '14 at 04:40
  • So is there any way to make android:theme="@style/AppTheme" working? I'm using minimum sdk version 9 and target as 19 – Engineer Jun 14 '14 at 04:45
  • Now that I have finished creating my first simple app in Android, the app seems to be working properly when I changed back to android:theme="@style/AppTheme" – Engineer Jun 14 '14 at 08:59
1

It appears that the same question has been discussed in this SO query. Basically, you would need to add the v7 app-compatibility JAR files in to your class path.

Community
  • 1
  • 1
Prahalad Deshpande
  • 4,709
  • 1
  • 20
  • 22
0

This worked on my Motorola device. Initially I was getting this "unfortunately app has stopped" on my device and now after changing the theme to android:theme="@style/Theme.AppCompat" it worked.

Wajahat
  • 1,593
  • 3
  • 20
  • 47