Note that there are some explanatory texts on larger screens.

plurals
  1. POFatal exception main : unable to start the activity component
    text
    copied!<p>I am parsing the data and displaying it on the textview. Though i have initialized all the variables and necessary permissions to be made in manifest file. Still iam getting the fatal error. Please have a look at code. Thanks in advance.</p> <p>The application is running successfully if i use android 2.1 i.ie API-7..but if i replace it with android 4.0.3 i.e API-15..it throws the same reeor..as i mentioned in logcat file</p> <p>Main Activity</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View layout = findViewById(R.id.layout); TextView id[]; TextView Name[]; TextView Email[]; TextView Address[]; try{ SAXParserFactory saxPF= SAXParserFactory.newInstance(); SAXParser saxP = saxPF.newSAXParser(); XMLReader xmlR = saxP.getXMLReader(); URL url = new URL("http://xyz"); XMLHandler myXMLHandler = new XMLHandler(); xmlR.setContentHandler(myXMLHandler); xmlR.parse(new InputSource(url.openStream())); }catch(Exception e){ e.printStackTrace(); } data= XMLHandler.data; id = new TextView[data.getId().size()]; Name = new TextView[data.getName().size()]; Email = new TextView[data.getEmail().size()]; for(int i=0 ; i &lt;data.getName().size(); i++) { id[i] = new TextView (this); id[i].setText("Id : " + data.getId().get(i)); Name[i] = new TextView(this); Name[i].setText("Name : " + data.getName().get(i)); Email[i] = new TextView(this); Email[i].setText("Email : " + data.getEmail().get(i)); ((ViewGroup)layout).addView(id[i]); ((ViewGroup)layout).addView(Name[i]); ((ViewGroup)layout).addView(Email[i]); } </code></pre> <p>XMLGettersSetters Class</p> <pre><code>public class XMLGettersSetters { private ArrayList&lt;String&gt; id = new ArrayList&lt;String&gt;(); private ArrayList&lt;String&gt; Name = new ArrayList&lt;String&gt;(); private ArrayList&lt;String&gt; Email = new ArrayList&lt;String&gt;(); public ArrayList&lt;String&gt; getId(){ return id; } public void setId(String id){ this.id.add(id); } public ArrayList&lt;String&gt; getName(){ return Name; } public void setName(String name) { this.Name.add(name); } public ArrayList&lt;String&gt; getEmail(){ return Email; } public void setEmail(String email){ this.Email.add(email); } } </code></pre> <p>XMLHandler class</p> <pre><code>public class XMLHandler extends DefaultHandler { String elementValue= null; Boolean elementOn = false; public static XMLGettersSetters data = null; public static XMLGettersSetters getXMLData(){ return data; } public static void setXMLData(XMLGettersSetters data) { XMLHandler.data=data; } public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException{ elementOn=true; if(localName.equals("ExaReceipts")){ data = new XMLGettersSetters(); }else if(localName.equals("Organisation")){ } } public void endElement(String uri,String localName,String qName)throws SAXException { elementOn = false; if(localName.equalsIgnoreCase("id")) data.setId(elementValue); else if(localName.equalsIgnoreCase("Name")) data.setName(elementValue); else if(localName.equalsIgnoreCase("Email")) data.setEmail(elementValue); } public void characters (char[] ch , int start , int length)throws SAXException { if(elementOn){ elementValue= new String(ch,start,length); elementOn=false; } } } </code></pre> <p>AndroidManifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.spinnertest1" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="15" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt;" &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".SpinnerTest1Activity" 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;/application&gt; &lt;/manifest&gt; </code></pre> <p>logcat</p> <pre><code>06-26 17:41:38.482: W/dalvikvm(2129): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 06-26 17:41:38.492: E/AndroidRuntime(2129): FATAL EXCEPTION: main 06-26 17:41:38.492: E/AndroidRuntime(2129): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spinnertest1/com.spinnertest1.SpinnerTest1Activity}: java.lang.NullPointerException 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.ActivityThread.access$600(ActivityThread.java:123) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.os.Handler.dispatchMessage(Handler.java:99) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.os.Looper.loop(Looper.java:137) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.ActivityThread.main(ActivityThread.java:4424) 06-26 17:41:38.492: E/AndroidRuntime(2129): at java.lang.reflect.Method.invokeNative(Native Method) 06-26 17:41:38.492: E/AndroidRuntime(2129): at java.lang.reflect.Method.invoke(Method.java:511) 06-26 17:41:38.492: E/AndroidRuntime(2129): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 06-26 17:41:38.492: E/AndroidRuntime(2129): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-26 17:41:38.492: E/AndroidRuntime(2129): at dalvik.system.NativeStart.main(Native Method) 06-26 17:41:38.492: E/AndroidRuntime(2129): Caused by: java.lang.NullPointerException 06-26 17:41:38.492: E/AndroidRuntime(2129): at com.spinnertest1.SpinnerTest1Activity.onCreate(SpinnerTest1Activity.java:58) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.Activity.performCreate(Activity.java:4465) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-26 17:41:38.492: E/AndroidRuntime(2129): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 06-26 17:41:38.492: E/AndroidRuntime(2129): ... 11 more </code></pre>
 

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