Empty Region - Android XML Layout and Mac OS X 10.7 - android

I've been using the ADT release from developers.android.com that comes with SDK and Eclipse in one package. I have some code that gives me a Empty Region exception upon drawing the XML file in the graphical layout tab.
Exception raised during rendering: Empty region! Exception details are
logged in Window > Show View > Error Log
java.lang.IllegalArgumentException: Empty region!
at javax.imageio.ImageReader.computeRegions(ImageReader.java:2689)
at com.sun.imageio.plugins.wbmp.WBMPImageReader.read(WBMPImageReader.java:184)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1282)
at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:96)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:233)
at com.android.layoutlib.bridge.bars.CustomBar.loadIcon(CustomBar.java:196)
at com.android.layoutlib.bridge.bars.CustomBar.loadIconById(CustomBar.java:188)
at com.android.layoutlib.bridge.bars.CustomBar.loadIconById(CustomBar.java:155)
at com.android.layoutlib.bridge.bars.FakeActionBar.(FakeActionBar.java:38)
This came on suddenly and shows a null pointer exception on Windows version of eclipse with the SDK.
I've checked for all images, as someone somewhere said something about corrupted images. Programs can view them just fine. I've fixed the project settings and reloaded eclipse, failed to resolve.
<com.demortes.controller.DualJoystickView
android:id="#+id/dualjoystickView"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent" android:layout_height="175dp"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/>
<Button
android:id="#+id/button_A"
android:layout_width="90dp"
android:text="#string/a_button"
android:textSize="24sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginRight="10dp" />
<Button
android:id="#+id/button_B"
android:text="#string/b_button"
android:textSize="24sp"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="#+id/button_Y"
android:text="#string/y_button"
android:textSize="24sp"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<Button
android:id="#+id/button_X"
android:text="#string/x_button"
android:textSize="24sp"
android:layout_width="90dp"
android:layout_height="wrap_content" />
</LinearLayout>
There's my XML file.
Now here's where it gets weird. When I switch the API from 17 to 8 in the graphical layout tab, it draws it... but incorrectly. It's completely strange to me.
Any insight you can think of is greatly appreciated! TIA.

check Manifest.xml like this
<application
android:label="#string/app_name"
android:icon="#drawable/logo"/>
make sure "drawable_hdpi" "drawable_ldpi" "drawable_mdpi" have file logo.png and the image resolution is correct.

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 solve rendering problems in AndroidStudio?

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...

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.

Cannot resolve symbol 'container' - Android Studio

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.

RelativeLayout - Couldnt resolve resource

I have a relative layout which works fine at runtime but in the Eclipse graphical layout designer I receive the exception
Couldn't resolve resource #id/imgSessionOutcome_Product1_Icon
The resource of the imageview is defined and is before the references to it, so I can't quite see what the issue is ? The exception is listed twice so both references to it fail.
I've saved/cleaned project to make sure resources rebuilt, still same error.
Eclipse Version: Helios Service Release 2 running on OSX with latest updates etc.
<RelativeLayout
android:id="#+id/lySessionOutcome_Product1"
android:layout_width="match_parent"
android:layout_height="55dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="5dip"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="#+id/imgSessionOutcome_Product1_Icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dip"
android:src="#drawable/gr_bag_bc" />
<TextView
android:id="#+id/tvSessionOutcome_Product1_Description"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/imgSessionOutcome_Product1_Icon"
android:ellipsize="marquee"
android:singleLine="false"
android:text="Description" />
<TextView
android:id="#+id/tvSessionOutcome_Product1_Type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/tvSessionOutcome_Product1_Description"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="#id/imgSessionOutcome_Product1_Icon"
android:gravity="center_vertical"
android:text="Product type"
android:textAppearance="#style/largeBlack" />
</RelativeLayout>
try using
android:layout_toRightOf="#+id/imgSessionOutcome_Product1_Icon"
Well I answered this long time ago I didn't knew why it works then and I am still not sure but based on my observation I think using + sign instead creates a temporary reference to the view so that we can view it in Android layout editor, actual anchor view gets picked at runtime only.
If you wont use the + sign it works fine at runtime as stated in the question itself.
Please correct me if I am wrong.

Categories

Resources