Android HelloViews Spinner Tutorial R.id and R.array cannot be resolved

I'm having problems with the Android HelloViews Spinner Tutorial. An error in HelloSpinner.java indicates that "Rid cannot be resolved" and "R.array cannot be resolved". The error in AndroidManifest.xml reads: "No resource found that matches the specified name (in the" label "with the value" @ string / app_name ") and" No found resource that matches the specified name (in the label with the value '@string / app_name ') ".

Here is my complete code:

HelloSpinner.java

package net.brianwolf.hellospinner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class HelloSpinner extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //Spinner spinner = (Spinner) findViewById(R.id.spinner);
        android.widget.Spinner spinner = (android.widget.Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.planets_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);


        spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    }
    public class MyOnItemSelectedListener implements OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
          Toast.makeText(parent.getContext(), "The planet is " +
              parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
        }

        public void onNothingSelected(AdapterView parent) {
          // Do nothing.
        }
    }
}

Res / layout / main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="@string/planet_prompt"
    />
    <Spinner 
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt"
    />
</LinearLayout>

Res / layoutvalues ​​/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="planet_prompt">Choose a planet</string>
    <string-array name="planets_array">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
        <item>Jupiter</item>
        <item>Saturn</item>
        <item>Uranus</item>
        <item>Neptune</item>
    </string-array>
</resources>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="net.brianwolf.hellospinner"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloSpinner"
                  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> 

Thank!

+3
5

strings.xml ( values.xml, ):

<string name="app_name">The Name Of Your App Goes Here</string>

+3

, Eclipse, ? > ...

+4

<string name="app_name">The Name Of Your App Goes Here</string>

. "R" "setContentView (R.layout.main)"; hellospinner.java

, , "R" net.brianwolf.hellospinner.R;

+1

. , MatrixFrog, , , , ( ) AndroidManifest.xml. :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.hellospinner"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="12" />

    <application android:icon="@drawable/icon" android:label="@string/planet_prompt">
        <activity android:name=".HelloSpinnerActivity"
                  android:label="@string/planet_prompt">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

, , app_name, planet_prompt, . , , , , Android, ... .

+1

Source: https://habr.com/ru/post/1764984/


All Articles