Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - XML Parser App
    primarykey
    data
    text
    <p>I'm developing an android app which parses an XML file from the server using SAX and displays in the form of list. I'm getting null pointer exception. But when i excecuted the same code as java application removing all the android stuffs i'm able to print the list which wanted to display in the list. It's document of about 700 items. I couldn't understand much from the logs i got using Logcat. I'm new to android development. It would really helpful if you can help me with this.</p> <pre><code>06-08 13:27:04.032: ERROR/AndroidRuntime(403): FATAL EXCEPTION: main 06-08 13:27:04.032: ERROR/AndroidRuntime(403): java.lang.RuntimeException: Unable to start activity ComponentInfo{rss.com/rss.com.RSSReader}: java.lang.NullPointerException 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:3647) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:507) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): Caused by: java.lang.NullPointerException 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at rss.com.RSSReader.onCreate(RSSReader.java:33) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) 06-08 13:27:04.032: ERROR/AndroidRuntime(403): ... 11 more </code></pre> <p>My Manifest file is </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="rss.com" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="9" /&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".RSSReader" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".ShowDescription" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Java code:</p> <pre><code>public class RSSReader extends Activity implements OnItemClickListener{ /** Called when the activity is first created. */ public RSSFeed feed=null; public List&lt;RSSItem&gt; list = null; public final static String RSSFEEDOFCHOICE = "http://people.rit.edu/~vxr9024/chemicalFeed.xml"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); feed = getFeed(RSSFEEDOFCHOICE); list = feed.getAllItems(); UpdateDisplay(list); } RSSFeed getFeed(String urlToRssFeed) { FeedParser parsedFeed = new FeedParser(); try { URL url = new URL(urlToRssFeed); XMLReader xread = XMLReaderFactory.createXMLReader(); xread.setContentHandler(parsedFeed); InputSource is = new InputSource(url.openStream()); xread.parse(is); return parsedFeed.getFeed(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; }catch (Exception e){ System.out.println("Blahblah"); return null; } } private void UpdateDisplay(List&lt;RSSItem&gt; list) { // TODO Auto-generated method stub RSSItem[] items = new RSSItem[list.size()]; list.toArray(items); ListView itemlist = (ListView) findViewById(R.id.itemlist); //RSSItem[] items = new RSSItem[()]; ArrayAdapter&lt;RSSItem&gt; adapter = new ArrayAdapter&lt;RSSItem&gt;(this, android.R.layout.simple_list_item_1, items); itemlist.setAdapter(adapter); itemlist.setOnItemClickListener(this); itemlist.setSelection(0); } @Override public void onItemClick(AdapterView parent, View v, int position, long id) { // TODO Auto-generated method stub Intent intentItem = new Intent(this,ShowDescription.class); Bundle b = new Bundle(); b.putString("chemicalName",feed.getItem(position).getChemicalName()); b.putString("synonyms",feed.getItem(position).getSynonyms()); b.putString("formula",feed.getItem(position).getFormula()); intentItem.putExtra("android.intent.extra.INTENT", b); startActivity(intentItem); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload