我的应用突然停了下来

时间:2012-06-30 00:12:01

标签: android android-layout android-widget

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

3 个答案:

答案 0 :(得分:0)

显然您忘记将</manifest>放在AndroidManifest.xml文件的末尾。

答案 1 :(得分:0)

有时候日食是愚蠢的。尝试执行“项目 - &gt;清理”,然后重新启动日食。你经常会解决这个问题,你会感到惊讶。

答案 2 :(得分: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没有方向!谢谢大家的帮助!!!