android - illeglStateException:VideoListFragment must be attached to a SherlockFragmentActivity -


i got exception @ runtime.it shows java.lang.illegalstateexception videolistfragment must attached sherlockfragmentactivity.i didn't know how solve these.

below posted codes.

logcat:

08-18 06:00:39.086: e/androidruntime(3068): fatal exception: main 08-18 06:00:39.086: e/androidruntime(3068): process: com.loco.android, pid: 3068 08-18 06:00:39.086: e/androidruntime(3068): java.lang.illegalstateexception: videolistfragment must attached sherlockfragmentactivity. 08-18 06:00:39.086: e/androidruntime(3068):     @ com.actionbarsherlock.app.sherlockfragment.onattach(sherlockfragment.java:25) 08-18 06:00:39.086: e/androidruntime(3068):     @ com.sit.loco.frgment.videolistfragment.onattach(videolistfragment.java:178) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:894) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1115) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1478) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:478) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.view.viewpager.populate(viewpager.java:1068) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.view.viewpager.populate(viewpager.java:914) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1436) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.view.measure(view.java:16497) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:719) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.widget.relativelayout.onmeasure(relativelayout.java:455) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.view.measure(view.java:16497) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.widget.framelayout.onmeasure(framelayout.java:310) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.view.measure(view.java:16497) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) 08-18 06:00:39.086: e/androidruntime(3068):     @ com.android.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:327) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.view.measure(view.java:16497) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.widget.framelayout.onmeasure(framelayout.java:310) 08-18 06:00:39.086: e/androidruntime(3068):     @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2291) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.view.measure(view.java:16497) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1916) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1113) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1295) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1000) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5670) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.choreographer$callbackrecord.run(choreographer.java:761) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.choreographer.docallbacks(choreographer.java:574) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.choreographer.doframe(choreographer.java:544) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.os.handler.handlecallback(handler.java:733) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.os.handler.dispatchmessage(handler.java:95) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.os.looper.loop(looper.java:136) 08-18 06:00:39.086: e/androidruntime(3068):     @ android.app.activitythread.main(activitythread.java:5017) 08-18 06:00:39.086: e/androidruntime(3068):     @ java.lang.reflect.method.invokenative(native method) 08-18 06:00:39.086: e/androidruntime(3068):     @ java.lang.reflect.method.invoke(method.java:515) 08-18 06:00:39.086: e/androidruntime(3068):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 08-18 06:00:39.086: e/androidruntime(3068):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 08-18 06:00:39.086: e/androidruntime(3068):     @ dalvik.system.nativestart.main(native method) 

videolistfragment.java:

  public class videolistfragment extends sherlockfragment {      onvideoselectedlistener mcallback;      boolean loadingmore = false;      // create string variables     string youtube_username = "";  // create object of views     listview list;     progressbar prgloading;     button btnrefresh;     button btnloadmore;      // create variable position, connection status, resources, , channel username     int position;     boolean isconnect = true;     resources res;     string[] channelusername;      // create object of custom adapter     videolistadapter vla;      // create arraylist variables     arraylist<hashmap<string, string>> menuitems;     progressdialog pdialog;      // flag current page     int current_page = 1;     int previous_page;       static final string key_id = "id";     static final string key_title = "title";     static final string key_thumbnail = "thumbnail";     static final string key_duration = "duration";      // create interface listener     public interface onvideoselectedlistener{         public void onvideoselected(string id);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         // todo auto-generated method stub         view v = inflater.inflate(r.layout.fragment_list, container, false);          // connect view objects , view id on xml         list = (listview) v.findviewbyid(r.id.list);         btnrefresh = (button) v.findviewbyid(r.id.btnrefresh);           menuitems = new arraylist<hashmap<string, string>>();          // value passed previous page         bundle bundle = this.getarguments();         position = bundle.getint("position", 0);           // channel username , put selected channel youtube api         res = getactivity().getresources();         channelusername = res.getstringarray(r.array.channel_username);         youtube_username = channelusername[position];            // create loadmore button         btnloadmore = new button(getactivity());         btnloadmore.setbackgroundresource(r.drawable.btn_default_holo_light);         btnloadmore.settext(getstring(r.string.load_more));          // adding load more button lisview @ bottom         list.addfooterview(btnloadmore);          new loadfirstlistview().execute();          // listener handle load more buttton when clicked         btnloadmore.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view arg0) {                 // starting new async task                 isconnect = true;     //            new loadmorelistview().execute();             }         });           // listener handle list when clicked         list.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> arg0, view arg1, int position,                     long arg3) {                 // todo auto-generated method stub                 hashmap<string, string> item = new hashmap<string, string>();                 item = menuitems.get(position);                  mcallback.onvideoselected(item.get("id"));                  list.setitemchecked(position, true);             }         });          // listener handle refresh button when clicked         btnrefresh.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 isconnect = true;                 new loadfirstlistview().execute();             }         });           return v;     }        @override     public void onattach(activity activity) {         super.onattach(activity);  ----> error occurred here          // makes sure container activity has implemented         // callback interface. if not, throws exception.         try {             mcallback = (onvideoselectedlistener) activity;         } catch (classcastexception e) {             throw new classcastexception(activity.tostring()                     + " must implement onheadlineselectedlistener");         }     }    } 

sherlockfrgament.java:

package com.actionbarsherlock.app;  import android.app.activity; import android.support.v4.app.fragment; import com.actionbarsherlock.internal.view.menu.menuitemwrapper; import com.actionbarsherlock.internal.view.menu.menuwrapper; import com.actionbarsherlock.view.menu; import com.actionbarsherlock.view.menuinflater; import com.actionbarsherlock.view.menuitem;  import static android.support.v4.app.watson.oncreateoptionsmenulistener; import static android.support.v4.app.watson.onoptionsitemselectedlistener; import static android.support.v4.app.watson.onprepareoptionsmenulistener;  public class sherlockfragment extends fragment implements oncreateoptionsmenulistener, onprepareoptionsmenulistener, onoptionsitemselectedlistener {     private sherlockfragmentactivity mactivity;      public sherlockfragmentactivity getsherlockactivity() {         return mactivity;     }      @override     public void onattach(activity activity) {         if (!(activity instanceof sherlockfragmentactivity)) {             throw new illegalstateexception(getclass().getsimplename() + " must attached sherlockfragmentactivity."); -->error occurred here         }         mactivity = (sherlockfragmentactivity)activity;          super.onattach(activity);     }      @override     public void ondetach() {         mactivity = null;         super.ondetach();     }      @override     public final void oncreateoptionsmenu(android.view.menu menu, android.view.menuinflater inflater) {         oncreateoptionsmenu(new menuwrapper(menu), mactivity.getsupportmenuinflater());     }      @override     public void oncreateoptionsmenu(menu menu, menuinflater inflater) {         //nothing see here.     }      @override     public final void onprepareoptionsmenu(android.view.menu menu) {         onprepareoptionsmenu(new menuwrapper(menu));     }      @override     public void onprepareoptionsmenu(menu menu) {         //nothing see here.     }      @override     public final boolean onoptionsitemselected(android.view.menuitem item) {         return onoptionsitemselected(new menuitemwrapper(item));     }      @override     public boolean onoptionsitemselected(menuitem item) {         //nothing see here.         return false;     } } 

i didn't know how solve illegalstateexception error.anybody can me this.thank you.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -