Austin Davis
Austin Davis

Reputation: 3756

Having Trouble generating R.Java

I'm recently been trying to get R.JAVA to generate with no avail. I've tried the following 1. Adding spaces to the manifest file 2. Project--> Clean

So my last guess is that there is some error in my xml files that I/eclipse haven't been able to see. So I was hoping to have a second pair of eyes that might be able to check my xml files for review. There's only three and they should be pretty basic(I'm following a intro to android book).

Manifest File

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.activites"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Activity2"
        android:label="Activity 2" >
        <intent-filter>
        <action android:name="com.example.ACTIVITY2" />

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

activity_main.xml

<RelativeLayout 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" >

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world"
    tools:context=".MainActivity" />

</RelativeLayout>

Activity2.xml

<RelativeLayout 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" >

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is Activity 2!" />
</RelativeLayout>

Again thanks to all of you that have taken time out of your busy day/night to help out a beginner like myself. Also if there's any suggestion other than errors in the xml feel free to bring them up.

As requested here are the problems appear in windows-> show view -> problems

  1. R cannot be resolved to a variable
  2. R cannot be resolved to a variable
  3. R cannot be resolved to a variable

Tag is not that obvious it is used to show debug information in catlog with the following lines of code.

public class MainActivity extends Activity {

String tag = "Events";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    Log.d(tag, "In the onCreate() event");
}

Upvotes: 0

Views: 262

Answers (4)

Doc
Doc

Reputation: 1112

I get following error when I compile your code:

res\layout\Activity2.xml: Invalid file name: must contain only [a-z0-9_.]

So remove capital A and rename "Activity2.xml" to "activity2.xml"

Also, if this doesn't help, try this:-

Rename your package name to some other. Clean. Restart Eclipse. Rename package back to the previous one. Again clean. Restart Eclipse.

Upvotes: 1

Techwolf
Techwolf

Reputation: 1228

tag should be a String variable. What is it defined as? You should probably hard-code it there, unless you are using it as a global variable for your application. http://developer.android.com/reference/android/util/Log.html#d%28java.lang.String,%20java.lang.String%29

EDIT: R cannot be resolved - Android error has a lot of different answers, try reading through those. If the first one doesn't solve your problem, another one might.

Upvotes: 0

mango
mango

Reputation: 5636

check your imports. is import android.R anywhere there? if so, remove it. if you're indeed following some android tutorial in a book and it instructed you to organize or manage imports with Ctrl+shift+O or otherwise, that will cause that to pop up.

Upvotes: 0

Justin ZHANG
Justin ZHANG

Reputation: 31

In eclipse you can check the Problems view(windows-->show view-->Problems) or/and the Console view to help locate errors in Xml efficiently. If you remain need help you may want to post these errors to us

Upvotes: 2

Related Questions