救命!我真的很喜欢Stack Overflow,它是过去几个月的贡献者.我已经有很多问题了,我在这里找到了答案......但是这个我似乎找不到任何地方......我是Java和Android的小伙子,我一直想弄清楚这个出去好几天.出于某种原因,我有一个名为fileList的ListView对象,它返回null ...一切编译都很好,但是当我尝试使用fileList时,我得到一个NullPointerException ...我已经能够将它隔离到它的声明:
ListView fileList = (ListView)findViewById(R.id.open_ListView);
Run Code Online (Sandbox Code Playgroud)
但我不能为我的生活了解这条线路有什么问题!我在下面包含了大量代码,理论上它应该包含任何和所有可能以任何方式与此错误相关的代码.
对此,任何帮助都将非常感谢!谢谢!
这是违规的代码部分.它只是开关模块的OPEN_DIALOG部分,所有其他开关都可以很好地显示它们的newDialog.我用星星标记了违规行......
@Override
protected Dialog onCreateDialog(int id)
{
Dialog newDialog = new Dialog(Minervalia.this);
switch(id)
{
case DIALOG_FILE_NEW:
newDialog.setContentView(R.layout.new_file);
newDialog.setTitle("New File");
newDialog.setCancelable(true);
Button okBtn = (Button) newDialog.findViewById(R.id.ok_btn);
Button cancelBtn = (Button) newDialog.findViewById(R.id.cancel_btn);
final EditText widthEt = (EditText) newDialog.findViewById(R.id.width_edit);
final EditText heightEt = (EditText) newDialog.findViewById(R.id.height_edit);
okBtn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
file_width = Integer.parseInt(widthEt.getText().toString());
file_height = Integer.parseInt(heightEt.getText().toString());
onCreate(null);
dismissDialog(DIALOG_FILE_NEW);
}
});
cancelBtn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{ …Run Code Online (Sandbox Code Playgroud)