0

I know this is a very common problem and I read the previous posts
But my project was just working fine and after I added a radio button it ruined the interface Then I deleted the radio button and some interface contents (like edit-texts and button) and added them again. Now the interface is fine.

The MainActivity.java did not recognize the radio button (although import android.widget.RadioGroup; import android.widget.RadioButton; are there) so I cleaned the project because I wanted R.java to be updated Then, R.java DISAPPEARS and the console shows this image

Things I have tried :
Re-clean project
Fix project portieres

This is my main_activity.xml

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.reg.MainActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="14dp"
        android:ems="10"
        android:imeOptions="flagNoExtractUi"
        android:inputType="textPersonName" > 
        <requestFocus />
        </EditText>

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             />
    </RadioGroup>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/radioGroup1"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:imeOptions="flagNoExtractUi"
         android:inputType="textEmailAddress" >


    </EditText>

    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/editText4"
        android:layout_alignLeft="@+id/editText2"
        android:layout_marginBottom="18dp"
        android:ems="10"
        android:imeOptions="flagNoExtractUi"
        android:inputType="textEmailAddress" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:ems="10"
        android:imeOptions="flagNoExtractUi"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/editText5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText4"
        android:layout_below="@+id/editText4"
        android:layout_marginTop="25dp"
        android:ems="10"
        android:inputType="date" />

    <EditText
        android:id="@+id/editText6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText5"
        android:layout_below="@+id/editText5"
        android:layout_marginTop="20dp"
        android:ems="10" 
         android:inputType="textEmailAddress"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="28dp"
         />

</RelativeLayout>

please justify your answer, I am just a beginner

UPDATE
it works when I change the target to 21 but I want it to be 20

Lana
  • 148
  • 1
  • 3
  • 12
  • disapear = cannot be generated. So because you have some problem somewhere, the R.java is gone. (check your problems tab in eclipse: it shows a red cross. Vind the one that does not come from R.java missing) – Nanne Oct 30 '14 at 10:11
  • @Nanne the only error I have is "R cannot be resolved" – Lana Oct 30 '14 at 10:12
  • I doubt that. any red crosses in any of the files? no strange "import android.R" you might have `ctrl-o`-ed in your files? – Nanne Oct 30 '14 at 10:13
  • Restart your eclipse, GO to project unCheck build automatically and build it again. – Android Noob Oct 30 '14 at 10:15
  • Are you using fragment as you are referring a fragment lib – Android Noob Oct 30 '14 at 10:20
  • @Shrinivas I did, please see the image above that what it shows – Lana Oct 30 '14 at 10:22
  • Most of the time R.java is not created because of an error of xml check your xml properly – Hasnain Oct 30 '14 at 10:22
  • 1
    As Nanne says, you must fix the other problems in your project first. R.java is automatically generated in a working project. If your project has errors in it, the R.java will not be generated. Fix the other problems first. "R cannot be resolved" is clearly NOT the only problem, as your image of the console shows. – Breandán Dalton Oct 30 '14 at 10:26
  • what is Your target/compile version sdk? – Opiatefuchs Oct 30 '14 at 10:29
  • I think you are confused about your issue, Your logcat says that you are getting some issues while importing support-v7-appcompat library and you are saying , there is no R.java – Android Noob Oct 30 '14 at 10:30
  • @Opiatefuchs android-20 – Lana Oct 30 '14 at 10:30

5 Answers5

0

Just go to gen folder>R.java & delete R.java and clean your project.

R.java will be automatically generated and your error will be removed .

Now I have seen the image post by you :- So I think you should check this also,also right click your project->build path->android check whether the appcompact-v7 library is refered properly.check whether there is green tick for lib reference

user3173628
  • 182
  • 5
0

R.java is not being generated as there is error in your xml files. If I were you, I would check the xml files (especially the layout files) for errors, resolve them and then clean the project.

Try changing your XML file to : (defining the android namespace first, and then the tools)

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    .....
Swayam
  • 16,294
  • 14
  • 64
  • 102
0

I think you are confused about your issue, Your logcat says that you are getting some issues while importing support-v7-appcompat library and you are saying , there is no R.java

I think you are getting issues while adding support-v7-appcompat library and thus it might be affecting R.java

Please follow below steps to add lib

ollow the instructions in the Support Library Setup - Adding libraries with resources. One thing that can bring some doubt is add the library to your aplicattion project:

(1) In the Project Explorer, right-click your project and select Properties. (2) At the left pane select Android. (3) At th bottom of the right pane click Add (4) Select the library project android-support-v7-appcompat and click OK. Click OK to close the properties window.

If you not get any of the errors I mentioned it´s all done.

However if you are like me, you dont´t followed the advice of Android team that suggests you always compile your source using the latest SDK, you get the error.

The error ocurrs because my Project Build Target was Android 2.3.3 and need to be at lest 3.0. It was not immediately clear to me because of the fact that I'm specifically developing for Android 2.3.3 and I'm using support libraries.

OK, I hope this helps.

Android Noob
  • 621
  • 8
  • 18
  • But did it generate R.java? First check if R.java is there or not then change target to 20 again and check – Android Noob Oct 30 '14 at 10:44
  • Yes R.java is there now and no errors in problem or console taps BUT When I try to make target 20, the console shows the same error in image above I do not know whats the problem – Lana Oct 30 '14 at 10:50
  • What is the build target of the project, try to make both to 19 or something and check if it is only working for 21. – Android Noob Oct 30 '14 at 10:53
  • it is only working in 21. I think I do not change the target correctly I just changed the value in manifest and project properties. – Lana Oct 30 '14 at 11:24
  • You dont have to modify it in project properties, What is the build target of the project?? – Android Noob Oct 30 '14 at 11:27
  • now my build target is 21 I want it to be 20 I tried changing it using build-path>android but the error still there. – Lana Oct 30 '14 at 11:38
  • Is there any reason for preferring only 20? not related with the ans just want to know, Keep the project build at 21, just change the targetSDK to 20 in manifest, it doesnt matter much – Android Noob Oct 30 '14 at 11:42
  • Yes I am working in a group project and my code is going to be added to my friends code in a project that has build 20 – Lana Oct 30 '14 at 12:01
  • You can commit the changes it wont affect – Android Noob Oct 30 '14 at 12:05
0

Case 1 = i think u delete radio button manually from xml so when we delete some button on textview etc. from xlm then some there other edit text or text view contain there id's like in below or above option in xml so R.java file have also these id's so just go in R.java find the error like and delete that id from R.java and xml also like

android:layout_below="@+id/radioGroup1"

in your case you delete a radio group but u did not delete id from edit text 2 so may b its give you that error

Case 2 = may be you are using android-support-v7-appcompat.jar file in your project so simple go in lib folder and delete android-support-v4.jar from lib and clear and re build your project

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_below="@+id/radioGroup1"
    android:layout_marginTop="24dp"
    android:ems="10"
    android:imeOptions="flagNoExtractUi"
     android:inputType="textEmailAddress" >
</EditText>

Hope its works

0

According to the Docs and Your error message that You´ve showed in the picture, it seems that one of the error is, that Your V7 support library is not included the right way. But this is vague and Your errors can have multiple causes. But for the first, try something:

  • be sure You have v4 support and v7 appcompat libraries included (both)
  • be sure You have downloaded both libraries to Your Android SDK
  • You have to set Your build versions like specified in the doc here:

https://developer.android.com/tools/support-library/features.html#v7

if all this is done, usually the error messages that You have showed in the image should be gone. Then You can go on, with the other error messages, if there are still some. Then come back if You need more help and show updatet question.

Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49