This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 8 years ago.
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
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.
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"
.....
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
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
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.
Related
I've been trying to use MaterialToggleGroup in an Android project, but it is not working properly. The problem is that it always seems to be empty, no matter what you put inside it.
I'm using a very simple layout, with a LinearLayout that includes the group and a ListView. The group itself contains two buttons.
<?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" >
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/toggle_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="#+id/button1"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<com.google.android.material.button.MaterialButton
android:id="#+id/button2"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</com.google.android.material.button.MaterialButtonToggleGroup>
<ListView
android:id="#+id/listado"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
/>
</LinearLayout>
In the editor it looks like this:
toggle group with wrap_content
If I change the hight and set it, for example, to 30dp, it shows up but as if it was empty, proving that it is being inserted but it's no working properly:
toggle group with 30dp
Project is in Java and its dependencies are pretty much not updated. The problem can be seen on editor but also when app is running on emulator and physical device.
What I've tried so far:
Invalidating caches/restarting.
Clean and rebuild project.
Upgrading all dependencies, including Gradle build tools, material and app compat libraries.
Test it in another layout, same result.
Test some other Material components, they work fine.
Create a new project and use the component, no problems found, seems that the problem is in this project.
I'm running out of ideas, but I'd like to avoid creating my own component to achieve the same result.
Thanks for your help.
My program is running correctly, but this error is being displayed in the compiler. How to fix it?
No answer regarding this can be found on Google, I checked quite many times.
activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- username-->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/username_TIL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:elevation="2dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/username_TIET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/username" />
</com.google.android.material.textfield.TextInputLayout>
<!-- password-->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/password_TIL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="#id/username_TIL">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/password_TIET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="password"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- confirmPassword-->
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/confirmPassword_TIL"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="#id/password_TIL">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/confirmPassword_TIET"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/confirm_password"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- SignIn-->
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/signIn_BTN"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/sign_in"
android:textColor="#android:color/white"
app:cornerRadius="50dp"
android:elevation="2dp"
android:layout_below="#id/confirmPassword_TIL"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:background="#android:color/holo_blue_light"/>
</RelativeLayout>
MainActivity has nothing in it - initialised
Manifest File also has nothing extra added to it. Any explanations towards why is this error occurring. Also one more error is being displayed.
E/InputTransport: ro.sf.lcd_density must be defined as a build property
I had the same problem but mine was because of screen density. You may need to revise your images or icons size if any in the drawable folder then generate a copy to following directories.
res/
drawable-xxxhdpi/
example.png
drawable-xxhdpi/
example.png
drawable-xhdpi/
example.png
drawable-hdpi/
example.png
drawable-mdpi/
example.png
For more info read here
To eliminate this error message, add the following line to the build.prop file located in the /system folder on the device:
ro.sf.lcd_density=160
This sets the display density to 160 dpi, which is the lowest among currently supported devices. You can adjust it to match the specific density of your device.
Note: You need to have root access to the device in order to edit the build.prop file. Since this can cause issues on some devices, it is to make a backup of the original file before making any changes.
I'm trying to develop an app right now that uses CardViews, and I'd like to have them be expandable; that is to say that upon someone pressing the CardView, it should expand to show more details. How would I go about doing this?
Here's a visual explanation of what i'm trying to do; when I press the highlighted CardView, I want it to expand to show more information, and be able to contract upon another press; I'm not sure how to do this, and searching the internet has led me to no answer as of yet.
Best Solution is,use Expandable Layout and add it inside your CardView.
<com.kyo.expandablelayout.ExpandableLayout
android:id="#+id/expandlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp" >
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:scaleType="centerCrop"
android:src="#drawable/parent" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:contentDescription="#null"
android:scaleType="centerCrop"
android:src="#drawable/child"
app:canExpand="true" />
</com.kyo.expandable.ExpandableLayout>
. I am newbie to android . For some need i need to get all the components (i.e. TextViews ,Buttons,EditTexts,Imageviews,spinners ,checkboxes and so on . . ) and their ids in my layout xml file.
say i have following xml file sample.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
Currently i have only id of my xml file .I need to get all components and ids so that i can modyfy their text using java code. In short i need some kind of parsing.
Assuming that i dont know anything inside my xml file except its id.
SO please help me . .Thank u in advance . .
Actually i need to change the text of each textVeiw in that layout say i need to add * ath the end of the text of each text view.
AFAIK There is no way for you to achieve what you are looking for.
If all ID's were created and defined in the xml layout file - you will have to call them in you code - but you will have to know their given ID's.
If you create your ID's via the code for example textView.setId(1234); - then you are able to keep track of all names and do whatever you want with them.
So, unfortunately I don't think what you want is possible.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
background layout moving when soft keyboard displayed - android
I have a layout file that contains severals views and EditText:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/connect"
android:id="#+id/btnConnect" android:layout_alignParentRight="true" android:layout_alignParentTop="true"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spServers"
android:layout_toLeftOf="#+id/btnConnect" android:layout_alignTop="#+id/btnConnect"
android:layout_alignBottom="#+id/btnConnect" android:layout_alignParentLeft="true"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnType" android:layout_alignLeft="#+id/btnConnect"
android:layout_below="#+id/btnConnect" android:layout_alignRight="#+id/btnConnect" android:textOff="#string/text"
android:textOn="#string/grid" />
<Spinner
android:layout_width="98dp"
android:layout_height="22dp"
android:id="#+id/spDataBases" android:layout_toLeftOf="#+id/btnConnect"
android:layout_below="#+id/btnConnect"
android:layout_alignBottom="#+id/btnType" android:layout_alignLeft="#+id/spServers"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/check"
android:id="#+id/btnCheck" android:layout_alignLeft="#+id/spServers" android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/run"
android:id="#+id/btnRun" android:layout_toRightOf="#+id/btnCheck" android:layout_alignTop="#+id/btnCheck"
android:layout_toLeftOf="#+id/btnLoad"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/load"
android:id="#+id/btnLoad" android:layout_alignRight="#+id/btnConnect"
android:layout_alignTop="#+id/btnCheck"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtSQL" android:layout_alignLeft="#+id/spServers" android:layout_below="#+id/btnType"
android:layout_alignRight="#+id/btnConnect" android:layout_above="#+id/btnCheck"
android:gravity="left|top" android:singleLine="false" android:textAlignment="gravity"/>
</RelativeLayout>
It looks like this:
But when I'm trying to type something, I'm getting this problem:
Help me please to fix this. I don't wanna change the screen position on the layout, when I'm typing some text. It's moving up when user trying to type something.
You could try to tell Android to not resize your layout when the keyboard is brought up, making sure that what you're typing is visible. (Docs: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft)
Add the following to your apps' manifest: (in the relevant activity instead of the dummy one below)
<activity android:name="Activity"
..
android:windowSoftInputMode="adjustPan"
..
</activity>
It's unclear to me if your issue is happening when you click on the EditText and the keyboard comes up, or if it only happens once you start typing? My answer will probably not help if the latter is the case. I'm also unsure if "adjustPan" is desirable behaviour, but it's worth a shot! It could also be a good idea to put your entire RelativeLayout in a ScrollView.