java - How do I create custom classes as subroutines -


i may have terms mixed up, i'm creating android app , want encapsulate of routine functions. instance actionbar. @ first had code on activities , if change 1 thing have change else where. want create navigationactionbarmanager.java file handle inital setup, onnavigationlistener, setlistnavigationcallbacks, etc.

here's class far:

import android.app.actionbar; import android.app.actionbar.onnavigationlistener; import android.app.activity; import android.content.intent; import android.view.menu; import android.widget.arrayadapter; import android.widget.spinneradapter;  public class navigationactionbarmanager extends activity {      public actionbar actionbar = getactionbar();    // actionbar object      // method: display     public void display() {         actionbar.setdisplayshowtitleenabled(false);         actionbar.setdisplayhomeasupenabled(true);         actionbar.setnavigationmode(actionbar.navigation_mode_list);     }      // method: inflate     public void inflate(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.activity_adventurers_new, menu);     }      // method: listen     public void listen() {         spinneradapter mspinneradapter = arrayadapter.createfromresource(this, r.array.array_character_views, android.r.layout.simple_spinner_dropdown_item);          onnavigationlistener monnavigationlistener = new onnavigationlistener() {             //string[] strings = getresources().getstringarray(r.array.array_character_views);              @override             public boolean onnavigationitemselected(int position, long itemid) {                 intent nextscreen = null;                 switch(position) {                 case 0:                     break;                 case 1:                     nextscreen = new intent(getapplicationcontext(), adventurersnewabilitiesactivity.class);                     break;                 case 2:                     break;                 }                  if(nextscreen != null) {                     startactivity(nextscreen);                 }                  return false;             }         };          actionbar.setlistnavigationcallbacks(mspinneradapter, monnavigationlistener);     }  } 

back in activity class, want apply such:

public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_adventurer_new_character);      navbar.display();     navbar.listen();  } 

i'm running error , don't understand logcat's output. here's logcat ouput:

04-17 23:12:01.110: e/androidruntime(14013): fatal exception: main 04-17 23:12:01.110: e/androidruntime(14013): java.lang.runtimeexception: unable instantiate activity componentinfo{com.app/com.app.adventurersnewcharacteractivity}: java.lang.nullpointerexception 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activitythread.performlaunchactivity(activitythread.java:1903) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2004) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activitythread.access$600(activitythread.java:132) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activitythread$h.handlemessage(activitythread.java:1157) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.os.handler.dispatchmessage(handler.java:99) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.os.looper.loop(looper.java:137) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activitythread.main(activitythread.java:4580) 04-17 23:12:01.110: e/androidruntime(14013):    @ java.lang.reflect.method.invokenative(native method) 04-17 23:12:01.110: e/androidruntime(14013):    @ java.lang.reflect.method.invoke(method.java:511) 04-17 23:12:01.110: e/androidruntime(14013):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:791) 04-17 23:12:01.110: e/androidruntime(14013):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:558) 04-17 23:12:01.110: e/androidruntime(14013):    @ dalvik.system.nativestart.main(native method) 04-17 23:12:01.110: e/androidruntime(14013): caused by: java.lang.nullpointerexception 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activity.initactionbar(activity.java:2071) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activity.getactionbar(activity.java:2058) 04-17 23:12:01.110: e/androidruntime(14013):    @ com.app.navigationactionbarmanager.<init>(navigationactionbarmanager.java:13) 04-17 23:12:01.110: e/androidruntime(14013):    @ com.app.adventurersnewcharacteractivity.<init>(adventurersnewcharacteractivity.java:13) 04-17 23:12:01.110: e/androidruntime(14013):    @ java.lang.class.newinstanceimpl(native method) 04-17 23:12:01.110: e/androidruntime(14013):    @ java.lang.class.newinstance(class.java:1319) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.instrumentation.newactivity(instrumentation.java:1025) 04-17 23:12:01.110: e/androidruntime(14013):    @ android.app.activitythread.performlaunchactivity(activitythread.java:1894) 04-17 23:12:01.110: e/androidruntime(14013):    ... 11 more 

have implemented oncreateoptionsmenu() method in activity?

doc available @ https://developer.android.com/guide/topics/ui/actionbar.html


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -