2014-11-23 94 views
0

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

+0

也添加了崩潰日誌。 – Manmohan 2014-11-23 06:05:02

回答

0

爲android開發時,總是打開一個logcat窗口。 當您看到崩潰對話框時,logcat將顯示錯誤的根本原因,使您很容易找到並修復錯誤。

0

其損壞的R.java文件的問題.....立即創建一個新的項目,並執行代碼或切換你的SDK。

0

刪除您的R.java文件和Clean您的項目。無需創建新項目。

相關問題