1

私は XML でアプリを作成しましたが、Java コードでクラスを作成していません。しかし、エミュレーターはアプリをその名前で表示でき、その後「残念ながら、アプリは停止しました」と表示されます。この問題のために私は何をしなければなりませんか??!

これは私のコードです:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Textview
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"/>
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/TextView2"/>
<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Button"
    />

</LinearLayout> 
4

2 に答える 2

0

manifest.xml がそれを認識して実行できるように、アプリケーションには少なくとも 1 つのアクティビティ (Java クラス) が必要です

于 2013-01-23T14:07:05.860 に答える
0

この xml を表示するには、アクティビティを使用する必要があります。

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

ご覧のとおり、xml は setContentView メソッドによって呼び出されます。

このアクティビティは、AndroidManifest.xml で宣言する必要があります。

<activity
        android:name="YOURPACKAGE.ACTIVITY_NAME"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
于 2013-01-23T14:07:33.723 に答える