android - Displaying Image from path to ListView -
i able store images path. able retrieve , display imageview. however, whenever tried display images listview doesn't work. please see code below: response appreciated.
imageview targetimage = (imageview) findviewbyid(r.id.stud_list_image); private void populatefields() { cursor data = studentsdbadapter.queuepic(); if (data.movetofirst()) { cursoradapter = new simplecursoradapter(this, r.layout.stud_row, data, new string[] {studentsdbadapter.key_imagepathid, studentsdbadapter.key_imagepath}, new int[] {r.id.textstud,r.id.stud_list_image}); simplecursoradapter.viewbinder viewbinder = new simplecursoradapter.viewbinder() { public boolean setviewvalue(view view, cursor cursor, int columnindex) { if(view != null && view.getid() != r.id.stud_list_image) { return false; } string username = cursor.getstring(cursor.getcolumnindex(studentsdbadapter.key_imagepathid)); string path = logindatabaseadapter.getimapath(username); file image = new file(path); ((imageview)view).setimagebitmap(bitmapfactory.decodefile(image.getabsolutepath())); ; return true; } }; int index = data.getcolumnindex(studentsdbadapter.key_imagepath); //log.d(constants.tag, "" + index); cursoradapter.setviewbinder(viewbinder); viewbinder.setviewvalue(targetimage, data, index); listcontent.setadapter(cursoradapter); } }
updated question, here logcat:
03-17 12:08:30.543: error/androidruntime(30551): fatal exception: main 03-17 12:08:30.543: error/androidruntime(30551): java.lang.runtimeexception: unable resume activity {com.csu.eclassrecord/com.csu.eclassrecord.students_show}: java.lang.nullpointerexception 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread.performresumeactivity(activitythread.java:2899) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread.handleresumeactivity(activitythread.java:2928) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2363) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread.access$600(activitythread.java:156) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread$h.handlemessage(activitythread.java:1340) 03-17 12:08:30.543: error/androidruntime(30551): @ android.os.handler.dispatchmessage(handler.java:99) 03-17 12:08:30.543: error/androidruntime(30551): @ android.os.looper.loop(looper.java:153) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread.main(activitythread.java:5297) 03-17 12:08:30.543: error/androidruntime(30551): @ java.lang.reflect.method.invokenative(native method) 03-17 12:08:30.543: error/androidruntime(30551): @ java.lang.reflect.method.invoke(method.java:511) 03-17 12:08:30.543: error/androidruntime(30551): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) 03-17 12:08:30.543: error/androidruntime(30551): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 03-17 12:08:30.543: error/androidruntime(30551): @ de.robv.android.xposed.xposedbridge.main(xposedbridge.java:132) 03-17 12:08:30.543: error/androidruntime(30551): @ dalvik.system.nativestart.main(native method) 03-17 12:08:30.543: error/androidruntime(30551): caused by: java.lang.nullpointerexception 03-17 12:08:30.543: error/androidruntime(30551): @ com.csu.eclassrecord.students_show$5.setviewvalue(students_show.java:180) 03-17 12:08:30.543: error/androidruntime(30551): @ com.csu.eclassrecord.students_show.populatefields(students_show.java:187) 03-17 12:08:30.543: error/androidruntime(30551): @ com.csu.eclassrecord.students_show.onresume(students_show.java:148) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.instrumentation.callactivityonresume(instrumentation.java:1190) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activity.performresume(activity.java:5200) 03-17 12:08:30.543: error/androidruntime(30551): @ android.app.activitythread.performresumeactivity(activitythread.java:2886)
update
i tried test using following code:
cursor data = studentsdbadapter.queuepic(); if (data.movetofirst()) { cursoradapter = new simplecursoradapter(this, r.layout.stud_row, data, new string[] {studentsdbadapter.key_imagepathid, studentsdbadapter.key_imagepath}, new int[] {r.id.textstud,r.id.stud_list_image}); simplecursoradapter.viewbinder viewbinder = new simplecursoradapter.viewbinder() { public boolean setviewvalue(view view, cursor cursor, int columnindex) { if(view != null && view.getid() != r.id.stud_list_image) { return false; } string username = cursor.getstring(cursor.getcolumnindex(studentsdbadapter.key_imagepathid)); // string path = studentsdbadapter.getimapath("101-00017"); // file image = new file(path); bitmap imagenandroid = bitmapfactory.decoderesource(getresources(),r.drawable.ic_launcher); targetimage.setimagebitmap(imagenandroid); return true; } }; int index = data.getcolumnindex(studentsdbadapter.key_imagepath); //log.d(constants.tag, "" + index); cursoradapter.setviewbinder(viewbinder); viewbinder.setviewvalue(targetimage, data, index); listcontent.setadapter(cu
rsoradapter);
it still give error at
viewbinder.setviewvalue(targetimage, data, index);
replace
((imageview)view).setimagebitmap(bitmapfactory.decodefile(image.getabsolutepath()));
with
targetimage.setimagebitmap(bitmapfactory.decodefile(image.getabsolutepath()));
Comments
Post a Comment