0

私は一生これを理解することができません。Hashmap を使用して、いくつかのカスタム データをリストビューに追加したいだけです。

プロセスは、情報を Hashmap に入れ、次にハッシュマップを ArrayList に入れます - これにより NullPointerException が発生し、これを修正する方法がわかりません。

public class RecipeDownload extends Activity {
    // Declare Variables
    ArrayList<HashMap<String, String>> FoodItems;
    public static String TitleofFood = "TitleofFood";
    public static String LinktoRecipe = "LinktoRecipe";
    public static String IngredientsofRecipe = "IngredientsofRecipe";
    public static String ThumbnailofFood = "thumbnail";


    public HashMap<String, String> RecipeItems = new HashMap<String, String>();


    EditText SearchField;
    Button ResearchButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from listview_main.xml
        setContentView(R.layout.recipedownload);

        // Declaration of Button "Refreshbutton".
        ResearchButton = (Button) findViewById(R.id.RefreshButton);

        // Declaration of EditText "SearchField"
        SearchField = (EditText) findViewById(R.id.SearchField);

        SearchField.setSelected(false);

        SearchField.setText(MainActivity.ItemToSearch);

        // Execute ConnectionCheck
        CheckConnection();

        // Recipe List Context Menu
        //registerForContextMenu(RecipeList);   


        RecipeItems.put(TitleofFood, "href");
        RecipeItems.put(LinktoRecipe, "href");
        RecipeItems.put(IngredientsofRecipe, "ingredients");
        RecipeItems.put(ThumbnailofFood, "thumbnail");

        FoodItems.add(RecipeItems);


    }

これにより、行 71 で NullPointerException が作成されます。

09-04 16:16:46.589: E/AndroidRuntime(10372): FATAL EXCEPTION: main
09-04 16:16:46.589: E/AndroidRuntime(10372): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.paul.barcoder/org.paul.barcoder.RecipeDownload}: java.lang.NullPointerException
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.os.Looper.loop(Looper.java:137)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.ActivityThread.main(ActivityThread.java:4898)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at java.lang.reflect.Method.invokeNative(Native Method)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at java.lang.reflect.Method.invoke(Method.java:511)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at dalvik.system.NativeStart.main(Native Method)
09-04 16:16:46.589: E/AndroidRuntime(10372): Caused by: java.lang.NullPointerException
09-04 16:16:46.589: E/AndroidRuntime(10372):    at org.paul.barcoder.RecipeDownload.onCreate(RecipeDownload.java:71)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.Activity.performCreate(Activity.java:5206)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
09-04 16:16:46.589: E/AndroidRuntime(10372):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
09-04 16:16:46.589: E/AndroidRuntime(10372):    ... 11 more

どんな助けでも大歓迎です。

4

3 に答える 3

1

Initialized ではなかったので foodItems を初期化します。したがって、nullPointer Eceptionを追加して取得しようとします

ArrayList<HashMap<String, String>> FoodItems = new ArrayList<HashMap<String, String>>();
于 2013-09-04T14:26:08.240 に答える
1

FoodItemsを初期化していません

使用する :

 ArrayList<HashMap<String, String>> FoodItems = new ArrayList<HashMap<String, String>>();
于 2013-09-04T14:26:30.107 に答える