我想創建Android上的佈局,當我嘗試執行時,系統給我的「不幸消息」,這是我的佈局代碼:我的應用程序突然停止
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/appetizer"
style="@style/header"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:background="@drawable/header_bk"
android:text="@string/appetizer" />
<Button
android:id="@+id/drinks"
style="@style/header"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:background="@drawable/header_bk"
android:text="@string/drinks" />
<Button
android:id="@+id/meats"
style="@style/header"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:background="@drawable/header_bk"
android:text="@string/meats" />
</LinearLayout>
<ImageView
android:id="@+id/logo"
android:layout_width="250dip"
android:layout_height="85dp"
android:layout_marginLeft="380dip"
android:background="@drawable/logo_bk" />
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="425dp"
android:layout_marginTop="49dip"
android:background="@drawable/background"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/header1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="630dip">
<Button
android:id="@+id/pastas"
style="@style/header"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:background="@drawable/header_bk"
android:text="@string/pastas" />
<Button
android:id="@+id/salads"
style="@style/header"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:background="@drawable/header_bk"
android:text="@string/salads" />
<Button
android:id="@+id/specials"
style="@style/header"
android:layout_width="130dip"
android:layout_height="wrap_content"
android:layout_marginLeft="1dip"
android:background="@drawable/header_bk"
android:text="@string/specials" />
</LinearLayout>
這是java文件的代碼:
package menu.menuapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
//import android.widget.*;
public class FrontActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.front);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.front, menu);
return true;
}
}
和日誌:
06-29 19:33:30.870: I/ActivityManager(95): START {act=android.intent.action.MAIN cat= [android.intent.category.LAUNCHER] flg=0x10200000 cmp=menu.menuapp/.FrontActivity} from pid 199
06-29 19:33:31.130: I/ActivityManager(95): Start proc menu.menuapp for activity menu.menuapp/.FrontActivity: pid=519 uid=10040 gids={}
06-29 19:33:31.222: I/WindowManager(95): createSurface Window{415c8348 Starting menu.menuapp paused=false}: DRAW NOW PENDING
06-29 19:33:32.701: E/AndroidRuntime(519): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{menu.menuapp/menu.menuapp.FrontActivity}: java.lang.ClassNotFoundException: menu.menuapp.FrontActivity
06-29 19:33:32.701: E/AndroidRuntime(519): Caused by: java.lang.ClassNotFoundException: menu.menuapp.FrontActivity
06-29 19:33:32.730: W/ActivityManager(95): Force finishing activity menu.menuapp/.FrontActivity
06-29 19:33:33.305: W/ActivityManager(95): Activity pause timeout for ActivityRecord{415c7a70 menu.menuapp/.FrontActivity}
這是明顯的。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="menu.menuapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FrontActivity"
android:label="@string/title_activity_front" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
嗯,我無法找到問題。你可以在Eclipse中做一個乾淨的項目並回報嗎? – cklab
我發現它的問題是與 如果你看到沒有方向,之後做到完美!我會把這個作爲答案。 –
hidura