I am working on android application, in which i am getting an error of Zero Exception. I am also not able to see my xml display on editor but it is working on device or emulator. Kindly please guide me what should i do for this error. My XML code is given below:
<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:background="#drawable/bg"
android:gravity="center_vertical"
android:orientation="horizontal" >
<com.zhy.view.CircleMenuLayout
android:id="#+id/id_menulayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="100dp"
android:background="#drawable/circle_bg" >
<RelativeLayout
android:id="#+id/id_circle_menu_item_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="104.0dip"
android:layout_height="104.0dip"
android:layout_centerInParent="true"
android:background="#drawable/turnplate_center_unlogin" />
<ImageView
android:layout_width="116.0dip"
android:layout_height="116.0dip"
android:layout_centerInParent="true"
android:background="#drawable/turnplate_mask_unlogin_normal" />
</RelativeLayout>
</com.zhy.view.CircleMenuLayout>
</LinearLayout>
Related
I am trying to design as shown in below figure,i have a linear layout,inside that i am adding two images,over each image i am adding text view.But as per below code image doesnt even appear in xml file(i have added image in drawable folder),What i am missing here?Please help me..
.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C5C5C5">
<TextView
android:text="Desing view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="#+id/linearLayout1"
android:background="#c5c5c5">
<ImageView
android:src="#drawable/img"
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/imageView1" />
<ImageView
android:src="#drawable/img"
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/imageView2" />
</LinearLayout>
</LinearLayout>
<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"
tools:context="${packageName}.${activityClass}" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context=".MainActivity" >
<AnalogClock
android:id="#+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="290dp" />
<TextClock
android:id="#+id/textClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="146dp"
android:text="#+id/textclock"
android:textColor="#FFFFFF"
android:textSize="100sp" />
</RelativeLayout>
Can I have some help on this I'm really confused would really appreciate some advice. I was just cleaning up my code when this error appeared. I have no idea on how to fix
The error comes because you didn't close RelativeLayout tag in your xml file,so add </RelativeLayout>at the end of xml file.
You don't need to add two relative layout where one parent layout is useless
So simply replace in your code
<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"
tools:context="${packageName}.${activityClass}" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context=".MainActivity" >
with
<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:background="#drawable/bg"
tools:context=".MainActivity" >
Second Option is
Remove your xml code and saved the xml file. After that,replace it with the above code and save. The error will be gone. It is probably a remnant from the time when "automatically build project" enabled.
I had created an old android project called LinearLayouts and written some code in activity_main.xml under the layout folder. The code ran perfectly fine on the emulator. But now I have edited activity_main.xml and changed the code. The problem is that edited or changed code is not shown on the emulator. Could anybody help me to find solution to this problem. Below is the old code and new code in activity_main.xml. When I run the new code even then the emulator shows the old code output. The new code or edited code output is not shown instead of that it shows the old code output itself.
My previous code of activity_main.xml is:
<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">
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type Here:"
/>
<EditText
android:id="#+id/edittext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/label"
android:layout_marginTop="10dp"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
My new or edited code in activity_main.xml is:
<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"
>
<SlidingDrawer
android:id="#+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Remove all the files from your /bin folder (except for AndroidManifest.xml) in your project root and try again.
After many hours I can't fix button on the bottom of activity. Either is invisible or at the top. I tried also without relative layout, I tried adding another linear layout, but I still don't know how set this button.
<?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"
tools:context=".News" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/news" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/newsbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Chiudi" />
</LinearLayout>
</RelativeLayout>
<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:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/news" />
<WebView
android:id="#+id/webView1"
android:layout_below="#id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/newsbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:text="Chiudi" />
</RelativeLayout>
First, you have a warning in Legacy Android Layout Editor, that either RelativeLayout or LinearLayout is useless. That should be a hint for you. Pay attention to warnings, they're helpful in most of the times.
Indeed, you can get rid of LinearLayout.
So, the solution is:
Remove LinearLayout.
Add android:layout_below="#+id/imageView1" to the WebView.
Add android:layout_alignParentBottom="true" to the Button.
Add android:contentDescription to ImageView.
Use #string instead of hardcoded strings.
Optional steps are not bolded, they will remove warnings.
Whole working code, tested under Android 4.1.2:
<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:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="TODO: DESCRIPTION"
android:src="#drawable/ic_launcher" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1" />
<Button
android:id="#+id/newsbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:text="Chiudi" />
</RelativeLayout>
copy paste the following in your button component ;)
android:layout_marginBottom="147dp"
android:layout_marginTop="50dp"
android:layout_marginleft="50dp"
android:layout_marginRight="47dp"
play only with the numbers and Im sure ull get the hang of it :)
Just add android:layout_below="#id/webView1" in your button.
If you would use LinearLayout, you could set the Widget that should fill the empty space like this: layout_height="0dp" and layout_weight="1". This should do the job too.
I am new to Android Development and trying to create a sample application. Can anyone tell me whats wrong with following layout (activity_sample.xml)? -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_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/app_name"
tools:context=".SampleActivity" />
</LinearLayout>
On Build, I am getting following error -
error: Error parsing XML: unbound prefix activity_sample.xml /Sample/res/layout line 4 Android AAPT Problem
You haven't declared the tools prefix in your XML. Try using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_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/app_name"
tools:context=".SampleActivity" />
</LinearLayout>