我正在構建一個Android應用程序,我在其中下載包含要在GoogleMap上顯示的內容的XML文件。信息窗口是可點擊的,所以區分不同的窗口我使用Hashmap。無法訪問散列圖
無論何時地圖加載它崩潰與NullPointerException。 HashMap的被命名爲markerEntryHashMap,這裏的一些代碼:
private class DownloadXmlTask extends AsyncTask<String, Void, String> {
/**
* Hashmap with marker; String ids as key, entry obj as value
*/
private HashMap<String, CurvitVacatureXmlParser.Entry> markerEntryHashMap;
@Override
protected String doInBackground(String... urls) {
[...]
}
@Override
protected void onPostExecute(String result) {
for (CurvitVacatureXmlParser.Entry entry : mapEntries) {
[...]
Log.d(TAG, "Marker ID: " + m.getId()); // OK; Marker ID: m0
Log.d(TAG, "Entry ID: " + entry.id); // OK; Entry ID: 12
// there is no unique identifier in an info-window so I thought using the hashmap to differentiate later on in an OnInfoWindowClickListener
// This crashes: FATAL EXCEPTION: main java.lang.NullPointerException
markerEntryHashMap.put(m.getId(), entry);
}
}
}
任何你們/加侖發現錯誤了嗎?
你可以發佈你的空指針棧跟蹤 – Babel
你初始化了你的地圖嗎? 'markerEntryHashMap = new HashMap <>();' –