Cleared project, my R.java file will not be created due to an error in the XML file?

I tried to launch my project in the Genymotion emulator, but none of the new updated buttons that I added showed up when I launched the Android app. So, I made a copy of my project to run “clean” because I had problems creating the R.java file after it was cleaned up, and I was right because the R.java file did not generate in the copied project. I am pretty sure this is a problem in my XML file, but there are no errors in my XML file.

I also had the same error that I wrote about here: R can not be resolved to a variable?

The R file is not generated, so all my calls to MainActivity, such as mBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.crayon);, indicate that "R cannot be resolved by a variable", which, as I know, indicates a problem in my XML file.

Here is my activity_main.xml file:

<?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="vertical"
   android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:gravity="center"
   tools:context=".MainActivity" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|fill_horizontal|center"
    android:orientation="horizontal" >

    <RadioGroup
        android:id="@+id/greyorcolor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/grey"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/reyscale" />

        <RadioButton
            android:id="@+id/color"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/color" />
    </RadioGroup>

    <RadioGroup
        android:id="@+id/smallorlarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/large" />

        <RadioButton
            android:id="@+id/small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/small" />
    </RadioGroup>
</LinearLayout>

<edu.berkeley.cs160.opalkale.prog2.DrawingView
    android:id="@+id/drawing"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_marginBottom="3dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="3dp"
    android:layout_weight="1"
    android:orientation="vertical"
    android:src="@drawable/ic_launcher" />

</LinearLayout>

My strings.xml file:

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

   <string name="app_name">Drawing</string>
   <string name="greyscale">Greyscale</string>
   <string name="color">Color</string>
   <string name="small">Small Brush</string>
   <string name="large">Large Brush</string>
   <string name="hello_world">Hello world!</string> </resources>

My MainActivity.java file:

package edu.berkeley.cs160.opalkale.prog2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

public class MainActivity extends Activity {

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

    Bitmap munBitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.crayon);
    Bitmap mBitmap = munBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mBitmap);

    DrawingView drawingView = (DrawingView) findViewById(R.id.drawing);
}

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

}

Problem window: enter image description here  enter the code here

+3
source share
5 answers

I do not quite understand about this, but are you using eclipse? If so, then I had similar problems when R.java was not generated, but eclipse did not put any errors. In all cases, there were errors in the XML layout files, but I found that I needed to open the Problems view to find out what they were. If you have not opened it yet, you can try the following:Window -> Show View -> Problems

+2

, eclipse . eclipse , R . , .

0

@

    <RadioButton
        android:id="@+id/grey"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@Greyscale" />                  // Here 

@

0

, Android,

:)

-, "", R.java, . , :)

, .:)

, "R.java" "CheckBox" . ?

0

:

1: You are forgot to add drawablenamed "crayon" in the transfer folder.

2:: package erroryou just need to check the import statements. he should look like

import com.test.example.R;

where is your package name = com.test.example

0
source

All Articles