android - unsuccessfully trying to get second spinner to get set depending on first spinner -


i'm trying create app calculate different capacity totals based on drive type, raid type , number of drives.

i've been looking @ different examples on here , other sites trying work no avail. no matter try "java.lang.nullpointerexception" when running app. below code have far(am trying test whether spinners dynamically set depending on choice of first spinner before going on):

activity_capacity_calculation.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context=".capacitycalculation" >  <spinner     android:id="@+id/spinnerdrive"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:prompt="@string/drive_selection" />  <spinner     android:id="@+id/spinnercapacity"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:prompt="@string/capacity_selection" />  <spinner     android:id="@+id/spinnerraid"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:prompt="@string/raid_selection" />  <spinner     android:id="@+id/spinnernumber"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:prompt="@string/number_of_drives" />  <button     android:id="@+id/capacity_button"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/capacity_button" />  </linearlayout> 

capcitycalcultaion.java

package com.jrod.storagecalculator;  import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import android.widget.arrayadapter; import android.widget.spinner;  public class capacitycalculation extends activity {      private spinner spinnerdrive, spinnercapacity;      arrayadapter<charsequence> stringarrayadapter = arrayadapter.createfromresource(capacitycalculation.this, r.array.drive_array, android.r.layout.simple_spinner_dropdown_item);     arrayadapter<charsequence> nlsasadapter = arrayadapter.createfromresource(capacitycalculation.this, r.array.nlsas_capacity, android.r.layout.simple_spinner_dropdown_item);     arrayadapter<charsequence> sasadapter = arrayadapter.createfromresource(capacitycalculation.this, r.array.sas_capacity, android.r.layout.simple_spinner_dropdown_item);     arrayadapter<charsequence> ssdadapter = arrayadapter.createfromresource(capacitycalculation.this, r.array.ssd_capacity, android.r.layout.simple_spinner_dropdown_item);      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_capacity_calculation);         setupactionbar();               spinnerdrive = (spinner) findviewbyid(r.id.spinnerdrive);             spinnerdrive.setadapter(stringarrayadapter);             spinnerdrive.setonitemselectedlistener(new onitemselectedlistener() {              public void onitemselected(adapterview<?> parent, view view, int position, long id) {                  string check = (string) parent.getitematposition(position);                      if (check.startswith("nl-sas")) {                     spinnercapacity.setadapter(nlsasadapter);                     }else if (check.startswith("sas")) {                     spinnercapacity.setadapter(sasadapter);                     }else if (check.startswith("ssd")) {                     spinnercapacity.setadapter(ssdadapter);                     }                 }                   public void onnothingselected(adapterview<?> parent){                  }             });      private void setupactionbar() {         getactionbar().setdisplayhomeasupenabled(true);     } } 

and logcat output:

03-10 15:07:23.155: e/androidruntime(29319): fatal exception: main 03-10 15:07:23.155: e/androidruntime(29319): process: com.jrod.storagecalculator, pid: 29319 03-10 15:07:23.155: e/androidruntime(29319): java.lang.runtimeexception: unable instantiate activity componentinfo{com.jrod.storagecalculator/com.jrod.storagecalculator.capacitycalculation}: java.lang.nullpointerexception 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2131) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2265) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.activitythread.access$800(activitythread.java:145) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.activitythread$h.handlemessage(activitythread.java:1206) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.os.handler.dispatchmessage(handler.java:102) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.os.looper.loop(looper.java:136) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.activitythread.main(activitythread.java:5081) 03-10 15:07:23.155: e/androidruntime(29319):    @ java.lang.reflect.method.invokenative(native method) 03-10 15:07:23.155: e/androidruntime(29319):    @ java.lang.reflect.method.invoke(method.java:515) 03-10 15:07:23.155: e/androidruntime(29319):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:783) 03-10 15:07:23.155: e/androidruntime(29319):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:599) 03-10 15:07:23.155: e/androidruntime(29319):    @ dalvik.system.nativestart.main(native method) 03-10 15:07:23.155: e/androidruntime(29319): caused by: java.lang.nullpointerexception 03-10 15:07:23.155: e/androidruntime(29319):    @ android.content.contextwrapper.getresources(contextwrapper.java:89) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.view.contextthemewrapper.getresources(contextthemewrapper.java:78) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.widget.arrayadapter.createfromresource(arrayadapter.java:430) 03-10 15:07:23.155: e/androidruntime(29319):    @ com.jrod.storagecalculator.capacitycalculation.<init>(capacitycalculation.java:15) 03-10 15:07:23.155: e/androidruntime(29319):    @ java.lang.class.newinstanceimpl(native method) 03-10 15:07:23.155: e/androidruntime(29319):    @ java.lang.class.newinstance(class.java:1208) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.instrumentation.newactivity(instrumentation.java:1061) 03-10 15:07:23.155: e/androidruntime(29319):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2122) 03-10 15:07:23.155: e/androidruntime(29319):    ... 11 more 

you have add line:

spinnercapacity = (spinner) findviewbyid(r.id.spinnercapacity); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -