Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:16:00+00:00 2026-06-10T02:16:00+00:00

I have built a small application in android.I have used XML pull parser to

  • 0

I have built a small application in android.I have used XML pull parser to retrieve the data from an xml file using a url.The problem is that when i test the app on emulator it works fine but when i test it on a real device it shows that the application has been stopped unexpectedly.Force close.What could be the reason for this?Please help me.

08-20 16:07:30.070 E/AndroidRuntime(10349): FATAL EXCEPTION: main
08-20 16:07:30.070 E/AndroidRuntime(10349): java.lang.IllegalArgumentException
08-20 16:07:30.070 E/AndroidRuntime(10349): at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1615)
08-20 16:07:30.070 E/AndroidRuntime(10349): at com.example.androidsample4.UNIXclass.getEventsFromAnXML(UNIXclass.java:84)
08-20 16:07:30.070 E/AndroidRuntime(10349): at com.example.androidsample4.UNIXclass$1.onClick(UNIXclass.java:54)
08-20 16:07:30.070 E/AndroidRuntime(10349): at android.view.View.performClick(View.java:3131)
08-20 16:07:30.070 E/AndroidRuntime(10349): at android.view.View$PerformClick.run(View.java:12035)
08-20 16:07:30.070 E/AndroidRuntime(10349): at android.os.Handler.handleCallback(Handler.java:587)
08-20 16:07:30.070 E/AndroidRuntime(10349): at android.os.Handler.dispatchMessage(Handler.java:92)
08-20 16:07:30.070 E/AndroidRuntime(10349): at android.os.Looper.loop(Looper.java:132)
08-20 16:07:30.070 E/AndroidRuntime(10349): at android.app.ActivityThread.main(ActivityThread.java:4123)
08-20 16:07:30.070 E/AndroidRuntime(10349): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 16:07:30.070 E/AndroidRuntime(10349): at java.lang.reflect.Method.invoke(Method.java:491)
08-20 16:07:30.070 E/AndroidRuntime(10349): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
08-20 16:07:30.070 E/AndroidRuntime(10349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-20 16:07:30.070 E/AndroidRuntime(10349): at dalvik.system.NativeStart.main(Native Method)
08-20 16:07:30.080 W/ActivityManager( 2900):   Force finishing activity com.example.androidsample4/.UNIXclass

Getting this in logcat

package com.example.androidsample4;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class UNIXclass extends Activity 
{
    String unixcommands[];

    AutoCompleteTextView actv1;
    static final String URL="http://cympac.com/apps/xmlfile.xml";
    static final String KEY_COMMAND = "command"; // parent node
    static final String KEY_WORD = "word";
    static final String KEY_EXPLANATION = "explanation";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv1=(TextView)findViewById(R.id.textView1);
        AutoCompleteTextView actv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
        Button b1=(Button)findViewById(R.id.button1);
        unixcommands=getResources().getStringArray(R.array.Commands);
        ArrayAdapter<String> adapter =new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1,unixcommands);
        actv1 = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
        actv1.setThreshold(1);
        actv1.setAdapter(adapter);
        b1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) 
            {
                TextView myXmlContent = (TextView)findViewById(R.id.textView2);
                String stringXmlContent = null;
                try {
                    stringXmlContent = getEventsFromAnXML(getBaseContext());   //   54 line
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    Toast.makeText(getBaseContext(), "error:"+e.getMessage(), Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    Toast.makeText(getBaseContext(), "error:"+e.getMessage(), Toast.LENGTH_SHORT).show();
                }
                myXmlContent.setText(stringXmlContent);

            }
        });
    }









    public String getEventsFromAnXML(Context baseContext) throws XmlPullParserException,IOException
    {
        StringBuffer stringBuffer=new StringBuffer();

        java.net.URL url=new java.net.URL("http://cympac.com/apps/xmlfile.xml");
        XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp=factory.newPullParser();
        xpp.setInput(getInputStream(url),"UTF_8");         //84 line
        int eventType = xpp.getEventType();
        String word = null;

        String tag;
        while ((eventType = xpp.next()) != XmlPullParser.END_DOCUMENT)
        {
            if(XmlPullParser.START_TAG==eventType)
            {
                tag=xpp.getName();
                //stringBuffer.append("\n"+tag);
                if (tag.equals("word"))
                {
                    eventType = xpp.next();
                    word = xpp.getText();
                }
                else if (tag.equals("explanation"))
                {
                    eventType = xpp.next();
                   //if ("cancel".equals(word))
                    if(actv1.getText().toString().equals(word))

                    {
                        stringBuffer.append("\n" + xpp.getText());
                    }
                }

            }

        }
        return stringBuffer.toString();



    }

this is my code.I am getting IllegalArgument Exception

    public InputStream getInputStream(java.net.URL url2) 
    {

        try
        {
            return url2.openConnection().getInputStream();
        }
        catch(Exception e)
        {
            return null;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:16:01+00:00Added an answer on June 10, 2026 at 2:16 am

    You are providing an illegal argument when supplying the parser with your XML data. According to the source you pass a null value.

    See this thread: Execute "doInBackground()" showing IllegalArgumentException

    Show us the line where you pass the XML to the KXmlParser.setInput method.

    Edit: Your getInputStream() is returning null, and therefor the parser throws an IllegalArgumentException. Log the value of url2 before you use it, to see if it is null. You could also try to directly pass the stream as stated as the solution by the other question.

    xpp.setInput(getInputStream(url), "UTF_8");

    To

    xpp.setInput(url.openConnection().getInputStream(), "UTF_8");

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a small web application in asp.net c# in VS 2010 using
We have a small application we built in our spare time using the latest
I have a small ajax application built with php. Using phpMyAdmin I have set
I have built an ERP for a small company using MS-Access (front end) and
I'm developing an application with node.js and socket.io. I have built a small-scale project
So I have this small application of mine I'm trying to deploy using visual
So I have built a small application that has a physics engine and a
I have built a small web application in PHP where users must first log
I have built a small app using javascript. I am using javascript for form
I have to create a small asp.net-application. The last such web-application I have built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.