Reputation: 11
I have searched everywhere but cannot find an answer to my problem. I am totally new to this and am in way over my head. I am simply doing the basic "my first app tutorial" from the Android dev site. The tutorial causes errors even though the code is exactly as written in the example. The error that shows up in the console is:
[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
The only things I changed was what the tutorial told me to change. Activity_main.xml
and strings.xml
. I never changed anything in main.xml
. In the package explorer it shows a red x next to MainActivity>onCreate(Bundle)
and onCreateOptionsMenu(Menu)
Here is the code from MainActiviy with errors in parenthesis
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;
}
}
What did I do wrong? I just started learning this and I can't even seem to get the tutorial to run right!
Here is the Activity_main.xml and strings.xml that I changed following the directions:
<?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>
Thanks for any help.
Upvotes: 1
Views: 3034
Reputation: 141
I am fairly new to Android programming myself but will try to help anyway.
R is usually automatically generated; a red line underneath it usually indicates it has disappeared.
A majority of the time you will receive this error because you have made an error in you String.xml file.
Based on your error message, it seems as though there is an error with the string for "action_settings". Ensure you have not included any apostrophes or made any other syntax errors.
Upvotes: 0
Reputation: 8641
The code looks OK, but the XML has some issues.
Upvotes: 0
Reputation: 132972
as in Console log :
Error: No resource found that matches the given name (at 'title' with value '@string/action_settings
means you will need to add an action_settings
string inside res/values/strings.xml
file as
<resources>
<!-- Your other strings -->
<string name="action_settings">Action Settings</string>
</resources>
Upvotes: 2