java - App crashes when adding an ImageView -


i'm trying add image app keeps crashing , can't conclude why.

i have multiple images in app, adding 1 image seems problematic. here's xml (edit: full xml (this has changed since original layout purposes)):

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="match_parent" >  <button     android:id="@+id/imagetextbutton4"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbaseline="@+id/imagetextbutton3"     android:layout_alignbottom="@+id/imagetextbutton3"     android:layout_alignleft="@+id/imagetextbutton2"     android:layout_alignright="@+id/imagetextbutton2"     android:drawabletop="@drawable/ic_launcher"     android:text="progress" />  <button     android:id="@+id/imagetextbutton3"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/imagetextbutton1"     android:layout_alignright="@+id/imagetextbutton1"     android:layout_below="@+id/imagetextbutton1"     android:layout_margintop="85dp"     android:drawabletop="@drawable/ic_launcher"     android:text="meal plans" />  <button     android:id="@+id/imagetextbutton2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentright="true"     android:layout_centervertical="true"     android:layout_marginright="22dp"     android:drawabletop="@drawable/ic_launcher"     android:text="your meals" />  <imageview     android:id="@+id/imageview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparenttop="true"     android:layout_centerhorizontal="true"     android:layout_margintop="42dp"     android:src="@drawable/logo" />  <button     android:id="@+id/imagetextbutton1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_centervertical="true"     android:layout_marginleft="16dp"     android:drawabletop="@drawable/ic_launcher"     android:text="meal of day" />  </relativelayout> 

and java code (condensed brevity):

package com.example.c3347115app;  import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.imageview; import android.content.intent;  public class mainactivity extends activity {  imageview image;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      image = (imageview) findviewbyid(r.id.imageview1); 

logcat:

05-10 01:55:30.718: w/dalvikvm(13140): threadid=1: thread exiting uncaught exception (group=0x40a99228) 05-10 01:55:30.728: e/androidruntime(13140): fatal exception: main 05-10 01:55:30.728: e/androidruntime(13140): java.lang.runtimeexception: unable     start activity componentinfo{com.example.c3347115app/com.example.c3347115app.mainactivity}: java.lang.classcastexception: android.widget.button cannot cast android.widget.imageview 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2205) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2240) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.activitythread.access$600(activitythread.java:139) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.activitythread$h.handlemessage(activitythread.java:1262) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.os.handler.dispatchmessage(handler.java:99) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.os.looper.loop(looper.java:156) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.activitythread.main(activitythread.java:4987) 05-10 01:55:30.728: e/androidruntime(13140):    @ java.lang.reflect.method.invokenative(native method) 05-10 01:55:30.728: e/androidruntime(13140):    @ java.lang.reflect.method.invoke(method.java:511) 05-10 01:55:30.728: e/androidruntime(13140):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 05-10 01:55:30.728: e/androidruntime(13140):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 05-10 01:55:30.728: e/androidruntime(13140):    @ dalvik.system.nativestart.main(native method) 05-10 01:55:30.728: e/androidruntime(13140): caused by: java.lang.classcastexception:      android.widget.button cannot cast android.widget.imageview 05-10 01:55:30.728: e/androidruntime(13140):    @ com.example.c3347115app.mainactivity.oncreate(mainactivity.java:22) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.activity.performcreate(activity.java:4538) 05-10 01:55:30.728: e/androidruntime(13140):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1071) 05-10 01:55:30.728: e/androidruntime(13140):    @        android.app.activitythread.performlaunchactivity(activitythread.java:2161) 

can figure out problem is? in advance.

when crating ids in xml file (using @+id/) on first occurrence , later use @id/

so xml should this

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="match_parent" >  <button     android:id="@+id/imagetextbutton4"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbaseline="@+id/imagetextbutton3"     android:layout_alignbottom="@id/imagetextbutton3"     android:layout_alignleft="@+id/imagetextbutton2"     android:layout_alignright="@id/imagetextbutton2"     android:drawabletop="@drawable/ic_launcher"     android:text="progress" />  <button     android:id="@id/imagetextbutton3"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/imagetextbutton1"     android:layout_alignright="@id/imagetextbutton1"     android:layout_below="@id/imagetextbutton1"     android:layout_margintop="85dp"     android:drawabletop="@drawable/ic_launcher"     android:text="meal plans" />  <button     android:id="@id/imagetextbutton2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentright="true"     android:layout_centervertical="true"     android:layout_marginright="22dp"     android:drawabletop="@drawable/ic_launcher"     android:text="your meals" />  <imageview     android:id="@+id/imageview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparenttop="true"     android:layout_centerhorizontal="true"     android:layout_margintop="42dp"     android:src="@drawable/logo" />  <button     android:id="@id/imagetextbutton1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_centervertical="true"     android:layout_marginleft="16dp"     android:drawabletop="@drawable/ic_launcher"     android:text="meal of day" />  </relativelayout> 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -