user2161897
user2161897

Reputation: 11

Android app dev my first app example error

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

Answers (3)

Rav
Rav

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

Joe Malin
Joe Malin

Reputation: 8641

The code looks OK, but the XML has some issues.

  1. Your code refers to activity_main, but the filename you used is Activity_main. Because the matching is case-sensitive, Android recommends that you use lowercase-only in file names.
  2. You seem to have listed Activity_main.xml twice. Strings.xml isn't there at all. For that reason, it's impossible to tell what the problem is.
  3. You didn't list any of the files in your res/menu directory. If you're creating an options menu, you need res/menu/menu.xml.

Upvotes: 0

ρяσѕρєя K
ρяσѕρєя K

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

Related Questions