android - Application crash during createVideoThumbnail -
currently i'm using listview
create file explorer video thumbnail. app crash when createvideothumbnail
, after removing code app works fine. below snippet of part createvideothumbnail
.
for (int = 0; < files.length; i++) { file file = files[i]; if (!file.ishidden() && file.canread()) { path.add(file.getpath()); if (file.isdirectory()) { item.add(file.getname() + "/"); } else { item.add(file.getname()); bitmap bmap = thumbnailutils.createvideothumbnail(file.getpath(), mediastore.video.thumbnails.micro_kind); rowimage.setimagebitmap(bmap); } } }
below whole class source code
public class video extends listactivity { list<string> item = null; list<string> path = null; string root; textview mypath; int visibility; string videopath; listview list; videoview videoview; view v; file f; button home; button exit; imageview rowimage; mediacontroller mcontroller; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.video_layout); mypath = (textview) findviewbyid(r.id.path); videoview = (videoview) findviewbyid(r.id.videoview); list = (listview) findviewbyid(android.r.id.list); home = (button) findviewbyid(r.id.home); exit = (button) findviewbyid(r.id.exit); rowimage = (imageview) findviewbyid(r.id.rowimage); root = environment.getexternalstoragedirectory().getpath(); getdir(root); home.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { getdir(root); } }); exit.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { finish(); } }); } void getdir(string dirpath) { mypath.settext("location: " + dirpath); item = new arraylist<string>(); path = new arraylist<string>(); f = new file(dirpath); file[] files = f.listfiles(); if (!dirpath.equals(root)) { item.add("/back"); path.add(f.getparent()); } (int = 0; < files.length; i++) { file file = files[i]; if (!file.ishidden() && file.canread()) { path.add(file.getpath()); if (file.isdirectory()) { item.add(file.getname() + "/"); } else { item.add(file.getname()); bitmap bmap = thumbnailutils.createvideothumbnail(file.getpath(), mediastore.video.thumbnails.micro_kind); rowimage.setimagebitmap(bmap); } } } arrayadapter<string> filelist = new arrayadapter<string>(this, r.layout.row, r.id.rowtext, item); collections.sort(path); collections.sort(item); setlistadapter(filelist); } @override protected void onlistitemclick(listview l, view v, int position, long id) { file file = new file(path.get(position)); if (file.isdirectory()) { if (file.canread()) { getdir(path.get(position)); } else { new alertdialog.builder(this).seticon(r.drawable.ic_launcher) .settitle("[" + file.getname() + "] folder can't read!") .setpositivebutton("ok", null).show(); } } else { if (visibility == 0) { videoview.setvisibility(view.visible); visibility = 1; videopath = file.getpath(); uri uri = uri.parse(videopath); videoview.setvideouri(uri); list.setvisibility(view.invisible); mcontroller = new mediacontroller(this); videoview.setmediacontroller(mcontroller); videoview.start(); toast.maketext(getapplicationcontext(), file.getabsolutepath(), toast.length_long).show(); intent intent = getintent(); string intentaction = intent.getaction(); if (!textutils.isempty(intentaction) && intentaction.equals(intent.action_view)) { videopath = intent.getdatastring(); } } else if (visibility == 1) { videoview.setvisibility(view.invisible); list.setvisibility(view.visible); visibility = 0; videoview.stopplayback(); } } } public void onbackpressed() { if (visibility == 1) { videoview.setvisibility(view.invisible); list.setvisibility(view.visible); videoview.stopplayback(); visibility = 0; } else if (f.getpath().equals(root)) { finish(); } else { getdir(f.getparent()); } } }
below logcat
12-16 18:28:18.449: d/surfaceview(7333): context in surfaceview init 12-16 18:28:21.959: d/androidruntime(7333): shutting down vm 12-16 18:28:21.959: w/dalvikvm(7333): threadid=1: thread exiting uncaught exception (group=0x412a8930) 12-16 18:28:21.969: e/androidruntime(7333): fatal exception: main 12-16 18:28:21.969: e/androidruntime(7333): java.lang.nullpointerexception 12-16 18:28:21.969: e/androidruntime(7333): @ com.myapp.mycarousel.video.getdir(video.java:135) 12-16 18:28:21.969: e/androidruntime(7333): @ com.myapp.mycarousel.video.onlistitemclick(video.java:188) 12-16 18:28:21.969: e/androidruntime(7333): @ android.app.listactivity$2.onitemclick(listactivity.java:319) 12-16 18:28:21.969: e/androidruntime(7333): @ android.widget.adapterview.performitemclick(adapterview.java:298) 12-16 18:28:21.969: e/androidruntime(7333): @ android.widget.abslistview.performitemclick(abslistview.java:1100) 12-16 18:28:21.969: e/androidruntime(7333): @ android.widget.abslistview.onkeyup(abslistview.java:2890) 12-16 18:28:21.969: e/androidruntime(7333): @ android.widget.listview.commonkey(listview.java:2258) 12-16 18:28:21.969: e/androidruntime(7333): @ android.widget.listview.onkeyup(listview.java:2113) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.keyevent.dispatch(keyevent.java:2865) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.view.dispatchkeyevent(view.java:7205) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewgroup.dispatchkeyevent(viewgroup.java:1354) 12-16 18:28:21.969: e/androidruntime(7333): @ android.widget.listview.dispatchkeyevent(listview.java:2088) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewgroup.dispatchkeyevent(viewgroup.java:1359) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewgroup.dispatchkeyevent(viewgroup.java:1359) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewgroup.dispatchkeyevent(viewgroup.java:1359) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewgroup.dispatchkeyevent(viewgroup.java:1359) 12-16 18:28:21.969: e/androidruntime(7333): @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchkeyevent(phonewindow.java:1920) 12-16 18:28:21.969: e/androidruntime(7333): @ com.android.internal.policy.impl.phonewindow.superdispatchkeyevent(phonewindow.java:1395) 12-16 18:28:21.969: e/androidruntime(7333): @ android.app.activity.dispatchkeyevent(activity.java:2394) 12-16 18:28:21.969: e/androidruntime(7333): @ com.android.internal.policy.impl.phonewindow$decorview.dispatchkeyevent(phonewindow.java:1847) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewrootimpl.deliverkeyeventpostime(viewrootimpl.java:3703) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewrootimpl.handleimefinishedevent(viewrootimpl.java:3653) 12-16 18:28:21.969: e/androidruntime(7333): @ android.view.viewrootimpl$viewroothandler.handlemessage(viewrootimpl.java:2820) 12-16 18:28:21.969: e/androidruntime(7333): @ android.os.handler.dispatchmessage(handler.java:99) 12-16 18:28:21.969: e/androidruntime(7333): @ android.os.looper.loop(looper.java:137) 12-16 18:28:21.969: e/androidruntime(7333): @ android.app.activitythread.main(activitythread.java:5041) 12-16 18:28:21.969: e/androidruntime(7333): @ java.lang.reflect.method.invokenative(native method) 12-16 18:28:21.969: e/androidruntime(7333): @ java.lang.reflect.method.invoke(method.java:511) 12-16 18:28:21.969: e/androidruntime(7333): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 12-16 18:28:21.969: e/androidruntime(7333): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 12-16 18:28:21.969: e/androidruntime(7333): @ dalvik.system.nativestart.main(native method)
anyone has idea? thank you!
Comments
Post a Comment