I have constantly gotten the same error over and over in my program and i can't find out how to fix it. R cannot be resolved to an error. I have tried to build my project and i have no imports that involve .R? Would anyone know how to fix it?
Here's my xml files i can't seem to find anything wrong....
strings.xml
Remote Doc
Remote Doc
Patient Mode
Doctor Mode
About
Exit
Simple Mode
Detailed Mode
About Remote Doc
\
Remote Doc is an application that allows a brace user analyze
how often they use their thing
main.xml
<!-- Patient Option -->
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/patientButton"
android:id="#+id/patientButton">
</Button>
<!-- Doctor Option -->
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/doctorButton"
android:layout_weight="1"
android:id="#+id/doctorButton">
</Button>
<!-- Exit Mode -->
<Button android:text="#string/exit"
android:layout_weight="1"
android:id="#+id/exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
<!-- About Mode -->
<Button android:text="#string/aboutButton"
android:layout_weight="1"
android:id="#+id/aboutButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
</LinearLayout>
/>
main.xml- land
android:text="#string/mainTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:textSize="24.5sp"/>
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:text="#string/patientButton"
android:id="#+id/patientButton"/>
<Button
android:text="#string/doctorButton"
android:id="#+id/doctorButton"/>
</TableRow>
<TableRow>
<Button
android:text="#string/aboutButton"
android:id="#+id/aboutButton"/>
<Button
android:text="#string/exit"
android:id="#+id/exit"/>
</TableRow>
</TableLayout>
</LinearLayout>
This is a really common problem. First try cleaning your project by going to Project > Clean.
If that doesn't work, try one of the recommendations from this similar question
R is an automatically generated class in Android. It holds all your ressource references.
Since the creation of that failed, you will most likely have an error inside one of
your ressource files. (e.g. syntax error in a layout file like main.xml, or in your strings.xml). Check these files inside the res/ folder. Probably in the one you most recently edited.
After your are done and found it, this should go away automatically. Sometimes it gets stuck though, then do a project clean. Inside eclipse select Project->Clean.
Related
So out of the blue I've ran into this problem. This is the Gradle Build console output:
https://i.stack.imgur.com/YxvfR.png
I've checked some posts online (mostly SO). So far I've changed the buildToolsVersion (which it doesn't let me be lower than 25.0.0), did Clean Builds, Restarts, checked all XML files for problems.
Nothing solved it. Also I didn't find anything about the first few errors ("No resourse matches..."). I tried to change those files to delete those lines but 1)"They're not part of the project" 2)If I change in anyway there's another error.
I've also returned to previous builds of my code, which worked and somehow now they all show the same errors.
Can you point me in the right direction? I want to understand what's wrong and how can I solve this?
[UPDATE]
Here's the code for res\layout\abc_list_menu_item_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall">
<!-- Icon will be inserted here. -->
<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
<RelativeLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="?attr/listPreferredItemPaddingLeft"
android:layout_marginRight="?attr/listPreferredItemPaddingRight"
android:duplicateParentState="true">
<TextView
android:id="#+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:textAppearance="?attr/textAppearanceListItemSmall"
android:singleLine="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView
android:id="#+id/shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true"
android:duplicateParentState="true" />
</RelativeLayout>
<!-- Checkbox, and/or radio button will be inserted here. -->
And this one's for res\layout\abc_popup_menu_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:minWidth="196dip"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem">
<!-- Icon will be inserted here. -->
<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
<RelativeLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.InternalGroup">
<TextView
android:id="#+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textAppearance="?attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" />
<TextView
android:id="#+id/shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:textAppearance="?attr/textAppearanceSmallPopupMenu"
android:singleLine="true"
android:duplicateParentState="true"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" />
</RelativeLayout>
<ImageView
android:id="#+id/submenuarrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:scaleType="center"
android:visibility="gone" />
<!-- Checkbox, and/or radio button will be inserted here. -->
The difference of these two to the res\merged\debug\SAME_NAME is none other than an error on the line xmlns:android="http://schemas.android.com/apk/res/android"saying URI is not registered. Since both of these files were created automatically I have no idea what's going on. I've searched this last "URI not registered" error but all the solutions presented are so different and seem so specific to one's project that they don't seem to apply here. I tried using Build Variant "release" and then changing it back but nothing happened again.
This happens out of the blue for me as well. I'm paying attention as to why that happened, but the solution is to clear the build cache.
To execute the task, select View > Tool Windows > Terminal from the menu bar and use one of the following commands:
For Windows: gradlew cleanBuildCache
For Mac or Linux: ./gradlew cleanBuildCache
For future reference and related options, check out this link:
Clear the build cache
Now, I finally got this to work but have simply no idea why or how it started working. So I had this ListView in one of my layouts and I wanted to add another in other layout. For some reason, when I created the second it changed the IDs of the first (one of them was 'title').
I deleted both ListViews but the problem persisted. So when I realized that I had the ListView with a 'title' id I decided to do it again with the first IDs and now everything works.
Couple of questions:
Why did the second ListView changed the first's IDs? - I created a Layout for the ListViews and seperate adapters since I wanted to show them in different ways.
Why deleting the layouts and the adapters did not solve the issue at first?
Plus, I still have an issue which is related. When I press the 3dots on the Toolbar (overflow), the app crashes. It throws a NullPointerException at ListMenuItemView. When I go to one of the faulty files in the question it says that it Cannot find the declaration of android.support.v7.view.menu.ListMenuItemView... Any ideas on what's going on?
I have started developing an app with Android Studio, and now, for no apparent reason, one of the content xml files is having rendering problems, seemingly missing a theme or something. But in both files, the one working and the one not working, there is no reference to ANY theme in the file.
I am totally confused. This does not make any sense to me. Please let me know which files I should post so someone can take a look!
Content of the file that seems to miss the theme, or whatever:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
android:alignmentMode="alignBounds"
android:columnOrderPreserved="false"
android:columnCount="4"
>
<TextView
android:text="#string/MainTitle"
android:textSize="32dip"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"
android:id="#+id/textView1"
/>
<TextView
android:text="You can configure email in just a few steps:"
android:textSize="16dip"
android:layout_columnSpan="4"
android:layout_gravity="left"
/>
<TextView
android:text="Email address:"
android:layout_gravity="right"
/>
<EditText
android:ems="10"
/>
<TextView
android:text="Password:"
android:layout_column="0"
android:layout_gravity="right"
/>
<EditText
android:ems="8"
/>
<Space
android:layout_row="4"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="fill"
/>
<Button
android:text="Next"
android:id="#+id/imageButton1"
android:layout_row="5"
android:layout_column="3"
/>
</GridLayout>
Error:
Rendering Problems Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find style 'textViewStyle' in current theme (28 similar errors not shown)
I have run into the issue before as well, and if I remember correctly, the error was caused by not having a selected android API level (e.g., API 21: Lollipop) in project settings.
The answer to the problem is a wrong theme which magically has changed with no apparent reason. Just look at the place where it says 'AppTheme' on the preview:
Click there and choose something else. This choice seems to have only an effect on the preview in AndroidStudio, not when running the real app. This is done somewhere else; I still have no clue how and where this is done...
I am taking the first step into android programming and XML. I am using the Big Nerd Ranch Guide book. In Eclipse, I used the XML given in the book and I got the error XML document structures must start and end within the same entity.
How do I fix this?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="#string/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button" />
</LinearLayout>
</LinearLayout>
Problem is solved. I removed the code and saved the xml file. After that, I replaced it with the above code and saved. The error is gone. It was probably a remanant from the time when "automatically build project" was enabled.
Strange.
I just created a new projet, building some layouts, writing some code. Everything was fine except I got this error as shown in the picture below.
I tried to remove and type it again and when typing 'R.id.', there was no 'container' showing up in the list. So that means theres no problem with my R file, just that the 'container' word lost somewhere.
Those code above are actually default code in onCreate() method in your main activity everytime you create a new project in Android Studio. (I actually tried to create a new project to compare and yes it's the same, and without error as it's brand new.).
All I did was comment out the if statement block so the error goes away, and the application has run just fine on the emulator. I just don't know why I got that problem and how I can handle it as I may need to do that in the future. Thank you!
Edit after #Raghunandan has mentioned: Below is my xml.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/provide_information"
android:id="#+id/provideInfoButton"
android:layout_alignParentTop="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/take_picture"
android:id="#+id/takePictureButton"
android:layout_below="#+id/provideInfoButton"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_below="#+id/takePictureButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/classNameTextView"
android:layout_above="#+id/personNametextView2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginBottom="38dp"
android:layout_above="#+id/emailTextView"
android:layout_alignLeft="#+id/emailTextView"
android:id="#+id/personNameTextView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/emailTextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/classNameTextView"
android:layout_marginBottom="82dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/send_button"
android:id="#+id/sendButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The reason is that I changed the root layout to RelativeLayout (the default of Android Studio was FrameLayout which has an id of "container"). My bad :). Thanks for mentioning about posting the xml file. I have not noticed that as I'm not as familiar with Android Studio as with Eclipse yet.
Recently I've been working on my first android app that converts to and from different units of temperatures. I have all the actual coding down pat, but I'm having an issue creating a GUI for it. I've been using the DroidDraw UI builder to generate the xml code; Inside of DroidDraw I'm using RelativeLayout throughout the entire UI. Whenver I create it in DroidDraw it looks fine in the preview, but when I try to run the app, it always ends up looking like basically a jumbled mess:
Does this have anything to due with requirements for different screen sizes, and if so, how can I fix it?
Adding some extra information, I'm not running it through an emulator; I'm running it on my captivate which has a 480x800 screen. Also, I'm building using the NetBeans IDE with the NBAndroid Plugin.
Here's my [main.xml][2] file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="#+id/input"
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_alignTop="#+id/output"
android:layout_alignParentLeft="true"
>
</EditText>
<TextView
android:id="#+id/widget42"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Output"
android:layout_below="#+id/ftok"
android:layout_alignLeft="#+id/ktoc"
>
</TextView>
<TextView
android:id="#+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Input"
android:layout_below="#+id/ftok"
android:layout_alignParentLeft="true"
>
</TextView>
<Button
android:id="#+id/ftok"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Far To Kel"
android:textStyle="bold"
android:layout_alignTop="#+id/ctok"
android:layout_alignParentLeft="true"
>
</Button>
<Button
android:id="#+id/ctok"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Cel To Kel"
android:textStyle="bold"
android:layout_alignTop="#+id/ktoc"
android:layout_alignLeft="#+id/ctof"
>
</Button>
<Button
android:id="#+id/ktoc"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Kel To Cel"
android:textStyle="bold"
android:layout_below="#+id/ctof"
android:layout_alignParentRight="true"
>
</Button>
<Button
android:id="#+id/ctof"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Cel To Far"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
>
</Button>
<Button
android:id="#+id/ktof"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Kel To Far"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</Button>
<Button
android:id="#+id/ftoc"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Far To Cel"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
</Button>
<TextView
android:id="#+id/widget50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Temperature Conversion is Fun!"
android:textSize="16sp"
android:textStyle="bold"
android:layout_below="#+id/widget49"
android:layout_toRightOf="#+id/widget41"
>
</TextView>
<TextView
android:id="#+id/widget49"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kel=Kelvin"
android:layout_below="#+id/widget48"
android:layout_alignLeft="#+id/ctok"
>
</TextView>
<TextView
android:id="#+id/widget48"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cel=Celcius"
android:layout_below="#+id/widget47"
android:layout_alignLeft="#+id/ctok"
>
</TextView>
<TextView
android:id="#+id/widget47"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Far=Fahrenheit"
android:layout_below="#+id/input"
android:layout_alignLeft="#+id/ctok"
>
</TextView>
<EditText
android:id="#+id/output"
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_below="#+id/widget42"
android:layout_toRightOf="#+id/ctok"
>
</EditText>
</RelativeLayout>
Any help would be much appreciated.
I never used droiddraw for real world layouts before and just downloaded it to test a bit around.
And from what I see: I would not recommend using it.
All the generated layouts use px by default as a unit to specify view sizes. That is a very bad idea in terms of android layouts (due to the many screen sizes/densities around) and should almost never be neccessary (I have yet to find a layout where that's useful). And even worse, I can't specify any other unit in the properties tab.
That leads to the exact problems you are seeing. Layouts which look correct on the screen size they were designed for and horribly failing on every other screen.
I recommend writing XML by hand. Or if you rather use a WYSIWYG editor, use the eclipse ADT plugin, that editor improved a lot recently.
Since the Dalvik Virtual Machine is heavily based on the Java Virtual Machine and I'm a Java Programmer, I can offer a little advice. If the droid API has an equivalent to JPanel, organize stuff with Panels (it looked like you may do that already). Also, check to see if the frame has a "refresh()" type of function - Usually that helps to tell the window to organize stuff accordingly.