2013-02-24 35 views
-1

在我的android應用程序中,我創建了一個簡單的應用程序,在eclipse中通過file> project> Androiapp我已經放下了簡單的活動,但應用程序給出了錯誤。Android項目未加載,它產生不尋常的錯誤

佈局文件

<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" 
    tools:context=".MainActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="@string/hello_world" /> 

</RelativeLayout> 

代碼文件

package com.example.testapp; 

import android.R; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

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.activity_main, menu); 
     return true; 
    } 

} 

,我可以看到有這個代碼沒有錯誤,但在日食它仍然在setContentView(R.layout.activity_main);getMenuInflater().inflate(R.menu.activity_main, menu);產生錯誤。

我覺得資源文件沒有加載

注意,在自動生成的代碼我還沒有作出任何改變。

+1

同樣的想法,我認爲你的資源文件沒有加載... – 2013-02-24 06:33:06

+0

你可以發佈你的堆棧跟蹤作爲logcat的一部分嗎? – lokoko 2013-02-24 06:47:24

回答

2

刪除此行。

import android.R; 

並清理該項目,然後構建它。

+0

我已經刪除了'導入android.r;'語句,並且比我清理項目表單**項目?清理項目**,但它仍然給msg你的項目包含錯誤... – 2013-02-24 06:45:05

+0

@Sagar Upadhyay然後有一些東西另一個問題,你可以發佈錯誤信息。 – 2013-02-24 06:45:55

+0

錯誤 **描述\t資源\t路徑\t位置\t類型 執行aapt時出錯。請檢查aapt是否出現在D:\ Android \ SDK \ platform-tools \ aapt.exe \t testApp \t \t未知\t Android打包問題**我認爲此文件丟失,這就是它生成錯誤的原因... – 2013-02-24 06:50:20

0

答案是

在你輸入

import android.R; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

刪除此行

import android.R; 
0

胡亂猜測這裏:如果你有其他的XML文件中的錯誤,那麼也許這可以阻止創建自動生成的R文件。查看gen文件夾下的文件,並驗證R.java文件是否存在且格式正確。

相關問題