Java Android 模拟器:不幸的是应用程序已停止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24216465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Emulator: Unfortunately App has stopped
提问by Engineer
I'm new to Android Programming. I'm following the guide on Android Developers to get started with Android.
我是 Android 编程的新手。我正在按照 Android 开发人员指南开始使用 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.
当尝试在模拟器上运行简单的 Hello World 应用程序时,模拟器显示“不幸的是,我的第一个应用程序已停止。”,其中我的第一个应用程序是应用程序的名称。
This is my AndroidManifest file:
这是我的 AndroidManifest 文件:
<?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:
这是 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.access0(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:
这是 activity_main 文件:
<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" />
采纳答案by user1736258
change apptheme to Theme.AppCompat in your manifest.xml
在 manifest.xml 中将 apptheme 更改为 Theme.AppCompat
<application
...
android:theme="@style/Theme.AppCompat">
This worked initially but later on after making the theme back to AppTheme worked too
这最初有效,但后来在将主题恢复为 AppTheme 后也有效
回答by Prahalad Deshpande
回答by Rhomi_Elijah
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.
这适用于我的摩托罗拉设备。最初我在我的设备上收到这个“不幸的应用程序已停止”,现在在将主题更改为android:theme="@style/Theme.AppCompat"
它之后可以正常工作。