0

I know this question is asked already but they didn't work for me(lots of them were for earlier versions of android studio that I couldn't find the menus in 0.8.2.

the R is marked red.and I don't know what should i do with this. MainListActivity.java :

import android.app.ListActivity;
import android.content.res.Resources;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Toast;

public class MainListActivity extends ListActivity {

    protected  String[] mAndroidNames;

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


        Resources resources = getResources();
        mAndroidNames = resources.getStringArray(R.array.android_names);

        // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mAndroidNames);
        // setListAdapter(adapter);
        Toast.makeText(this,R.string.No_items,Toast.LENGTH_LONG).show();
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

AndroidMainfest.xml:

A<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.habib.blogreader" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainListActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">BlogReader</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="No_items">No items to display</string>
    <String-array name = "android_names">
        <items>Android 1</items>
        <items>Android 2</items>
        <items>Android 3</items>
        <items>Android 4</items>
        <items>Android 5</items>
        <items>Android 6</items>
        <items>Android 7</items>
        <items>Android 8</items>
        <items>Android 9</items>
        <items>Android 10</items>
        <items>Android 11</items>
    </String-array>

</resources>

the other questions are for earlier versions of android studio I have 0.8.2 , for example there was an
answer :enable external build but there isn't in the 0.8.2(in that address). And most of them are for eclipse not for android studio.

FINALLY I FIX THIS PROBLEM BY CHANGING <ITMES> TO <ITEM> IN STRINGS.XML.

habib
  • 91
  • 2
  • 6
  • did you check the logcat? did you rebuild / clean the project? did you declared some wrong variables? String-array ? try to change it to string-array – Elior Sep 08 '14 at 11:47
  • Marked this as duplicate; `R` is not generated due to an error in your XML file (most likely the one mentioned by blackbelt). This is stated as a possible cause in the linked thread. – Jave Sep 08 '14 at 11:50
  • whats `A` the `A` is it a typo here or in the xml as well ? – Sagar Pilkhwal Sep 08 '14 at 11:53
  • i did clean project but in the logcat Error:A problem was found with the configuration of task ':app:generateDebugBuildConfig'. > No value has been specified for property 'buildConfigPackageName'. – habib Sep 08 '14 at 11:53
  • A was an copy paste error – habib Sep 08 '14 at 11:55
  • clean the project or enable Build Automatically – Sagar Pilkhwal Sep 08 '14 at 12:00
  • where is the build automatically there is make project automatically in the settings --> compiler are they same ?if yes it doesn't work for me. – habib Sep 08 '14 at 12:05

2 Answers2

1
<String-array name = "android_names">

this is wrong. It should be <string-array name = "android_names">

with the lower case s. That could be to compile time errors that prevent R to be generated, therefore it can not be resolved. As pointed out by @LokiSinclair

A<?xml version="1.

you have an additional A, in your manifest (could it be a copy/paste error)?

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

Try importing this;

import com.example.habib.blogreader.R;
Faruk Yazici
  • 2,344
  • 18
  • 38