作業中の Android プログラムに問題があります。以下のメソッドは MyActivity にあります。MyActivity には、AsyncTask を拡張する内部クラス InnerClass があります。InnerClass の doInBackground メソッドで、データベースを検索します。その検索の結果は、このメソッド processSearchResult に渡されます。最後の行が NullPointerException をスローすることを除いて、すべてが機能します。ボタンの作成中にこれの代わりに getApplicationContext() を使用しようとしましたが、それでも例外がスローされました。私はそれをデバッグし、問題が android.content.ContextWrapper クラスにあることを発見しました。getApplicationContext() メソッドでは、mBase.getApplicationContext を呼び出します。問題は、変数 mBase が null であることです。this キーワードを使用すると、このメソッドへの呼び出しがまだあり、mBase はまだ null です。mBase が null である理由を誰か教えてもらえますか? または、mBase が null になるのが実際に正常な場合はどうなりますか?
public void processSearchResult(ResultSet result) {
try {
int x = 1;
while (result.next()) {
String name = result.getString(1);
String ing = result.getString(2);
String ins = result.getString(3);
String notes = result.getString(4);
String type = result.getString(5);
String course = result.getString(6);
Recipe r = new Recipe(name, ing, ins, notes, type, course);
recipeList.add(r);
Button button = new Button(this);