接口变为null

时间:2015-03-19 12:34:31

标签: android interface

在我的应用程序中,我使用界面从列表中获取值。我的列表显示正确,但是当我单击列表值时,应用程序会崩溃。请帮我解决问题。

代码

public class MainActivity extends Activity {
    private String[] array;
    private Dialog dialog;
    private DropDownList dropDownList;
    private Button button;
    private DropDownAdapter adapter;
    private GetDropDownData getDropDownData;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        array = getResources().getStringArray(R.array.Religion);
        button = (Button) findViewById(R.id.id_show);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog();
            }
        });

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();


        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void showDialog() {


        dialog = new Dialog(this);
        dialog.setContentView(R.layout.dropdown_list);
        ListView lvDropDown = (ListView) dialog.findViewById(R.id.lv_drop_down);
        adapter = new DropDownAdapter(this, array);
        lvDropDown.setAdapter(adapter);
        lvDropDown.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                getDropDownData.getValue(array[position]);
                getDropDownData.getPosition(position);
                dialog.dismiss();
            }
        });

        dialog.show();


    }


}

我认为我的界面未初始化,这就是我的应用崩溃的原因

在此行获取错误

 getDropDownData.getValue(array[position]);

0 个答案:

没有答案