gpt4 book ai didi

Android 应用开发我的第一个应用示例错误

转载 作者:行者123 更新时间:2023-11-29 21:47:40 26 4
gpt4 key购买 nike

我到处搜索,但找不到我的问题的答案。我对此完全陌生,并且难以理解。我只是在 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 中的任何内容。在包资源管理器中,它在 MainActivity>onCreate(Bundle)onCreateOptionsMenu(Menu) 旁边显示一个红色 x 这是来自 MainActiviy 的代码,括号中有错误

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>

感谢您的帮助。

最佳答案

如在控制台日志中:

Error: No resource found that matches the given name (at 'title' with value '@string/action_settings

意味着您需要在 res/values/strings.xml 文件中添加一个 action_settings 字符串作为

<resources>
<!-- Your other strings -->
<string name="action_settings">Action Settings</string>
</resources>

关于Android 应用开发我的第一个应用示例错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15367559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com