2013-06-25 52 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實例解決了我的問題。 對不起這真是一個愚蠢的問題。我不得不想出我自己的。 –

相關問題