Cannot resolve symbol 'container' - Android Studio - android

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.

Related

Android Studio shows wrong layout in layout preview (ActionBarOverlayLayout?!)

I have a nice FrameLayout as main container and some other views inside it's hierarchy.
But the preview shows a simple ActionBarOverlayLayout.
What is that? Why is it here?
I have Android Studio 3.0.0
I have tried:
Restart Android Studio. Refresh the preview by resizing. Changed the preview device, changed the SDK of the preview, changed the blueprint\design options, pressed "force refresh layout" Button.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="match_parent"
android:layout_height="#dimen/walk_list_item_height"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:layout_heightPercent="25%"
app:layout_marginLeftPercent="0%"
app:layout_marginTopPercent="0%"
app:layout_widthPercent="100%"
app:riv_corner_radius="#dimen/corner_radius"
android:id="#+id/walk_iv" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/gradient"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<TextView
android:id="#+id/walk_name_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:padding="16dp"
android:text="New Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_duration_icon" />
<TextView
android:id="#+id/duration_tv"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:gravity="center|left"
android:text="TextView"
android:textColor="#fff" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_marker"
android:layout_marginLeft="16dp" />
<TextView
android:id="#+id/stops_tv"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
That is because there is a broken build in your earlier build. It is coming from the intermediate files which is because the files are not proper in your xml files. There might be a broken link or a - in the drawables names.
Until you resolve this you cannot proceed to see the layout of your app in the layout-editor.
Moreover Android Studio will not show you any error in the error log or any other terminal.
Start from the styles/themes of the app, it might contain something which is missing from the gradle or resources of the project. Due to the support library still in the project it partially showcases it as missing control of XML files, but it will not let you load the xml editor visually for the project.
You have see that by yourself, start first from drawables and then move to values folder, if not check your gradle and then come back to Java files for the error.
Had to raise
buildToolsVersion to 26.0.0
previous was bugged (25.0.2)
I faced the same problem and, In my case, it was simpler than that. I just received a warning message recommending to remove the explict reference to the BuildToolsVerison from build.gradle file so I just did it, then saved all file, Menu >> Run >> Make a project and it worked fine.

How to port RelativeLayout from Android source code?

Background
I have a card-like UI on my app, which uses a RelativeLayout.
The problem
Recently I've discovered that on at least one device ( or rom, or andorid version), when I switch to an RTL language (such as Hebrew), everything got messed up.
This has happened only on LG G2 with Android V4.2.2 .
Here's what I see:
If you compare it to the screenshots of the app, you can see this is not how it should look like.
That's even though on all Android devices that I've checked, and on all emulators, I've never seen it (even when switching to Hebrew).
What I've tried
I've tried to fix it by using a GridLayout instead, but that wasn't working well (link here).
I've also tried to use a LinearLayout, but considering there might be issues with it, I've used LinearLayoutCompat instead. It works, but it's not recommended to use so many.
Another thing I've tried is to port the RelativeLayout of Android source code, but this gives me a lot of warnings and errors that are quite hard to handle.
Here's the original XML of the layout, BTW (I've removed the irrelevant stuff, to make it shorter) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants" >
<ImageView
android:id="#+id/appIconImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="#android:drawable/sym_def_app_icon" />
<LinearLayout
android:id="#+id/appDetailsContainer"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/appIconImageView"
android:layout_toLeftOf="#+id/overflowView"
android:layout_toRightOf="#+id/appIconImageView"
android:layout_toStartOf="#+id/overflowView"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:text="label" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="description" />
</LinearLayout>
<ImageView
android:id="#+id/overflowView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#android:drawable/sym_def_app_icon" />
<ImageView
android:id="#+id/isSystemAppImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="#android:drawable/sym_def_app_icon" />
</RelativeLayout>
The question
As I use RelativeLayout, how can I port the code from the official source code of Android?
Is there maybe a library that does it?

Error in ImageButtons at src:"#drawable/..." Top level element is not completed

Everytime I put a #drawable item it appears underlined in red. It worked before but I pressed one of the options in the light bulb that appears next to the line and then all drawables became errors. I can't find the problem... I'm working with Android Studio. I tried to rebuild, clean, reimport... and nothing solves the problem.
My code:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="*" android:stretchColumns="*" android:background="#ffffff">
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/back"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:background="#null"
android:src="#drawable/backstate" /> /////////////////ERROR in "#drawable/backstate" (Underlined in red)
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/blanc"
android:layout_marginTop="50dp"
android:layout_marginLeft="20dp"
android:background="#null"
android:src="#drawable/blancstate"/> /////////////////SAME ERROR
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/groc"
android:layout_marginTop="50dp"
android:layout_marginRight="20dp"
android:background="#null"
android:src="#drawable/grocstate"/> /////////////////SAME ERROR
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/taronja"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:background="#null"
android:src="#drawable/taronjastate"/> /////////////////SAME ERROR
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/vermell"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="#null"
android:src="#drawable/vermellstate"/> /////////////////SAME ERROR
</TableRow>
</TableLayout>
All xml states are correct, layouts are well formed, i didn't change anything from the code, and by clicking that option that I didn't remember, all drawables started to give me errors.
ERROR DESCRIPTION: Top level element is not completed. Valid XML document must have a root tag.
Anyway the document is well formed... And it says the same error each time I write "#drawable/..."
EDIT: I found the origin of the problem. android namespace is the problem, if I change it for tools namespace it works. tools:src="#drawable/vermellstate" for example.
Can anyone help me please?
Try this:
Select item that is displaying error, then press alt + enter on the drawable item which calls error (for example:"#drawable/vermellstate") and select "Uninject language/reference"
Could be the case that you injected language by mistake.
If you are using Android Studio right click the code in question then->Local History->Show History and revert to a time prior to "Language Injection Configuration Update" .
Hope it helped,
Best of luck !

Code okay and yet I get error - XML document structures must start and end within the same entity

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.

Bizarre exceptions being thrown in android activity

So, I have an android app to finish making for a project, the same one as I asked questions about here before but this time I'm having trouble with a completely different aspect. Since the app is about Pokémon, in one activity I have some TextViews, EditTexts and a button set up to make an IV calculator. If you're curious and don't know what "IVs" are in Pokémon, google it of course. Anyway, getting back on track...this image here I put together highlights my problem
Above the boxed line you see there is a ClassCastException thrown saying cannot cast from type TextView to EditText...I know what that means in a general sense but I cannot fathom why it is occurring here because as you can see in the relevant line of code (which i pasted into the image) the part of that line that involves casting is casting from View (return type of findViewById) to EditText. The arg R.id.EditText06 IS referring to an EditText in my activity so I don't see where the bad casting attempt is supposedly occurring. Just for a little clarification of the context of this, this is part of stuff coded into the OnClickListener of the button.
Apologies if this question seems perhaps incomplete as regards content shown about the problem but it is quite late for me (so much so that I'm going to bed upon posting this) and please do ask for me to post other stuff if you feel you need it to try to help me.
EDIT: here is my xml file for the activity in question. http://pastebin.com/g5B8d393
EDIT2: OK now this is getting worse :( My current setup is that I have a sort of dummy main activity with just a button to launch an activity. While testing I changed which one it was to launch as desired...until some time last night (and I really don't see what could've started this problem) it worked fine with my IVCalculatorActvity once I had it working fully and properly, and with the other activity. But now, it just crashes when I hit the button in the main activity...I'm just going to upload the project somewhere. (http://www.filehosting[DOT]org/file/details/429262/PokeUtility.zip)
Grrr...curse this reputation restriction on link posting >.>
I understand the reasoning but meh...
EDIT3: apologies for ssuch sudden editing but I only just saw you latest post now HalR. Testing app atm.
findViewById doesn't return an object of class View, but of whatever class that object is indicated in your XML file. Whatever you think you are describing your EditText06 as in your XML, it thinks its a TextView instead of and EditText. Double check and make sure you aren't defining the id="EditText06" in more than one spot.
If you show your xml, It would likely be easier for someone to point out the specific problem in your xml file.
You need to use the format "#+id/..." once for each label, the first time it shows up (either as a reference or as an id". Otherwise you generate multiple labels. I edited your file the way I think it needs.
<?xml version="1.0" encoding="utf-8"?>
<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"
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=".IVCalculatorActivity" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/calculate" />
<EditText
android:id="#+id/EditText01"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textViewD"
android:layout_alignBottom="#id/textViewD"
android:layout_alignLeft="#+id/EditText05"
android:ems="10" />
<EditText
android:id="#+id/EditText03"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignBottom="#id/textView5"
android:layout_alignLeft="#+id/EditText02"
android:ems="10" />
<EditText
android:id="#+id/EditText04"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView6"
android:layout_alignBottom="#id/textView6"
android:layout_alignLeft="#+id/EditText03"
android:ems="10" />
<TextView
android:id="#+id/textViewA"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textViewC"
android:layout_alignParentTop="true"
android:text="#string/IVcalcHeader" />
<TextView
android:id="#id/textViewC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/textViewD"
android:layout_below="#id/textViewA"
android:layout_marginTop="26dp"
android:text="Stat" />
<EditText
android:id="#id/EditText05"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/textViewC"
android:layout_alignBottom="#id/textViewC"
android:layout_alignRight="#id/textViewA"
android:ems="10" />
<TextView
android:id="#id/textViewD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textViewB"
android:layout_below="#id/EditText05"
android:layout_marginTop="27dp"
android:text="Stat value" />
<EditText
android:id="#+id/EditText02"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/textViewB"
android:layout_alignBottom="#id/textViewB"
android:layout_alignLeft="#id/EditText01"
android:ems="10" />
<TextView
android:id="#id/textViewB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/textView5"
android:layout_below="#id/EditText01"
android:layout_marginTop="28dp"
android:text="Level" />
<TextView
android:id="#id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/textView6"
android:layout_centerVertical="true"
android:text="EV count" />
<TextView
android:id="#id/textView6"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_alignRight="#id/button3"
android:layout_below="#+id/EditText03"
android:layout_marginTop="29dp"
android:text="Base Stat" />
<TextView
android:id="#+id/textViewE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/textView6"
android:layout_below="#id/textView6"
android:layout_marginTop="40dp"
android:text="Nature" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/EditText04"
android:layout_alignTop="#id/button3"
android:text=" " />
<EditText
android:id="#+id/EditText06"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/textViewE"
android:layout_alignBottom="#id/textViewE"
android:layout_alignLeft="#id/textView7"
android:ems="10" />
</RelativeLayout>

Categories

Resources