找不到与标题上的给定名称匹配的资源

时间:2014-05-01 11:51:39

标签: java android xml eclipse android-layout

我的android应用程序包中没有生成R,并且我的所有java文件都有错误而没有更改这些文件的任何内容,我操纵了这些文件:

字符串:

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

    <string name="app_name">Washing Machines System</string>
    <string name="action_settings">something here</string>
    <string name="details">insert your details</string>
    <string name="sign">Sign in</string>
    <string name="title_activity_rooms">Rooms</string>
    <string name="hello_world">Hello world!</string>

</resources>

mainfeast:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/download"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light" >
        <activity
            android:name="com.example.washingsystem.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.washingsystem.Rooms"
            android:label="@string/title_activity_rooms" >
        </activity>
    </application>

</manifest>

MainActivity:

package com.example.washingsystem;

import android.R;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class MainActivity extends ActionBarActivity {
    Button i;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @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);
        return true;
    }

    public void signin(View view)
    {
        //Toast.makeText(this,"AAAAAAAAAA",Toast.LENGTH_SHORT).show();
        Intent myIntent = new Intent(MainActivity.this, Rooms.class);

        MainActivity.this.startActivity(myIntent);
    }

    @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);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }

    }

}

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg"
    android:visibility="visible"
    tools:ignore="MergeRootFrame" >

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="17dp"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="110dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="136dp"
        android:onClick="signin"
        android:text="@string/sign" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_alignLeft="@+id/editText2"
        android:layout_marginBottom="62dp"
        android:ems="10"
        android:inputType="textPassword" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="212dp"
        android:layout_height="52dp"
        android:layout_above="@+id/editText2"
        android:layout_alignRight="@+id/editText2"
        android:layout_marginBottom="25dp"
        android:text="@string/details"
        android:textColor="@color/Black"
        android:textSize="20sp" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

R not generating because you have import android.R;

So remove the import android.R;

and make sure there will be no errors in your xml files and clean and build the project again