我有Spinner
需要提供ID和说明地址。
private Spinner spnBairroPesquisa;
spnBairroPesquisa=(Spinner) findViewById(R.id.spnBairroPesquisa);
我正在寻找有关该方法的信息:
listaBairro = bairroDAO.listaBairroPesquisa(this,bairroPOJO);
并提供对象listaBairro
的列表BairroPOJO
以下方法提供对象列表:
public List<BairroPOJO> listaBairroPesquisa(Context context, BairroPOJO bairro){
List<BairroPOJO> listaBairro = new ArrayList<BairroPOJO>();
try {
conn = dataBase.getReadableDatabase();
String query = "select * from "+bairro.TABELA+
" where "+bairro.IDCLIENTE+"="+bairro.getIdcliente()+
" and "+bairro.IDPESQUISA+"="+bairro.getIdpesquisa()+
" and "+bairro.CPFOPERADOR+"="+bairro.getCpfoperador();
Cursor cursor = conn.rawQuery(query, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
cursor.moveToFirst();
do {
bairroPOJO = new BairroPOJO();
bairroPOJO.setIdbairro(cursor.getInt(cursor.getColumnIndex(bairroPOJO.IDBAIRRO)));
bairroPOJO.setDescricaoBairro(cursor.getString(cursor.getColumnIndex(bairroPOJO.DESCRICAOBAIRRO)));
bairroPOJO.setCodigoBairro(cursor.getString(cursor.getColumnIndex(bairroPOJO.CODIGOBAIRRO)));
bairroPOJO.setIdcliente(cursor.getInt(cursor.getColumnIndex(bairroPOJO.IDCLIENTE)));
bairroPOJO.setIdpesquisa(cursor.getInt(cursor.getColumnIndex(bairroPOJO.IDPESQUISA)));
bairroPOJO.setCpfoperador(cursor.getString(cursor.getColumnIndex(bairroPOJO.CPFOPERADOR)));
listaBairro.add(bairroPOJO);
} while (cursor.moveToNext());
}
}
conn.close();
}catch (Exception ex){
}
return listaBairro;
}
创建步骤列表和布局以提供ArrayAdapter
adpBairro:
adpBairro = new ArrayAdapter<BairroPOJO>(this, R.layout.list_adp_bairropesquisa,listaBairro);
adpBairro.setDropDownViewResource(R.layout.bairro_item_spinner);
但是当我在Spinner
中填充数据适配器时出现NullPointException
错误:
spnBairroPesquisa.setAdapter(adpBairro);
请帮我解决这个问题。
更新,关注我的logcat:
08-27 21:09:37.101 1293-1293/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.wgti.wgadvisor/br.com.wgti.wgadvisor.UI.actFormularioUI}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at br.com.wgti.wgadvisor.UI.actFormularioUI.alimentaSpinnerBairro(actFormularioUI.java:1016)
at br.com.wgti.wgadvisor.UI.actFormularioUI.onCreate(actFormularioUI.java:226)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)