Android emulator: unfortunately the application is stopped

I am new to Android programming. I follow the Android Developers guide to get started with Android.

When you try to run the Hello World application on the emulator, the emulator shows "Unfortunately My First App has stopped", where My First App is the name of the application.

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 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" />
+4
source share
3 answers

change apptheme to Theme.AppCompat in your manifest. xml

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

This worked initially, but later, after the theme was added back to AppTheme.

+3
source

, SO. , JAR v7 .

0

This worked on my Motorola device. Initially, I received this application “unfortunately stopped” on my device, and now, after changing the theme to android:theme="@style/Theme.AppCompat", it worked.

0
source

Source: https://habr.com/ru/post/1544552/


All Articles