android.widget.ImageView cannot be cast to android.widget.CheckBox -
my code crashing , giving error image view cannot cast checkbok. source code shown below. pl me figure out pblm
package com.example.application1; import android.content.context; import android.content.intent; import android.content.res.resources; import android.database.cursor; import android.graphics.bitmap; import android.os.bundle; import android.provider.mediastore; import android.provider.mediastore.images.media; import android.util.sparsebooleanarray; import android.view.layoutinflater; import android.view.view; import android.view.window; import android.view.view.onclicklistener; import android.view.viewgroup; import android.view.animation.animation; import android.view.animation.animationutils; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.baseadapter; import android.widget.button; import android.widget.checkbox; import android.widget.compoundbutton; import android.widget.compoundbutton.oncheckedchangelistener; import android.widget.gridview; import android.widget.imageview; import android.widget.textview; import com.nostra13.universalimageloader.core.displayimageoptions; import com.nostra13.universalimageloader.core.displayimageoptions.builder; import com.nostra13.universalimageloader.core.imageloader; import com.nostra13.universalimageloader.core.imageloaderconfiguration; import com.nostra13.universalimageloader.core.listener.simpleimageloadinglistener; import java.io.printstream; import java.util.arraylist; //import com.example.application1.r.layout; import java.util.hashset; import android.*; import com.example.application1.baseactivity; import com.example.application1.r.menu; public class multiphotoselectactivity extends baseactivity { private albumadapter albumadapter; button done; private gridview gridview; private imageadapter imageadapter; private arraylist<string> imageurls; private boolean isalbumview; private arraylist<album> malbumslist; private displayimageoptions options; private void fillalbums() { this.isalbumview = true; this.malbumslist = new arraylist(); string[] arrayofstring = { "_data", "_id", "bucket_display_name", "bucket_id" }; cursor localcursor = managedquery(mediastore.images.media.external_content_uri, arrayofstring, null, null, null); hashset localhashset = new hashset(); (int = 0;; i++) { if (i >= localcursor.getcount()) { return; } album localalbum = new album(); localcursor.movetoposition(i); int j = localcursor.getcolumnindex("_data"); int k = localcursor.getcolumnindex("bucket_display_name"); int m = localcursor.getcolumnindex("bucket_id"); localcursor.getcolumnindex("_id"); string str = localcursor.getstring(k); localalbum.setalbumname(str); localalbum.setimageurl(localcursor.getstring(j)); localalbum.albumid = localcursor.getstring(m); if (localhashset.add(str)) { this.malbumslist.add(localalbum); } system.out.println("=====> bucket_display_name => " + localcursor.getstring(localcursor.getcolumnindex("bucket_display_name"))); } } private void fillgallery(string paramstring) { string[] arrayofstring = { "_data", "_id" }; cursor localcursor = managedquery(mediastore.images.media.external_content_uri, arrayofstring, "bucket_id=?", new string[] { paramstring }, "datetaken desc"); this.imageurls = new arraylist(); (int = 0;; i++) { if (i >= localcursor.getcount()) { this.imageadapter = new imageadapter(this.imageurls); this.gridview.setadapter(this.imageadapter); return; } localcursor.movetoposition(i); int j = localcursor.getcolumnindex("_data"); this.imageurls.add(localcursor.getstring(j)); } } public void onbackpressed() { ; if (this.isalbumview) { super.onbackpressed(); return; } this.isalbumview = true; this.gridview.setadapter(this.albumadapter); } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); imageloader.init(imageloaderconfiguration.createdefault(getbasecontext())); //baseactivity.imageloader.init(imageloaderconfiguration.createdefault(getbasecontext())); setcontentview( com.example.application1.r.layout.activity_multiphoto_); fillalbums(); this.options = new displayimageoptions.builder().showstubimage(r.drawable.ic_gallery).showimageforemptyuri(r.drawable.ic_gallery).cacheinmemory().cacheondisc().build(); this.albumadapter = new albumadapter(this.malbumslist); this.gridview = ((gridview)findviewbyid(r.id.gridview)); this.done = ((button)findviewbyid(r.id.done)); this.gridview.setadapter(this.albumadapter); this.gridview.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview<?> paramanonymousadapterview, view paramanonymousview, int paramanonymousint, long paramanonymouslong) { if (multiphotoselectactivity.this.isalbumview) { multiphotoselectactivity.this.isalbumview = false; multiphotoselectactivity.this.fillgallery(((multiphotoselectactivity.album)multiphotoselectactivity.this.malbumslist.get(paramanonymousint)).albumid); } } }); this.done.setonclicklistener(new view.onclicklistener() { public void onclick(view paramanonymousview) { arraylist localarraylist = multiphotoselectactivity.this.imageadapter.getcheckeditems(); intent localintent = new intent(multiphotoselectactivity.this, createslideactivity.class); localintent.putextra("list", localarraylist); system.out.println(" " + localarraylist); multiphotoselectactivity.this.setresult(-1, localintent); multiphotoselectactivity.this.finish(); } }); } protected void ondestroy() { super.ondestroy(); } protected void onstop() { super.onstop(); } public class album { public string albumid; private string albumname; private string imageurl; public album() {} public string getalbumname() { return this.albumname; } public string getimageurl() { return this.imageurl; } public void setalbumname(string paramstring) { this.albumname = paramstring; } public void setimageurl(string paramstring) { this.imageurl = paramstring; } } public class albumadapter extends baseadapter { context mcontext; arraylist<multiphotoselectactivity.album> mlist; public albumadapter(arraylist<album> malbumslist) { this.mlist = malbumslist; } public int getcount() { return this.mlist.size(); } public multiphotoselectactivity.album getitem(int paramint) { return (multiphotoselectactivity.album)this.mlist.get(paramint); } public long getitemid(int paramint) { return paramint; } public view getview(int paramint, view paramview, viewgroup paramviewgroup) { if (paramview == null) { paramview = ((layoutinflater)multiphotoselectactivity.this.getsystemservice("layout_inflater")).inflate(r.layout.row_album_item, null); } final imageview localimageview = (imageview)paramview.findviewbyid(r.id.albumview); textview localtextview = (textview)paramview.findviewbyid(r.id.albumname); multiphotoselectactivity.this.imageloader.displayimage("file://" + ((multiphotoselectactivity.album)this.mlist.get(paramint)).imageurl, localimageview, multiphotoselectactivity.this.options, new simpleimageloadinglistener() { public void onloadingcomplete(bitmap paramanonymousbitmap) { animation localanimation = animationutils.loadanimation(multiphotoselectactivity.this, r.anim.fade_in); localimageview.setanimation(localanimation); localanimation.start(); } }); localtextview.settext(((multiphotoselectactivity.album)this.mlist.get(paramint)).albumname); return paramview; } } class imageadapter extends baseadapter { compoundbutton.oncheckedchangelistener mcheckedchangelistener = new compoundbutton.oncheckedchangelistener() { public void oncheckedchanged(compoundbutton paramanonymouscompoundbutton, boolean paramanonymousboolean) { multiphotoselectactivity.imageadapter.this.msparsebooleanarray.put(((integer)paramanonymouscompoundbutton.gettag()).intvalue(), paramanonymousboolean); } }; context mcontext; arraylist<string> mlist; sparsebooleanarray msparsebooleanarray = new sparsebooleanarray(); public imageadapter(arraylist<string> imageurls) { this.mlist = imageurls; } public arraylist<string> getcheckeditems() { arraylist<string> arraylist = new arraylist<string>(); int = 0; { if (i >= mlist.size()) { return arraylist; } if (msparsebooleanarray.get(i)) { arraylist.add((string)mlist.get(i)); } i++; } while (true); } public int getcount() { return multiphotoselectactivity.this.imageurls.size(); } public object getitem(int paramint) { return null; } public long getitemid(int paramint) { return paramint; } public view getview(int paramint, view paramview, viewgroup paramviewgroup) { //imageloader.init(imageloaderconfiguration.createdefault(getbasecontext())); if (paramview == null) { paramview = ((layoutinflater)multiphotoselectactivity.this.getsystemservice("layout_inflater")).inflate(r.layout.row_multiphoto_item, null); } multiphotoselectactivity.this.done.setvisibility(0); checkbox localcheckbox = (checkbox)paramview.findviewbyid(r.id.imageview2); final imageview localimageview = (imageview)paramview.findviewbyid(r.anim.fade_in); multiphotoselectactivity.this.imageloader.displayimage("file://" + (string)multiphotoselectactivity.this.imageurls.get(paramint), localimageview, multiphotoselectactivity.this.options, new simpleimageloadinglistener() { public void onloadingcomplete(bitmap paramanonymousbitmap) { animation localanimation = animationutils.loadanimation(multiphotoselectactivity.this, r.anim.fade_in); localimageview.setanimation(localanimation); localanimation.start(); } }); localcheckbox.settag(integer.valueof(paramint)); localcheckbox.setchecked(this.msparsebooleanarray.get(paramint)); localcheckbox.setoncheckedchangelistener(this.mcheckedchangelistener); return paramview; } } }
this xml file row_multi_photo.
<?xml version="1.0" encoding="utf-8"?> <relativelayout android:padding="0.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <relativelayout android:background="@drawable/bg_photo" android:padding="3.0dip" android:layout_width="108.0dip" android:layout_height="108.0dip"> <imageview android:id="@+id/imageview2" android:layout_width="105.0dip" android:layout_height="105.0dip" android:src="@drawable/ic_launcher" android:scaletype="centercrop" android:layout_centerinparent="true" /> </relativelayout> <checkbox android:id="@+id/checkbox1" android:padding="3.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/checkbox" android:layout_alignparentright="true" android:layout_alignparentbottom="true" /> </relativelayout>
the log cat shown below
09-10 18:57:51.569: e/androidruntime(25984): fatal exception: main 09-10 18:57:51.569: e/androidruntime(25984): java.lang.illegalargumentexception: view must not null 09-10 18:57:51.569: e/androidruntime(25984): @ com.nostra13.universalimageloader.core.imageaware.viewaware.<init>(viewaware.java:70) 09-10 18:57:51.569: e/androidruntime(25984): @ com.nostra13.universalimageloader.core.imageaware.viewaware.<init>(viewaware.java:50) 09-10 18:57:51.569: e/androidruntime(25984): @ com.nostra13.universalimageloader.core.imageaware.imageviewaware.<init>(imageviewaware.java:44) 09-10 18:57:51.569: e/androidruntime(25984): @ com.nostra13.universalimageloader.core.imageloader.displayimage(imageloader.java:365) 09-10 18:57:51.569: e/androidruntime(25984): @ com.nostra13.universalimageloader.core.imageloader.displayimage(imageloader.java:340) 09-10 18:57:51.569: e/androidruntime(25984): @ com.example.application1.multiphotoselectactivity$imageadapter.getview(multiphotoselectactivity.java:313) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.abslistview.obtainview(abslistview.java:2465) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.gridview.makeandaddview(gridview.java:1331) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.gridview.makerow(gridview.java:331) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.gridview.filldown(gridview.java:283) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.gridview.fillfromtop(gridview.java:407) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.gridview.layoutchildren(gridview.java:1241) 09-10 18:57:51.569: e/androidruntime(25984): @ android.widget.abslistview.ontouchevent(abslistview.java:3898) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.view.dispatchtouchevent(view.java:7234) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2231) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1964) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2237) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1979) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2237) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1979) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2237) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1979) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2237) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1979) 09-10 18:57:51.569: e/androidruntime(25984): @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:2177) 09-10 18:57:51.569: e/androidruntime(25984): @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1482) 09-10 18:57:51.569: e/androidruntime(25984): @ android.app.activity.dispatchtouchevent(activity.java:2470) 09-10 18:57:51.569: e/androidruntime(25984): @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:2125) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.view.dispatchpointerevent(view.java:7414) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewrootimpl.deliverpointerevent(viewrootimpl.java:3555) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewrootimpl.deliverinputevent(viewrootimpl.java:3487) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewrootimpl.doprocessinputevents(viewrootimpl.java:4604) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewrootimpl.enqueueinputevent(viewrootimpl.java:4582) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewrootimpl$windowinputeventreceiver.oninputevent(viewrootimpl.java:4686) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.inputeventreceiver.dispatchinputevent(inputeventreceiver.java:177) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.inputeventreceiver.nativeconsumebatchedinputevents(native method) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.inputeventreceiver.consumebatchedinputevents(inputeventreceiver.java:166) 09-10 18:57:51.569: e/androidruntime(25984): @ android.view.viewrootimpl.doconsumebatchedinput(viewrootimpl.java:4654)
the problem here :
checkbox localcheckbox = (checkbox)paramview.findviewbyid(r.id.imageview2);
you casting imageview checkbox , change :
checkbox localcheckbox = (checkbox)paramview.findviewbyid(r.id.checkbox1);
Comments
Post a Comment