2013-06-25 53 views
-5

我不知道为什么我要将java.lang.NullPointerException设置为autocomplete。正是这个说法产生了这个异常:获取NullPointerException

textView.setAdapter(adapter); 

我在布局文件夹中都有布局。

  AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); 
    helpBuilder.setTitle("Search Location"); 
    LayoutInflater inflater = getLayoutInflater(); 
    View PopupLayout = inflater.inflate(R.layout.custom_autocomplete, null); 
    helpBuilder.setView(PopupLayout); 
    AlertDialog helpDialog = helpBuilder.create(); 
    helpDialog.show(); 
    textView = (AutoCompleteTextView)findViewById(R.id.locationAutoCompleteTv); 
    adapter = new ArrayAdapter<String>(this,R.layout.item_list); 
    adapter.setNotifyOnChange(true); 
    textView.setAdapter(adapter); 
+1

那么,无论'textView'是'null'还是'adapter'都是'null'。只是'System.out.println'他们找出来。 -1,因为这可以非常容易地自行调试。 – Doorknob

+0

感谢您的帮助。是的,我在textview上得到了null,这是我通过helpDialog.findViewById解决的。 –

回答

1

如果该行被扔NullPointerException,它必须是textView为空。

这可能是因为您的findViewById调用给出了在视图中未找到的ID。

你没有给我们足够的信息,但我怀疑你试图抓住你刚刚展示的helpDialog中的textView。尝试用helpDialog.findViewById替换findViewById

+0

非常感谢您使用helpDialog.findViewById实例解决了我的问题。 对不起这真是一个愚蠢的问题。我不得不想出我自己的。 –

相关问题