我的工作中,我一直在使用ormlite後,我想在微調顯示這些信息,以從服務器獲取一些信息,將它們保存在數據庫中的項目,從數據庫機器人填補了微調
所以從數據庫到微調得到的信息我稱這種方法:
public Dao<ServiceProviderCompanies, Integer> getTowServiceProviderCompaniesDao() {
if (null == towServiceProviderCompaniesDao) {
try {
towServiceProviderCompaniesDao = getDao(ServiceProviderCompanies.class);
} catch (java.sql.SQLException e) {
e.printStackTrace();
}
}
return towServiceProviderCompaniesDao;
}
我把它叫做在我的活動是這樣的:
String[] ServicePCompanies;
try {List<ServiceProviderCompanies> mSerProCom=towManager.getTowServiceProviderCompaniesDao().queryForAll();
ServicePCompanies=new String[mSerProCom.size()];
for(int i=1;i<mSerProCom.size();i++){
ServicePCompanies[i]=mSerProCom.get(i)._serviceRequesterServiceProviderCompany;
}
//CompaniesForSpinner=towManager.getTowServiceProviderCompaniesDao().queryForAll().toString();
} catch (SQLException e) {
e.printStackTrace();
}
,我充滿了我的SP內使用的代碼
Spinner entrAssistanceList=(Spinner)findViewById(R.id.SpNomEntrAssis);
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item,ServicePCompanies);
spinnerArrayAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
entrAssistanceList.setAdapter(spinnerArrayAdapter);
這些行當我這樣做,所以我得到這個錯誤:
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:194)
at android.widget.Spinner.onMeasure(Spinner.java:454)
at android.view.View.measure(View.java:15811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4952)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1427)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:714)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:604)
at android.view.View.measure(View.java:15811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4952)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1427)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:714)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:604)
at android.view.View.measure(View.java:15811)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1228)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:326)
at android.widget.ScrollView.onMeasure(ScrollView.java:321)
at android.view.View.measure(View.java:15811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4952)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1427)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:714)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:604)
at android.view.View.measure(View.java:15811)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:15811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4952)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:326)
at android.view.View.measure(View.java:15811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4952)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1427)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:714)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:604)
at android.view.View.measure(View.java:15811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4952)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:326)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2209)
at android.view.View.measure(View.java:15811)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2232)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1310)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1505)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4962)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
at android.view.Choreographer.doCallbacks(Choreographer.java:579)
at android.view.Choreographer.doFrame(Choreographer.java:548)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5449)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
知道我tryed與我手動創建的陣列以填充微調:
ServicePCompaniesArray=new String[]{"Entreprise1","Entreprise2","Entreprise3"};
和我沒有得到錯誤,所以我認爲問題是當我從數據庫中獲取信息,knwoing,我調試它,我給適配器的字符串數組充滿了信息n表示我從數據庫中獲取,所以我真的不知道在哪裏的NullPointerException來自
謝謝你們,
謝謝,你解決了我的錯誤 – 2015-03-25 09:33:28