Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java CustomListAdapter的Hashmap上出现Nullpointer异常?_Java_Android_Listview_Nullpointerexception - Fatal编程技术网

Java CustomListAdapter的Hashmap上出现Nullpointer异常?

Java CustomListAdapter的Hashmap上出现Nullpointer异常?,java,android,listview,nullpointerexception,Java,Android,Listview,Nullpointerexception,我一辈子都搞不清楚这件事。我只想用Hashmap将一些自定义数据添加到listview中 这个过程是我把信息放在一个Hashmap中,然后我把Hashmap放在一个ArrayList中——这会导致一个NullPointerException,我不知道如何修复它 public class RecipeDownload extends Activity { // Declare Variables ArrayList<HashMap<String, String>&

我一辈子都搞不清楚这件事。我只想用Hashmap将一些自定义数据添加到listview中

这个过程是我把信息放在一个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);


    }

任何帮助都将不胜感激。

初始化
FoodItems
。你没有

 FoodItems = new ArrayList<HashMap<String, String>>();
FoodItems=newArrayList();

顺便说一句,所有变量名都以小写开头。

初始化
FoodItems
。你没有

 FoodItems = new ArrayList<HashMap<String, String>>();
FoodItems=newArrayList();

顺便说一句,所有变量名都以小写开头。

初始化未初始化的foodItems。因此,您尝试添加并获取null指针Eception

ArrayList<HashMap<String, String>> FoodItems = new ArrayList<HashMap<String, String>>();
ArrayList FoodItems=new ArrayList();

初始化未初始化的foodItems。因此,您尝试添加并获取null指针Eception

ArrayList<HashMap<String, String>> FoodItems = new ArrayList<HashMap<String, String>>();
ArrayList FoodItems=new ArrayList();

您尚未初始化FoodItems

使用:

ArrayList FoodItems=new ArrayList();

您尚未初始化FoodItems

使用:

ArrayList FoodItems=new ArrayList();

哦,天哪。非常感谢。请不要浪费时间在问题上,所以,设置制动点并验证为什么它是空的,我会研究使用断点。我使用Eclipse,但还没有弄清楚如何在Eclipse中使用它(现在用谷歌搜索)。再一次谢谢你,天哪。非常感谢。请不要浪费时间在问题上,所以,设置制动点并验证为什么它是空的,我会研究使用断点。我使用Eclipse,但还没有弄清楚如何在Eclipse中使用它(现在用谷歌搜索)。再次感谢你,谢谢你,皮尤斯!你总是忘记最简单或最小的事情。谢谢你,皮尤!你总是忘记最简单或最小的事情。