if文のTextViewで 'getText'を呼び出すときにこのエラーが発生します。奇妙なことは、ifステートメントの直前のLogステートメントの同じビューで同じメソッドを呼び出すと、エラーがポップアップしないということです。私は他の多くの同様の質問を見てきましたが、私は自分のビルドをきれいにして再構築しようとしました。私がそれを実行しようとすると、エラーはエラーになります。ブール値は逆参照できません。 TextViewはプリミティブ型ではないので、その上でメソッドを呼び出すことができるはずです。私は以下の方法を持っています。他のコードが必要な場合は教えてください。TextView/errorでメソッド 'getText()'を解決できません:ブール値を参照解除できませんか?
private void doSearch(Cursor query) {
// get a Cursor, prepare the ListAdapter
// and set it
Cursor c = query;
startManagingCursor(c);
String[] from = new String[] {"QUANTITY", "_id"};
int[] to = new int[] {android.R.id.text1};
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, c, from, to);
mListView.setAdapter(cursorAdapter);
Log.e("doSearch method:", "has been called");
mListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, log with the TextView text
Log.e("doSearch method:", "Answer: " + ((TextView) view).getText()); //no error here
if(cMap.containsKey((TextView) view).getText()){ //error here
//start new activity
} else if (chMap.containsKey((TextView) view).getText()){//error here
//start new activity
} else if (aMap.containsKey((TextView) view).getText()){//error here
//start new activity
}
}
});
}
ありがとうございました。あなたがのcontainsKeyの引数としてビューを渡している
containsKey()は、テキストビューではなくブール値を返します。したがって、エラー。あなたはおそらくget()を代わりにしたいでしょう(nullの警告チェック) –
if文で使用するブール値を使用しませんか? – grassss
ブール値にはgetTextメソッドはありません。 –