if (dyn_List_ID[i]==null){ String[] form_IDs = db.getEntireColumn(List_table_name[i],"form_label_ID"); String[] spinnerArray = new String[form_IDs.length]; for (int k=0;k<form_IDs.length;k++){ spinnerArray[k] = db.getFromLanguagetable(language_short_name,List_table_name[i],form_IDs[k]); System.out.println("Spinner Array "+spinnerArray[k]); } product_spinner[i] = new Spinner(vIEwToload.getContext()); //First Spinner product_spinner[i].setLayoutParams(lp_spinner); product_spinner[i].setBackgroundResource(R.drawable.spinner_selector); ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(vIEwToload.getContext(),com.Orange.R.layout.my_spinner_textvIEw,spinnerArray); spinnerArrayAdapter.setDropDownVIEwResource(R.layout.multiline_spinner_dropdown_item); product_spinner[i].setAdapter(spinnerArrayAdapter); this.SpinnerFIElds.add(product_spinner[i]); linear_layout[i].addVIEw(product_spinner[i]); tablerow_product[i].addVIEw(linear_layout[i]); themes_tableLayout.addVIEw(tablerow_product[i],new tableLayout.LayoutParams(tableRow.LayoutParams.FILL_PARENT,tableRow.LayoutParams.WRAP_CONTENT)); } else { String[] spinnerA = new String[item_visible]; int cont=0; for (int p=0;p<status_itemList.length;p++){ if (status_itemList[p].trim().equals("1")){ spinnerA[cont]=db.getFromLanguagetable(language_short_name,"pr_dyn_List_option",form_label_ID_itemList[p]); System.out.println("Spinner dinamic array "+spinnerA[cont]); cont++; } } product_spinner[i] = new Spinner(vIEwToload.getContext()); //second Spinner product_spinner[i].setLayoutParams(lp_spinner); product_spinner[i].setBackgroundResource(R.drawable.spinner_selector); ArrayAdapter spinnerAdapter = new ArrayAdapter(vIEwToload.getContext(),spinnerA); spinnerAdapter.setDropDownVIEwResource(com.Orange.R.layout.multiline_spinner_dropdown_item); product_spinner[i].setAdapter(spinnerAdapter); this.SpinnerFIElds.add(product_spinner[i]); linear_layout[i].addVIEw(product_spinner[i]); tablerow_product[i].addVIEw(linear_layout[i]); themes_tableLayout.addVIEw(tablerow_product[i],tableRow.LayoutParams.WRAP_CONTENT)); }
它在屏幕上看起来很好但是当我点击它时我得到这个错误:
15:53:22.040 8716 com.Orange ERROR AndroIDRuntime java.lang.NullPointerException15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.ArrayAdapter.createVIEwFromresource(ArrayAdapter.java:355)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.ArrayAdapter.getDropDownVIEw(ArrayAdapter.java:376)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.Spinner$DropDownAdapter.getDropDownVIEw(Spinner.java:329)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.Spinner$DropDownAdapter.getVIEw(Spinner.java:325)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.AbsListVIEw.obtainVIEw(AbsListVIEw.java:1294)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.ListVIEw.measureHeightOfChildren(ListVIEw.java:1198)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.ListVIEw.onMeasure(ListVIEw.java:1109)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.vIEw.VIEw.measure(VIEw.java:8171)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3132)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1012)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.linearLayout.measureVertical(linearLayout.java:381)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.linearLayout.onMeasure(linearLayout.java:304)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at com.androID.internal.Widget.WeightedlinearLayout.onMeasure(WeightedlinearLayout.java:60)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:245)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.vIEw.VIEwRoot.performTraversals(VIEwRoot.java:801)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.vIEw.VIEwRoot.handleMessage(VIEwRoot.java:1727)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.os.Handler.dispatchMessage(Handler.java:99)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.os.Looper.loop(Looper.java:123)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at androID.app.ActivityThread.main(ActivityThread.java:4627)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at java.lang.reflect.Method.invokeNative(Native Method)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at java.lang.reflect.Method.invoke(Method.java:521)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)15:53:22.040 8716 com.Orange ERROR AndroIDRuntime at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:626)
第一个Spinner添加工作正常,但对于第二个Spinner,我得到了这个错误.
我不知道为什么我在Adapterarray.createVIEwFromresources上得到一个nullpointer,因为我不使用这个方法.我的错误在哪里?
确保spinnerA中没有空值(我认为这是第二个Spinner的数据(!??!)).
总结以上是内存溢出为你收集整理的android – Spinner:ArrayAdapter.createViewFromResource中的NullPointerException全部内容,希望文章能够帮你解决android – Spinner:ArrayAdapter.createViewFromResource中的NullPointerException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)