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 9103021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:31:48+00:00 2026-06-17T01:31:48+00:00

I realize this is an easy issue usually, but I’ve been looking at other

  • 0

I realize this is an easy issue usually, but I’ve been looking at other similar questions on this site and others and have not been able to fix the code, nor seeing exactly where the error is coming from. What seems to be my problem is calling an OnClickListener assigned to a button, but then again I could be wrong. I had basically straight copied this code (with minimal changes) from another application where this had worked. This fact baffles me a little bit more. Thanks in advance for your help with this relatively easy question.

Code:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.update_activity);

    final Handler handler;
    handler = new Handler();

    final EditText getCustID = (EditText) findViewById(R.id.customer);
    final EditText custvar1 = (EditText) findViewById(R.id.var1);
    final EditText custvar2 = (EditText) findViewById(R.id.var2);
    final EditText custvar3 = (EditText) findViewById(R.id.var3);

    class sendGET implements Runnable
    {
        private String url;

        public sendGET(String mUrl)
        {
            url = mUrl;
        }

        public void run()
        {
            try
            {
                //Declare HttpClient and HttpGet
                HttpClient client = new DefaultHttpClient();
                HttpGet httpget = new HttpGet(url);

                //Run HttpGet
                client.execute(httpget);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    class getCustomerData implements Runnable
    {       
        public void run()
        {
            try
            {
                InputStream stream = null;
                XMLparser xmlParser = new XMLparser();
                List<Customer> customers = null;

                String parseUrl = URL + getCustID.getText().toString();

                try
                {
                    stream = downloadUrl(parseUrl);
                    customers = xmlParser.parse(stream);
                }
                finally
                {
                    stream.close();
                }

                final Customer data = customers.get(0);

                handler.post(new Runnable() {
                    public void run() {
                        custvar1.setText(String.valueOf(data.var1));
                        custvar2.setText(String.valueOf(data.var2));
                        custvar3.setText(String.valueOf(data.var3));
                    }
                });
            }
            catch (IOException e)
            {
                //return getResources().getString(R.string.connection_error);
            }
            catch (XmlPullParserException e)
            {
                //return getResources().getString(R.string.xml_error);
            }
        }

        private Customer readCustomer(XmlPullParser parser) throws XmlPullParserException, IOException
        {
            parser.require(XmlPullParser.START_TAG, null, "customer");
            String custID = null;
            String var1 = null;
            String var2 = null;
            String var3 = null;

            while(parser.next() != XmlPullParser.END_TAG)
            {
                if (parser.getEventType() != XmlPullParser.START_TAG)
                {
                    continue;
                }
                String name = parser.getName();
                if (name.equals("CustID"))
                {
                    custID = readCustID(parser);
                } else if (name.equals("custvar1"))
                {
                    var1 = readVar1(parser);
                } else if (name.equals("custvar2"))
                {
                    var2 = readVar2(parser);
                } else if (name.equals("custvar3"))
                {
                    var3 = readVar3(parser);
                } else
                {
                    skip(parser);
                }

            }
            return new Customer(custID, var1, var2, var3);
        }

        private String readCustID(XmlPullParser parser) throws IOException, XmlPullParserException
        {
            parser.require(XmlPullParser.START_TAG, null, "CustID");
            final String custID = readText(parser);
            parser.require(XmlPullParser.END_TAG, null, "CustID");
            return custID;
        }

        private String readVar1(XmlPullParser parser) throws IOException, XmlPullParserException
        {
            parser.require(XmlPullParser.START_TAG, null, "custvar1");
            String var1 = readText(parser);
            parser.require(XmlPullParser.END_TAG, null, "custvar1");
            return var1;
        }

        private String readVar2(XmlPullParser parser) throws IOException, XmlPullParserException
        {
            parser.require(XmlPullParser.START_TAG, null, "custvar2");
            String var2 = readText(parser);
            parser.require(XmlPullParser.END_TAG, null, "custvar2");
            return var2;
        }

        private String readVar3(XmlPullParser parser) throws IOException, XmlPullParserException
        {
            parser.require(XmlPullParser.START_TAG, null, "custvar3");
            String var3 = readText(parser);
            parser.require(XmlPullParser.END_TAG, null, "custvar3");
            return var3;
        }

        private String readText(XmlPullParser parser) throws IOException, XmlPullParserException
        {
            String result = "";
            if (parser.next() == XmlPullParser.TEXT)
            {
                result = parser.getText();
                parser.nextTag();
            }
            return result;
        }

        private void skip(XmlPullParser parser) throws IOException, XmlPullParserException
        {
            if (parser.getEventType() != XmlPullParser.START_TAG)
            {
                throw new IllegalStateException();
            }
            int depth = 1;
            while (depth != 0)
            {
                switch (parser.next()) {
                case XmlPullParser.END_TAG:
                    depth --;
                case XmlPullParser.START_TAG:
                    depth++;
                    break;
                }
            }
        }

        class XMLparser
        {       
            public List<Customer> parse(InputStream in) throws XmlPullParserException, IOException {
                try
                {
                    XmlPullParser parser = Xml.newPullParser();
                    parser.setInput(in, null);
                    parser.nextTag();
                    return readXML(parser);
                } finally {
                    in.close();
                }
            }

            private List<Customer> readXML(XmlPullParser parser) throws XmlPullParserException, IOException
            {
                List<Customer> custData = new ArrayList<Customer>();

                parser.require(XmlPullParser.START_TAG, null, "xml");
                while (parser.next() != XmlPullParser.END_TAG)
                {
                    if (parser.getEventType() != XmlPullParser.START_TAG)
                    {
                        continue;
                    }
                    String name = parser.getName();

                    //Look for customer tag
                    if (name.equals("customer"))
                    {
                        custData.add(readCustomer(parser));
                    }
                    else
                    {
                        skip(parser);
                    }
                }

                return custData;
            }
        }

        private InputStream downloadUrl(String urlString) throws IOException
        {
            URL url = new URL(urlString);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(10000);
            conn.setConnectTimeout(15000);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);

            //start the query
            conn.connect();
            InputStream stream = conn.getInputStream();
            return stream;
        }
    }

    final Button getData = (Button) findViewById(R.id.getData);
    getData.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            //Declare and start thread
            final Runnable mGetData = new getCustomerData();
            final Thread getData = new Thread(mGetData);
            getData.start();
        }
    });

    final Button submit = (Button) findViewById(R.id.Submit);
    submit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //set url
            String url = "**removed**";
            url += "var1=" + custvar1.getText().toString() + "&var2=" + custvar2.getText().toString() + "&var3=" + custvar3.getText().toString();

            //Declare and start thread
            final Runnable mConnect = new sendGET(url);
            final Thread Connect = new Thread(mConnect);
            Connect.start();
        }
    });
}

public class Customer
{
    public final String custID;
    public final String var1;
    public final String var2;
    public final String var3;

    private Customer()
    {
        custID = null;
        var1 = null;
        var2 = null;
        var3 = null;
    }

    private Customer(String custID, String var1, String var2, String var3)
    {
        this.custID = custID;
        this.var1 = var1;
        this.var2 = var2;
        this.var3 = var3;

    }
}

Logcat Error:

01-09 19:20:53.478: W/dalvikvm(911): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
01-09 19:20:53.478: E/AndroidRuntime(911): FATAL EXCEPTION: Thread-99
01-09 19:20:53.478: E/AndroidRuntime(911): java.lang.NullPointerException
01-09 19:20:53.478: E/AndroidRuntime(911):  at us.rns.editdata.UpdateActivity$1getCustomerData.run(UpdateActivity.java:90)
01-09 19:20:53.478: E/AndroidRuntime(911):  at java.lang.Thread.run(Thread.java:856)
01-09 19:20:54.408: W/IInputConnectionWrapper(911): showStatusIcon on inactive InputConnection
  • 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-17T01:31:49+00:00Added an answer on June 17, 2026 at 1:31 am

    Your downloadUrl method is failing.

    InputStream stream = null;
    XMLparser xmlParser = new XMLparser();
    List<Customer> customers = null;
    
    String parseUrl = URL + getCustID.getText().toString();
    
    try
    {
        stream = downloadUrl(parseUrl);
        customers = xmlParser.parse(stream);
    }
    finally
    {
        stream.close();
    }
    

    The stream object is set to null, then you assign stream = downloadUrl(parseUrl).

    The downloadUrl method fails, without having assigned anything to stream.

    You then try to close the stream in the finally clause.

    private InputStream downloadUrl(String urlString) throws IOException
    {
        URL url = new URL(urlString);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000);
        conn.setConnectTimeout(15000);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
    
        //start the query
        conn.connect();
        InputStream stream = conn.getInputStream();
        return stream;
    }
    

    Put a breakpoint on this method, and debug through it. Please return with the exact line it is breaking on. I suspect it is conn.connect(); or InputStream stream = conn.getInputStream();

    I would also do this in the finally clause:

    finally
    {
        if(stream != null)
            stream.close();
    }
    

    It could also be the following:

    You need to move all of these:

    final EditText getCustID = (EditText) findViewById(R.id.customer);
    final EditText custvar1 = (EditText) findViewById(R.id.var1);
    final EditText custvar2 = (EditText) findViewById(R.id.var2);
    final EditText custvar3 = (EditText) findViewById(R.id.var3);
    
    final Button getData = (Button) findViewById(R.id.getData);
    
    final Button submit = (Button) findViewById(R.id.Submit);
    

    into onResume, rather than onCreate()

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

Sidebar

Related Questions

I realize this is a basic question but I have searched online, been to
I realize this question has probably been asked numerous times, but I have not
I realize this question is pretty basic, but I'm really stuck. I have a
I realize this is a broad topic, but I'm looking for a good primer
I realize this might be an easy question that I may have overlooked in
I realize this is an easy question, but despite searching I can't find anything
I realize this is syntactically bad but I figure it somewhat explains what I'm
I realize this is more of a hardware question, but this is also very
I realize this is a rather odd request, but I was wondering if anyone
I realize this is probably a hopelessly newbie question, but what is the difference

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.