android - Why can't I use relativeLayout as the parentView? -


this have setcontentview(r.layout.activity_main); , don't understand why every time run app crashes.

<?xml version="1.0" encoding="utf-8"?> <relativelayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/mainbody"    android:layout_width= "wrap_content" android:layout_height= "wrap_content"      > <linearlayout android:id="@+id/boss" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">   </linearlayout>  </relativelayout> 

but if use <linearlayou> main parent instead, won't crashes!

<?xml version="1.0" encoding="utf-8"?> <linearlayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/mainbody"    android:layout_width= "wrap_content" android:layout_height= "wrap_content"      > <linearlayout android:id="@+id/boss" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">   </linearlayout>  </linearlayout> 

and here log cat has it..

05-20 11:55:14.400: e/androidruntime(2052): fatal exception: main 05-20 11:55:14.400: e/androidruntime(2052): java.lang.classcastexception: android.widget.linearlayout$layoutparams cannot cast android.widget.relativelayout$layoutparams 

i don't it..

the problem not in xml, in java file. doing

linearlayout xyz = (linearlayout)findviewbyid(r.id.mainbody) 

while using relativelayout. getting classcastexception. this

 relativelayout xyz = (relativelayout)findviewbyid(r.id.mainbody) 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -