android support v7 appcompat showing exception in android 2.3v device but works perfectly in 4.2 device -


hello working android navigation drawer minsdkversion 8 17. in program using action bar component work navigation drawer. whenever run program in 4.1v android device run when try run same program in 2.3v android device showing exception. here detailed snippet.

mainactivity.java

@targetapi(build.version_codes.honeycomb) public class mainactivity extends actionbaractivity{      private drawerlayout mdrawerlayout;     private listview mdrawerlist;     private actionbardrawertoggle mdrawertoggle;      private charsequence mdrawertitle;     private charsequence mtitle;     private string[] meventoptions;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          mtitle = mdrawertitle = "event option";//gettitle();         meventoptions = getresources().getstringarray(r.array.event_options);         mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout);         mdrawerlist = (listview) findviewbyid(r.id.left_drawer);          // set custom shadow overlays main content when drawer opens         mdrawerlayout.setdrawershadow(r.drawable.drawer_shadow, gravitycompat.start);         // set drawer's list view items , click listener         mdrawerlist.setadapter(new arrayadapter<string>(this,                 r.layout.drawer_list_item, meventoptions));         mdrawerlist.setonitemclicklistener(new draweritemclicklistener());          // enable actionbar app icon behave action toggle nav drawer         getsupportactionbar().setdisplayhomeasupenabled(true);         getsupportactionbar().sethomebuttonenabled(true);          // actionbardrawertoggle ties the proper interactions         // between sliding drawer , action bar app icon         mdrawertoggle = new actionbardrawertoggle(                 this,                  /* host activity */                 mdrawerlayout,         /* drawerlayout object */                 r.drawable.ic_drawer,  /* nav drawer image replace 'up' caret */                 r.string.drawer_open,  /* "open drawer" description accessibility */                 r.string.drawer_close  /* "close drawer" description accessibility */                 ) {             public void ondrawerclosed(view view) {                 getsupportactionbar().settitle(mtitle);                 supportinvalidateoptionsmenu(); // creates call onprepareoptionsmenu()             }              public void ondraweropened(view drawerview) {                 getsupportactionbar().settitle(mdrawertitle);                 supportinvalidateoptionsmenu(); // creates call onprepareoptionsmenu()             }         };         mdrawerlayout.setdrawerlistener(mdrawertoggle);          if (savedinstancestate == null) {             selectitem(0);         }     }      @override     public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.main, menu);         return super.oncreateoptionsmenu(menu);     }      /* called whenever call invalidateoptionsmenu() */     @override     public boolean onprepareoptionsmenu(menu menu) {         // if nav drawer open, hide action items related content view         //boolean draweropen = mdrawerlayout.isdraweropen(mdrawerlist);         menu.finditem(r.id.action_websearch).setvisible(false);/*!draweropen*/         return super.onprepareoptionsmenu(menu);     }      @override     public boolean onoptionsitemselected(menuitem item) {         // action bar home/up action should open or close drawer.         // actionbardrawertoggle take care of this.         if (mdrawertoggle.onoptionsitemselected(item)) {             return true;         }         // handle action buttons         switch(item.getitemid()) {          default:             return super.onoptionsitemselected(item);         }     }      /* click listner listview in navigation drawer */     private class draweritemclicklistener implements listview.onitemclicklistener {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             selectitem(position);         }     }      private void selectitem(int position) {          // update selected item , title, close drawer          switch (position) {          case 0:              getfragmentmanager().begintransaction()             .replace(r.id.content_frame, new mainactivityfragment2())             .commit();             break;          case 1:              getfragmentmanager().begintransaction()             .replace(r.id.content_frame, new mainactivityfragment2())             .commit();             break;          case 2:              getfragmentmanager().begintransaction()             .replace(r.id.content_frame, new mainactivityfragment2())             .commit();             break;          case 3:              getfragmentmanager().begintransaction()             .replace(r.id.content_frame, new mainactivityfragment2())             .commit();             break;          }         mdrawerlist.setitemchecked(position, true);         settitle(meventoptions[position]);         mdrawerlayout.closedrawer(mdrawerlist);     }      @override     public void settitle(charsequence title) {         mtitle = title;         getsupportactionbar().settitle(mtitle);     }      /**      * when using actionbardrawertoggle, must call during      * onpostcreate() , onconfigurationchanged()...      */      @override     protected void onpostcreate(bundle savedinstancestate) {         super.onpostcreate(savedinstancestate);         // sync toggle state after onrestoreinstancestate has occurred.         mdrawertoggle.syncstate();     }      @override     public void onconfigurationchanged(configuration newconfig) {         super.onconfigurationchanged(newconfig);         // pass configuration change drawer toggls         mdrawertoggle.onconfigurationchanged(newconfig);     }  } 

catlog:

10-07 02:06:29.338: e/androidruntime(387): fatal exception: main 10-07 02:06:29.338: e/androidruntime(387): java.lang.nosuchmethoderror: in.wptrafficanalyzer.actionbarcompatdemo.mainactivity.getfragmentmanager 10-07 02:06:29.338: e/androidruntime(387):  @ in.wptrafficanalyzer.actionbarcompatdemo.mainactivity.selectitem(mainactivity.java:144) 10-07 02:06:29.338: e/androidruntime(387):  @ in.wptrafficanalyzer.actionbarcompatdemo.mainactivity.oncreate(mainactivity.java:74) 10-07 02:06:29.338: e/androidruntime(387):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 10-07 02:06:29.338: e/androidruntime(387):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1611) 10-07 02:06:29.338: e/androidruntime(387):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 10-07 02:06:29.338: e/androidruntime(387):  @ android.app.activitythread.access$1500(activitythread.java:117) 10-07 02:06:29.338: e/androidruntime(387):  @ android.app.activitythread$h.handlemessage(activitythread.java:931) 10-07 02:06:29.338: e/androidruntime(387):  @ android.os.handler.dispatchmessage(handler.java:99) 10-07 02:06:29.338: e/androidruntime(387):  @ android.os.looper.loop(looper.java:130) 10-07 02:06:29.338: e/androidruntime(387):  @ android.app.activitythread.main(activitythread.java:3683) 10-07 02:06:29.338: e/androidruntime(387):  @ java.lang.reflect.method.invokenative(native method) 10-07 02:06:29.338: e/androidruntime(387):  @ java.lang.reflect.method.invoke(method.java:507) 10-07 02:06:29.338: e/androidruntime(387):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 10-07 02:06:29.338: e/androidruntime(387):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 10-07 02:06:29.338: e/androidruntime(387):  @ dalvik.system.nativestart.main(native method) 

androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="in.wptrafficanalyzer.actionbarcompatdemo"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/theme.appcompat" >         <activity             android:name="in.wptrafficanalyzer.actionbarcompatdemo.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>          <activity             android:name=".mainactivity$planetfragment"             android:label="@string/app_name" >         </activity>     </application>  </manifest>  

activity_main.xml

<!-- drawerlayout intended used top-level content view using match_parent both width , height consume full space available. --> <android.support.v4.widget.drawerlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent">      <!-- main content view, view below consumes entire          space available using match_parent in both dimensions. -->     <framelayout         android:id="@+id/content_frame"         android:layout_width="match_parent"         android:layout_height="match_parent" />      <!-- android:layout_gravity="start" tells drawerlayout treat          sliding drawer on left side left-to-right          languages , on right side right-to-left languages.          drawer given fixed width in dp , extends full height of          container. solid background used contrast          content view. -->     <listview         android:id="@+id/left_drawer"         android:layout_width="240dp"         android:layout_height="match_parent"         android:layout_gravity="start"         android:choicemode="singlechoice"         android:divider="@android:color/transparent"         android:dividerheight="0dp"         android:background="#111"/> </android.support.v4.widget.drawerlayout> 

replace occurrences of getfragmentmanager getsupportfragmentmanager. might need replace other parts of app accordingly.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -