java - Passing data RecyclerView data to another activity on click -
i in process of passing information recyclerview activity called "partyinformation", in respective clicked cell. information in recyclerview fetched parse.com. recyclerview consists of textviews imageviews , populate "partyinfomation" data. when compile , run receive no errors when cell clicked recyclerview app quits , reads "unfortunately, app has stopped". the logcat prompts error: java.lang.classcastexception: android.support.v7.widget.appcompattextview cannot cast android.os.parcelable.
can please review code , identify went wrong in process of trying pass data on click?
main activity
package com.example.jbobo_000.prac; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.os.bundle; import android.support.v4.widget.drawerlayout; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.support.v7.widget.toolbar; import android.view.menu; import com.parse.findcallback; import com.parse.getcallback; import com.parse.parse; import com.parse.parseexception; import com.parse.parsefile; import com.parse.parseobject; import com.parse.parsequery; import java.util.arraylist; import java.util.list; public class homescreen extends appcompatactivity { private recyclerview mrecyclerdrawer; private customadapter madapter; private context context; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home_screen); setupdrawer(); context=this; final list<information> data = new arraylist<>(); parse.initialize(this, "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx"); final parsequery<parseobject> query = parsequery.getquery("flyerdatafetch"); query.orderbydescending("createdat"); query.findinbackground(new findcallback<parseobject>() { @override public void done(list<parseobject> results, com.parse.parseexception e) { (parseobject : results) { list<parseobject> dataholder = null; try { dataholder = query.find(); if (e == null) { information information = new information(); information.partyname = a.getstring("partyname"); information.partypromotername = a.getstring("partypromotername"); information.partycost = a.getstring("partycost"); parsefile bum1 = (parsefile) a.get("partyflyerimage"); parsefile bum2 = (parsefile) a.get("partypromoterimage"); byte[] file1 = bum1.getdata(); byte[] file2 = bum2.getdata(); information.flyerpic = bitmapfactory.decodebytearray(file1, 0, file1.length); information.partypromoterpic = bitmapfactory.decodebytearray(file2,0,file2.length); data.add(information); } else { // went wrong } } catch (parseexception e1) { e1.printstacktrace(); }} mrecyclerdrawer = (recyclerview) findviewbyid(r.id.drawerlist); mrecyclerdrawer.setlayoutmanager(new linearlayoutmanager(context)); madapter = new customadapter(context, data); mrecyclerdrawer.setadapter(madapter); madapter.notifydatasetchanged(); } }); } private void setupdrawer() { toolbar mtoolbar; navigationdrawer mdrawerfragment; mtoolbar = (toolbar) findviewbyid(r.id.app_bar); setsupportactionbar(mtoolbar); getsupportactionbar().setdisplayhomeasupenabled(true); //setup navigationdrawer mdrawerfragment = (navigationdrawer) getsupportfragmentmanager().findfragmentbyid(r.id.fragment_navigation_drawer); mdrawerfragment.setup(r.id.fragment_navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout), mtoolbar); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } }
customadapter
package com.example.jbobo_000.prac; import android.content.context; import android.content.intent; import android.graphics.bitmap; import android.os.parcelable; import android.support.v7.widget.recyclerview; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.textview; import com.parse.parseimageview; import java.util.collections; import java.util.list; public class customadapter extends recyclerview.adapter<customadapter.myviewholder> { list<information> data = collections.emptylist(); private layoutinflater inflater; private context context; public customadapter (context context,list<information>data){ this.context=context; inflater=layoutinflater.from(context); this.data= data; } @override public myviewholder oncreateviewholder(viewgroup parent, int viewtype){ view view= inflater.inflate(r.layout.custom_row, parent, false); myviewholder holder = new myviewholder(view); return holder; } @override public void onbindviewholder(myviewholder holder,int position){ information current= data.get(position); holder.promoternametext.settext(current.partypromotername); holder.costtext.settext(current.partycost); holder.partynametext.settext(current.partyname); holder.flyerimage.setimagebitmap(current.flyerpic); holder.promoterimage.setimagebitmap(current.partypromoterpic); } @override public int getitemcount(){ return data.size(); } class myviewholder extends recyclerview.viewholder implements view.onclicklistener { textview promoternametext; textview costtext; textview partynametext; imageview flyerimage; imageview promoterimage; public myviewholder(view itemview) { super(itemview); itemview.setonclicklistener(this); promoterimage = (imageview) itemview.findviewbyid(r.id.promoterpicimage); flyerimage = (imageview) itemview.findviewbyid(r.id.flyertimage); costtext = (textview) itemview.findviewbyid(r.id.costtext); promoternametext = (textview) itemview.findviewbyid(r.id.promoternametext); partynametext = (textview) itemview.findviewbyid(r.id.partynametext); } @override public void onclick(view v) { //context.startactivity(new intent(context, partyinformation.class)); int postion = getadapterposition(); intent = new intent(context, partyinformation.class); i.putextra("partyname", (parcelable) partynametext); i.putextra("promoternametext", (android.os.parcelable) promoternametext); i.putextra("costtext", (android.os.parcelable) costtext); i.putextra("flyerimage", (android.os.parcelable) flyerimage); i.putextra("promoterimage", (android.os.parcelable) promoterimage); context.startactivity(i); } } }
partyinformation
package com.example.jbobo_000.prac; import android.content.intent; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.imageview; import android.widget.textview; public class partyinformation extends actionbaractivity implements view.onclicklistener{ button checkout; textview partyname1; imageview informationflyer1; imageview promoterpic1; string partyname= getintent().getstringextra("partyname"); string promoternametext= getintent().getstringextra("promoternametext"); string costtext= getintent().getstringextra("costtext"); string flyerimage= getintent().getstringextra("flyerimage"); string promoterimage= getintent().getstringextra("promoterimage"); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_party_information); partyname1 = (textview) findviewbyid(r.id.textview2); informationflyer1 = (imageview) findviewbyid(r.id.informationflyer); promoterpic1 = (imageview) findviewbyid(r.id.imageview); partyname1.settext(partyname); //informationflyer1.setimageresource(flyerimage); //promoterpic1.setimageresource(promoterimage); checkout = (button) findviewbyid(r.id.requestticketbtn); checkout.setonclicklistener(this); } @override public void onclick(view v){ switch(v.getid()){ case r.id.requestticketbtn: startactivity(new intent(this, checkout.class));}} @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_party_information, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
logcat
06-18 17:27:28.505 28047-28047/? i/art﹕ late-enabling -xcheck:jni 06-18 17:27:28.785 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ crash reporting enabled com.example.jbobo_000.prac, initializing... 06-18 17:27:28.797 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ looking error files in /data/data/com.example.jbobo_000.prac/files/com.parse/cr/reports 06-18 17:27:28.797 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ looking error files in /data/data/com.example.jbobo_000.prac/files/com.parse/cr/minidumps 06-18 17:27:29.051 28047-28075/com.example.jbobo_000.prac d/openglrenderer﹕ use egl_swap_behavior_preserved: true 06-18 17:27:29.057 28047-28047/com.example.jbobo_000.prac d/﹕ hostconnection::get() new host connection established 0xb42ccb80, tid 28047 06-18 17:27:29.068 28047-28047/com.example.jbobo_000.prac d/atlas﹕ validating map... 06-18 17:27:29.125 28047-28075/com.example.jbobo_000.prac d/libegl﹕ loaded /system/lib/egl/libegl_emulation.so 06-18 17:27:29.127 28047-28075/com.example.jbobo_000.prac d/libegl﹕ loaded /system/lib/egl/libglesv1_cm_emulation.so 06-18 17:27:29.149 28047-28075/com.example.jbobo_000.prac d/libegl﹕ loaded /system/lib/egl/libglesv2_emulation.so 06-18 17:27:29.176 28047-28075/com.example.jbobo_000.prac d/﹕ hostconnection::get() new host connection established 0xaf0395c0, tid 28075 06-18 17:27:29.202 28047-28075/com.example.jbobo_000.prac i/openglrenderer﹕ initialized egl, version 1.4 06-18 17:27:29.316 28047-28075/com.example.jbobo_000.prac d/openglrenderer﹕ enabling debug mode 0 06-18 17:27:29.354 28047-28075/com.example.jbobo_000.prac w/egl_emulation﹕ eglsurfaceattrib not implemented 06-18 17:27:29.354 28047-28075/com.example.jbobo_000.prac w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xaf035b20, error=egl_success 06-18 17:27:30.025 28047-28047/com.example.jbobo_000.prac i/choreographer﹕ skipped 37 frames! application may doing work on main thread. 06-18 17:27:46.016 28047-28047/com.example.jbobo_000.prac i/viewutils﹕ app:theme deprecated. please move using android:theme instead. 06-18 17:27:46.371 28047-28075/com.example.jbobo_000.prac w/egl_emulation﹕ eglsurfaceattrib not implemented 06-18 17:27:46.371 28047-28075/com.example.jbobo_000.prac w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xb431d440, error=egl_success 06-18 17:27:46.409 28047-28047/com.example.jbobo_000.prac e/recyclerview﹕ no adapter attached; skipping layout 06-18 17:27:46.700 28047-28047/com.example.jbobo_000.prac e/recyclerview﹕ no adapter attached; skipping layout 06-18 17:27:47.697 28047-28056/com.example.jbobo_000.prac w/art﹕ suspending threads took: 12.419ms 06-18 17:27:49.209 28047-28047/com.example.jbobo_000.prac d/androidruntime﹕ shutting down vm 06-18 17:27:49.209 28047-28047/com.example.jbobo_000.prac e/crashreporting﹕ parsecrashreporting caught classcastexception exception com.example.jbobo_000.prac. building report. 06-18 17:27:49.210 28047-28047/com.example.jbobo_000.prac e/crashreporting﹕ handling exception crash java.lang.classcastexception: android.support.v7.widget.appcompattextview cannot cast android.os.parcelable @ com.example.jbobo_000.prac.customadapter$myviewholder.onclick(customadapter.java:77) @ android.view.view.performclick(view.java:4780) @ android.view.view$performclick.run(view.java:19866) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) 06-18 17:27:49.213 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ generating report file crash 06-18 17:27:49.284 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ retrieving logcat output... 06-18 17:27:49.312 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ retrieving logcat output... 06-18 17:27:49.329 28047-28047/com.example.jbobo_000.prac d/crashreporting﹕ retrieving logcat output... 06-18 17:27:49.388 28047-28047/com.example.jbobo_000.prac w/settings﹕ setting stay_on_always has moved android.provider.settings.system android.provider.settings.global, returning read-only value. 06-18 17:27:49.529 28047-28047/com.example.jbobo_000.prac v/crashreporting﹕ start reportsenderworker #handleexception 06-18 17:27:49.538 28047-28251/com.example.jbobo_000.prac d/crashreporting﹕ #checkandsendreports - start 06-18 17:27:49.538 28047-28251/com.example.jbobo_000.prac d/crashreporting﹕ looking error files in /data/data/com.example.jbobo_000.prac/files/com.parse/cr/reports 06-18 17:27:49.540 28047-28251/com.example.jbobo_000.prac d/crashreporting﹕ loading file 1434662869213-classcastexception-1.stacktrace 06-18 17:27:49.547 28047-28251/com.example.jbobo_000.prac i/crashreporting﹕ sending file 1434662869213-classcastexception-1.stacktrace 06-18 17:27:49.548 28047-28251/com.example.jbobo_000.prac d/crashreporting﹕ sending crash report parse... 06-18 17:27:49.556 28047-28251/com.example.jbobo_000.prac d/crashreporting﹕ #checkandsendreports - finish 06-18 17:27:49.631 28047-28047/com.example.jbobo_000.prac e/androidruntime﹕ fatal exception: main process: com.example.jbobo_000.prac, pid: 28047 java.lang.classcastexception: android.support.v7.widget.appcompattextview cannot cast android.os.parcelable @ com.example.jbobo_000.prac.customadapter$myviewholder.onclick(customadapter.java:77) @ android.view.view.performclick(view.java:4780) @ android.view.view$performclick.run(view.java:19866) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698)
change this:
i.putextra("partyname", (parcelable) partynametext); i.putextra("promoternametext", (android.os.parcelable) promoternametext); i.putextra("costtext", (android.os.parcelable) costtext)
to this:
i.putextra("partyname", partynametext.gettext().tostring()); i.putextra("promoternametext", promoternametext.gettext().tostring())); i.putextra("costtext", costtext.gettext().tostring()))
this adds data intent 'i' strings. can't cast textview parcelable.
Comments
Post a Comment