微调器在平板电脑上显示空值,但在手机上运行正常

时间:2012-05-18 11:50:11

标签: android android-spinner

selectQType一个简单的微调器。这些值将从数据库填充,它们很好。

     ArrayAdapter<String> spinnerArrayAdapter1 = 
            new ArrayAdapter<String>(SpotlighterBasicActivity.this,
                    android.R.layout.simple_spinner_item, spinnerQTypeList);
     spinnerArrayAdapter1.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item); 
     Spinner selectQType=(Spinner) findViewById(R.id.spinnerInputQType);

     selectQType.setPrompt("QType");// logcat points warning on this line.
     selectQType.setAdapter(spinnerArrayAdapter1);
     selectQType.setSelection(QTypeIndex);
     selectQType.setOnItemSelectedListener(new OnItemSelectedListener() {
     ...
     }

这是我获得的平板电脑输出:

Output on tablet

奇怪的是,它对于移动类别的模拟器和设备工作得非常好,但是对 tablet 类别的模拟器和设备发出警告。

以下是logcat详细信息:

05-18 16:47:29.284: E/SpotlighterBasicActivity(481): QTypeIndex=0
05-18 16:47:29.284: E/SpotlighterBasicActivity(481): spinnerArrayList[1]=Type 1, spinnerQTypeID=5853, defaultQType=6307
05-18 16:47:29.294: E/SpotlighterBasicActivity(481): spinnerArrayList[2]=Type 2, spinnerQTypeID=6308, defaultQType=6307
05-18 16:47:29.304: W/System.err(481): java.lang.NullPointerException
05-18 16:47:29.304: W/System.err(481):  at in.varit.spotlighter.basic.SpotlighterBasicActivity.loadQTypeSpinners(SpotlighterBasicActivity.java:334)
05-18 16:47:29.304: W/System.err(481):  at in.varit.spotlighter.basic.SpotlighterBasicActivity.onCreate(SpotlighterBasicActivity.java:203)
05-18 16:47:29.304: W/System.err(481):  at android.app.Activity.performCreate(Activity.java:4397)
05-18 16:47:29.304: W/System.err(481):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
05-18 16:47:29.313: W/System.err(481):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
05-18 16:47:29.313: W/System.err(481):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
05-18 16:47:29.313: W/System.err(481):  at android.app.ActivityThread.access$500(ActivityThread.java:122)
05-18 16:47:29.313: W/System.err(481):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
05-18 16:47:29.325: W/System.err(481):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 16:47:29.325: W/System.err(481):  at android.os.Looper.loop(Looper.java:132)
05-18 16:47:29.325: W/System.err(481):  at android.app.ActivityThread.main(ActivityThread.java:4123)
05-18 16:47:29.325: W/System.err(481):  at java.lang.reflect.Method.invokeNative(Native Method)
05-18 16:47:29.325: W/System.err(481):  at java.lang.reflect.Method.invoke(Method.java:491)
05-18 16:47:29.334: W/System.err(481):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
05-18 16:47:29.334: W/System.err(481):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
05-18 16:47:29.334: W/System.err(481):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

selectQType is null

使用if(null!=selectQType)

进行检查

并检查selectQType的id是否正确于layout.xml?