android - When I insert a Linear Layout I get 'The application has stopped unexpectedly' error -
i android newbie, started learning recently.
<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="@android:color/black" 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="com.bugaman.android.inspireme.mainactivity$placeholderfragment" > <imageview android:id="@+id/imageview2" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="fitcenter" android:src="@drawable/inspire" /> <imageview android:id="@+id/imageview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:src="@drawable/finalshake" /> <button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/imageview1" android:layout_centerhorizontal="true" android:text="inspire me!" android:textsize="24sp" android:typeface="serif" /> <textview android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:shadowcolor="#000000" android:shadowdx="0.0" android:shadowdy="0.0" android:shadowradius="2.0" android:textcolor="#ffffff" android:textsize="22sp" android:typeface="serif" /> </relativelayout>
when run code, fine, when insert linear layout, error next 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" android:background="@android:color/black" 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="com.bugaman.android.inspireme.mainactivity$placeholderfragment" > <imageview android:id="@+id/imageview2" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="fitcenter" android:src="@drawable/inspire" /> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:orientation="vertical" android:weightsum="1" > <textview android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.77" android:shadowcolor="#000000" android:shadowdx="0.0" android:shadowdy="0.0" android:shadowradius="2.0" android:textcolor="#ffffff" android:textsize="22sp" android:typeface="serif" /> <button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.115" android:text="inspire me!" android:textsize="24sp" android:typeface="serif" /> <imageview android:id="@+id/imageview1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.115" android:src="@drawable/finalshake" /> </linearlayout> </relativelayout>
here did is, insert linearlayout(vertical)... fill height... center horizontally... dragged textview1, button1 , imageview1 linearlayout... changed weightsum of linear layout 1... weight of textview1 0.77... weight of button1 0.115... weight of imageview1 0.115... changed layout height of textview1, button1, , imageview1 0dp... if run, error 'the application blah blah has stopped unexpectedly.'...
does know doing wrong?
logcat messages --
06-19 12:55:34.409: d/androidruntime(7999): shutting downwards vm 06-19 12:55:34.419: w/dalvikvm(7999): threadid=1: thread exiting uncaught exception (group=0x401b9648) 06-19 12:55:34.429: e/androidruntime(7999): fatal exception: main 06-19 12:55:34.429: e/androidruntime(7999): java.lang.runtimeexception: unable start activity componentinfo{com.bugaman.android.inspireme/com.bugaman.android.inspireme.mainactivity}: java.lang.classcastexception: android.widget.imageview 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.activitythread.performlaunchactivity(activitythread.java:1872) 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1893) 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.activitythread.access$1500(activitythread.java:135) 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.activitythread$h.handlemessage(activitythread.java:1054) 06-19 12:55:34.429: e/androidruntime(7999): @ android.os.handler.dispatchmessage(handler.java:99) 06-19 12:55:34.429: e/androidruntime(7999): @ android.os.looper.loop(looper.java:150) 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.activitythread.main(activitythread.java:4389) 06-19 12:55:34.429: e/androidruntime(7999): @ java.lang.reflect.method.invokenative(native method) 06-19 12:55:34.429: e/androidruntime(7999): @ java.lang.reflect.method.invoke(method.java:507) 06-19 12:55:34.429: e/androidruntime(7999): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:849) 06-19 12:55:34.429: e/androidruntime(7999): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:607) 06-19 12:55:34.429: e/androidruntime(7999): @ dalvik.system.nativestart.main(native method) 06-19 12:55:34.429: e/androidruntime(7999): caused by: java.lang.classcastexception: android.widget.imageview 06-19 12:55:34.429: e/androidruntime(7999): @ com.bugaman.android.inspireme.mainactivity.oncreate(mainactivity.java:24) 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1072) 06-19 12:55:34.429: e/androidruntime(7999): @ android.app.activitythread.performlaunchactivity(activitythread.java:1836) 06-19 12:55:34.429: e/androidruntime(7999): ... 11 more 06-19 13:03:33.717: d/androidruntime(9096): shutting downwards vm 06-19 13:03:33.717: w/dalvikvm(9096): threadid=1: thread exiting uncaught exception (group=0x401b9648) 06-19 13:03:33.727: e/androidruntime(9096): fatal exception: main 06-19 13:03:33.727: e/androidruntime(9096): java.lang.runtimeexception: unable start activity componentinfo{com.bugaman.android.inspireme/com.bugaman.android.inspireme.mainactivity}: java.lang.classcastexception: android.widget.imageview 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.activitythread.performlaunchactivity(activitythread.java:1872) 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1893) 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.activitythread.access$1500(activitythread.java:135) 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.activitythread$h.handlemessage(activitythread.java:1054) 06-19 13:03:33.727: e/androidruntime(9096): @ android.os.handler.dispatchmessage(handler.java:99) 06-19 13:03:33.727: e/androidruntime(9096): @ android.os.looper.loop(looper.java:150) 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.activitythread.main(activitythread.java:4389) 06-19 13:03:33.727: e/androidruntime(9096): @ java.lang.reflect.method.invokenative(native method) 06-19 13:03:33.727: e/androidruntime(9096): @ java.lang.reflect.method.invoke(method.java:507) 06-19 13:03:33.727: e/androidruntime(9096): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:849) 06-19 13:03:33.727: e/androidruntime(9096): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:607) 06-19 13:03:33.727: e/androidruntime(9096): @ dalvik.system.nativestart.main(native method) 06-19 13:03:33.727: e/androidruntime(9096): caused by: java.lang.classcastexception: android.widget.imageview 06-19 13:03:33.727: e/androidruntime(9096): @ com.bugaman.android.inspireme.mainactivity.oncreate(mainactivity.java:24) 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1072) 06-19 13:03:33.727: e/androidruntime(9096): @ android.app.activitythread.performlaunchactivity(activitythread.java:1836) 06-19 13:03:33.727: e/androidruntime(9096): ... 11 more 06-19 13:08:33.820: d/process(9096): killprocess, pid=9096
clean , rebuild app.
sometimes when editing resource xml files , reordering, adding or deleting elements @+id
identifiers id numbers messed between generated r.java
, compiled binary xml resource files. when requesting view findviewbyid()
, id matches other view , attempting cast result type can cause classcastexception
.
it's android developers using adt have learn: build dependency scheme not reliable , when related resources doesn't quite work right, clean , rebuild first see if solves issue.
android xml android-linearlayout
No comments:
Post a Comment