Android java.lang.nullpointerexception hatası
Merhabalar, bir siteden XML parse yapmaktayim fakat aldigim hata dolayisiyla uygulama calismiyor. LogCat uzerinden hatayi aldigim yeri buldum,arastirdigim kadariyla genelde karsilasilan bir hata...Nasil duzeltebilirim ?
[code]
public class XMLParsing extends Activity {
static final String URL = "http://www.psnit.pl/mobile.xml";
static final String KEY_ITEM = "item";
static final String KEY_TITLE = "title";
//static final String KEY_REGION = "region";
static final String KEY_SNOWCOVER = "snowCover";
//static final String KEY_SKICONDITIONS = "skiConditions";
static final String KEY_PUBDATE = "pubDate";
@Override
protected void onCreate(Bundle SavedInstanceState) {
super.onCreate(SavedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParsing parser = new XMLParsing();
String xml = parser.getXmlFromUrl(URL);
Document doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName(KEY_ITEM); //hatayi aldigim satir burasi
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);
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
// map.put(KEY_REGION, parser.getValue(e, KEY_REGION));
map.put(KEY_SNOWCOVER, parser.getValue(e, KEY_SNOWCOVER));
// map.put(KEY_SKICONDITIONS, parser.getValue(e, KEY_SKICONDITIONS));
map.put(KEY_PUBDATE, parser.getValue(e, KEY_PUBDATE));
menuItems.add(map);
}
ListAdapter adapter = new SimpleAdapter(this, menuItems, (Integer) R.layout.list_item, new String[] {KEY_TITLE,KEY_SNOWCOVER,KEY_PUBDATE}, new int[] {
R.id.title,R.id.snowCover, R.id.pubDate});
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String snowCover =((TextView) view.findViewById(R.id.snowCover)).getText().toString();
String pubDate = ((TextView) view.findViewById(R.id.pubDate)).getText().toString();
//Starting new Intent
Intent in = new Intent(XMLParsing.this, SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_SNOWCOVER, snowCover);
in.putExtra(KEY_PUBDATE, pubDate);
startActivity(in);
}
});
}
[/code]
LogCat
[code]02-13 15:12:58.568: E/AndroidRuntime(1515): FATAL EXCEPTION: main
02-13 15:12:58.568: E/AndroidRuntime(1515): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.polskiesta.pl/com.polskiesta.pl.XMLParsing}: java.lang.NullPointerException
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.os.Looper.loop(Looper.java:137)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-13 15:12:58.568: E/AndroidRuntime(1515): at java.lang.reflect.Method.invokeNative(Native Method)
02-13 15:12:58.568: E/AndroidRuntime(1515): at java.lang.reflect.Method.invoke(Method.java:511)
02-13 15:12:58.568: E/AndroidRuntime(1515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-13 15:12:58.568: E/AndroidRuntime(1515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-13 15:12:58.568: E/AndroidRuntime(1515): at dalvik.system.NativeStart.main(Native Method)
02-13 15:12:58.568: E/AndroidRuntime(1515): Caused by: java.lang.NullPointerException
02-13 15:12:58.568: E/AndroidRuntime(1515): at com.polskiesta.pl.XMLParsing.onCreate(XMLParsing.java:48)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.Activity.performCreate(Activity.java:5104)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-13 15:12:58.568: E/AndroidRuntime(1515): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-13 15:12:58.568: E/AndroidRuntime(1515): ... 11 more
[/code]