NullPointerException
このコードは、何らかの理由で をスローします。理由がわかりません。誰でも助けることができますか?
static final String KEY_NEWS = "news"; // parent node
static final String KEY_ID = "id";
public static final String KEY_TITLOS = "titlos";
public static final String KEY_DATE = "date";
public static final String KEY_FOTO = "foto";
public static final String KEY_MESSAGE = "message";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rss_item_list);
try {
if (android.os.Environment
.getExternalStorageState()
.equals(android.os.Environment.MEDIA_MOUNTED))
{
if(!XmlDir.exists())
XmlDir.mkdirs();
if(isOnline()){
File file = new File(XmlDir,"news.xml");
XMLParser.DownloadFile(data, file);
コードはこのように続きます
InputStream is = new FileInputStream(file.getPath());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(is));
doc.getDocumentElement().normalize();
XMLParser parser = new XMLParser();
NodeList nl = doc.getElementsByTagName(KEY_NEWS);
// looping through all hotels nodes <hotel>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_TITLOS, parser.getValue(e, KEY_TITLOS));
map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
map.put(KEY_FOTO, parser.getValue(e, KEY_FOTO));
map.put(KEY_MESSAGE, parser.getValue(e, KEY_MESSAGE));
// adding HashList to ArrayList
HotelList.add(map);
}
次のコードのどこかに間違いがあると思います。
ListView myList=(ListView)findViewById(R.id.list);
.......
ListAdapter adapter = new SimpleAdapter(MyNews.this,
HotelList, R.layout.rss_item_list_row,
new String[] { KEY_FOTO, KEY_TITLOS, KEY_DATE, KEY_MESSAGE },
new int[] { R.id.page_url, R.id.title, R.id.pub_date, R.id.message });
myList.setAdapter(adapter);
// Click event for single list row
}
}
.......