私は長い時間を検索し、私の問題の解決策を見つけることができません。私は、AutoCompleteTextViewでダイアログを作成しようとしています。 Androidデベロッパーのウェブサイトのチュートリアルに続き、うまくいきました。以前はDialogsのレイアウトを使って成功していたので、これも簡単だと思いました。 Dialogのレイアウトを作成し、AutoCompleteTextViewにIDがあることを確認しました。面白いことが起こる場所はここにあります...AutoCompleteTextView NullPointer例外
dialog.setContentView(R.layout.auto_layout);
AutoCompleteTextView auto_tv = (AutoCompleteTextView)findViewById(R.id.role_ac);
ここにレイアウトもあります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Role" />
<AutoCompleteTextView android:id="@+id/role_ac" android:layout_width="280dip" android:layout_height="wrap_content"/>
<Button android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Done"
android:id="@+id/auto_doneButton" />
</LinearLayout>
何らかの理由で、auto_tvがレイアウトauto_layoutに存在するにもかかわらず、nullです。 Dialog内でAutoCompleteTextViewを取得できる唯一の方法は、レイアウトをプログラムで構築することです。なぜそれを使用しようとするとAutoCompletTextViewはnullですか?レイアウトで何かを忘れてしまったのですか、オブジェクトを正しく構築していませんか?これに関する助けがあれば大いに感謝します。ありがとう。
Javaの行がアプリケーションに適合する場所のコンテキストを指定できますか?それはどのような活動ですか? – Blumer
私は何か似たようなことをしています! http://stackoverflow.com/questions/12854336/autocompletetextview-backed-by-cursorloader – toobsco42