1

どこでも検索しましたが、問題に対する答えが見つかりません。私はこれにまったく慣れておらず、頭を悩ませています。Android 開発サイトから基本的な「初めてのアプリ チュートリアル」を実行しているだけです。コードが例に書かれているとおりであっても、チュートリアルではエラーが発生します。コンソールに表示されるエラーは次のとおりです。

[2013-03-12 15:33:36 - MyFirstApp] D:\Android Development\MyFirstApp\res\menu       \main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_settings').
[2013-03-12 15:34:38 - MyFirstApp] W/ResourceType( 6352): Bad XML block: header size     311 or total size 5346560 is larger than data size 0

私が変更したのは、チュートリアルで変更するように言われたものだけです。 Activity_main.xmlstrings.xml。で何も変更したことはありませんmain.xml。パッケージ エクスプローラーでは、横に赤い x が表示 され、括弧内にエラーがある MainActiviy のコードは次MainActivity>onCreate(Bundle)のとおりです。onCreateOptionsMenu(Menu)

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); (error here red underline under R)
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu); (error here red underline under R)
    return true;
}

}

私は何を間違えましたか?私はこれを学び始めたばかりで、チュートリアルを正しく実行することさえできないようです!

指示に従って変更した Activity_main.xml と strings.xml を次に示します。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText android:id="@+id/edit_message"
android:layout_weight="1" 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send" />

</LinearLayout>


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText android:id="@+id/edit_message"
android:layout_weight="1" 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send" />

</LinearLayout>

助けてくれてありがとう。

4

3 に答える 3

2

コンソールログのように:

エラー: 指定された名前に一致するリソースが見つかりません (「タイトル」で値が「@string/action_settings」の場合)

ファイルaction_settings内に文字列を追加する必要があることを意味しますres/values/strings.xml

<resources>
    <!-- Your other strings -->
    <string name="action_settings">Action Settings</string>
</resources>
于 2013-03-12T17:12:36.393 に答える
0

コードは問題ないように見えますが、XML にはいくつか問題があります。

  1. コードは activity_main を参照していますが、使用したファイル名は Activity_main です。照合では大文字と小文字が区別されるため、Android ではファイル名に小文字のみを使用することをお勧めします。
  2. Activity_main.xml を 2 回リストしたようです。Strings.xml はまったくありません。そのため、何が問題なのかを判断することは不可能です。
  3. res/menu ディレクトリ内のファイルを一覧表示しませんでした。オプション メニューを作成する場合は、res/menu/menu.xml が必要です。
于 2013-03-12T17:12:53.727 に答える
0

私は自分で Android プログラミングにかなり慣れていませんが、とにかく助けようとします。

R は通常、自動的に生成されます。その下の赤い線は通常、それが消えたことを示します。

ほとんどの場合、String.xml ファイルにエラーがあるため、このエラーが発生します。

エラー メッセージによると、"action_settings" の文字列にエラーがあるようです。アポストロフィが含まれていないか、その他の構文エラーがないことを確認してください。

于 2013-03-12T17:15:55.340 に答える