我对Android应用程序编程有点新。 我能够创建应用程序并能够导出并将其安装到我的Android设备,但是当我尝试运行它时,它会退出并显示消息“不幸的是,我的第一个应用程序已停止。”这个问题也存在,当我尝试在模拟器中运行的应用程序不幸的是,“应用程序名称”已停止。 (Eclipse,Android)
这是我AndroidManifest文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tada"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
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>
这是我mainactivity文件:
package com.example.tada;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@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) {
item.getItemId();
return true;
}
}
这是我activity_main文件
<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="com.example.tada.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_to_the_tada_app" />
</RelativeLayout>
这里是我的logcat的
11-23 01:22:21.520 D/AndroidRuntime(1055):关闭VM 11-23 01:22:21.520:W/dalvikvm(1055):threadid = 1:线程退出时未捕获的异常= 0xb3afbba8) 11-23 01:22:21.560:E/AndroidRuntime(1055):致命例外:main 11-23 01:22:21.560:E/AndroidRuntime(1055):进程:com.example.tada,PID :1055 11-23 01:22:21.560:E/AndroidRuntime(1055):java.lang.Error:未解决的编译问题: 11-23 01:22:21.560:E/AndroidRuntime(1055):activity_main无法解析或不是字段 11-23 01:22:21.560:E/AndroidRuntime(1055):at com.example.tada.MainActivity.onCreate(MainActivity.java:14) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.app.Activity.performCreate(Acti vity.java:5231) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 11-23 01:22:21.560:E/AndroidRuntime(1055):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2245) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.app.ActivityThread.access $ 800(ActivityThread.java:135) 11-23 01:22:21.560:E/AndroidRuntime(1055) ):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.os.Handler.dispatchMessage(Handler.java:102 ) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.os.Loo per.loop(Looper.java:136) 11-23 01:22:21.560:E/AndroidRuntime(1055):at android.app.ActivityThread.main(ActivityThread.java:5017) 11-23 01:22: 21.560:E/AndroidRuntime(1055):在java.lang.reflect.Method.invokeNative(本地方法) 11-23 01:22:21.560:E/AndroidRuntime(1055):在java.lang.reflect.Method.invoke (Method.java:515) 11-23 01:22:21.560:E/AndroidRuntime(1055):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779) 11-23 01 :22:21.560:E/AndroidRuntime(1055):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 11-23 01:22:21.560:E/AndroidRuntime(1055):at dalvik .system.NativeStart.main(Native Method) 11-23 01:22:26.100:I/Process(1055):发送信号。 PID:1055 SIG:9
也添加了崩溃日志。 – Manmohan 2014-11-23 06:05:02