spinner值不在android中显示

时间:2014-10-31 10:33:32

标签: php android

嗨在这段代码中,前两个值显示数据,第三个字符串数组给出空指针Exception但数据来自database.can任何一个请帮助我。

此值仅显示NullPointerException

patient_main_type_name[i] = JA.getJSONObject(i).getString("patient_main_type_name");
patient_type_name[i] = JA.getJSONObject(i).getString("patient_type_name");
religion_name[i] = JA.getJSONObject(i).getString("religion_name");
caste_name[i] = JA.getJSONObject(i).getString("caste_name");

类文件

String result = DatabaseUtility.executeQueryPhp("getpatient","");
System.out.print(result);

try
{
    JSONArray JA = new JSONArray(result);

    initial_name = new String[JA.length()];
    initial_id = new String[JA.length()];
    patient_main_type_name = new String[JA.length()];
    patient_type_name = new String[JA.length()];
    religion_name= new String[JA.length()];
    caste_name= new String[JA.length()];

    for(int i=0;i<JA.length();i++)
    {
        initial_name[i] = JA.getJSONObject(i).getString("initial_name");
        initial_id[i] = JA.getJSONObject(i).getString("initial_id");
        patient_main_type_name[i] = JA.getJSONObject(i).getString("patient_main_type_name");
        patient_type_name[i] = JA.getJSONObject(i).getString("patient_type_name");
        religion_name[i] = JA.getJSONObject(i).getString("religion_name");
        caste_name[i] = JA.getJSONObject(i).getString("caste_name");
    }

    spinner_fn();  
} catch(Exception e) {
    Log.e("Fail 3", e.toString());
}
private void spinner_fn() {

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_spinner_item,
                initial_name);
        dataAdapter
        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        intial.setAdapter(dataAdapter);

        intial.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int position, long id) {

                Log.e("Position new", initial_name[position]);



            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }

        });
        ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_spinner_item,
                patient_main_type_name);
        dataAdapter1
        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        pmaincat.setAdapter(dataAdapter1);

        pmaincat.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int position, long id) {

                Log.e("Position new", patient_main_type_name[position]);



            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }

        });

logcat的

10-31 10:08:23.045: E/Fail 3(7235): java.lang.NullPointerException: storage == null
10-31 10:08:23.045: E/Fail 3(7235): org.json.JSONException: No value for patient_main_type_name
10-31 10:08:23.054: E/Fail 3(7235): org.json.JSONException: No value for patient_type_name

json数据

[{"initial_id":"1","initial_name":"Mr.","sex":"male","to_patient":"1","to_employee":"1"},{"initial_id":"2","initial_name":"Mrs.","sex":"female","to_patient":"1","to_employee":"1"},{"initial_id":"3","initial_name":"","sex":"male","to_patient":"1","to_employee":"1"}]       [{"patient_main_type_id":"36","patient_main_type_name":"asdasdsa","billing_type":"TPA"},{"patient_main_type_id":"37","patient_main_type_name":"sasa","billing_type":"TPA"},{"patient_main_type_id":"85","patient_main_type_name":"awsome","billing_type":"CGHS"},{"patient_main_type_id":"86","patient_main_type_name":"ssssssssss","billing_type":"CGHS"},{"patient_main_type_id":"87","patient_main_type_name":"ddddddd","billing_type":"TPA"}]           [{"patient_type_id":"1","patient_type_name":"abc","patient_main_type_id":"36"},{"patient_type_id":"2","patient_type_name":"pqr","patient_main_type_id":"36"},{"patient_type_id":"3","patient_type_name":"lmn","patient_main_type_id":"85"}]

0 个答案:

没有答案