0

我正在尝试在 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>
4

3 回答 3

0

显然你忘了把</manifest>你的 AndroidManifest.xml 文件放在末尾。

于 2012-06-30T01:02:53.893 回答
0

有时日食是愚蠢的。尝试执行“项目 --> 清理”,然后重新启动 Eclipse。您会惊讶于这实际上解决了问题的频率。

于 2012-06-30T01:49:15.520 回答
0

问题在这里解决:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
     android:orientation="horizontal">
     <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/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>


<LinearLayout
    android:id="@+id/wrapper"
    android:layout_width="match_parent"
    android:layout_height="425dp"
    android:layout_marginTop="45dip"
    android:background="@drawable/background"
    android:orientation="vertical" >

</LinearLayout>
 </RelativeLayout>

问题是因为在我添加应用程序后,Relativelayout 没有方向,运行流畅!谢谢大家的帮助!!!

于 2012-06-30T03:48:38.827 回答