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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:58:48+00:00 2026-06-01T09:58:48+00:00

I have a problem with parseInt() , it throws the error: unable to parse

  • 0

I have a problem with parseInt(), it throws the error: unable to parse ‘null’ as integer, also my ViewFlipper isn’t working. Here is my activity:

    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;

    import org.xml.sax.InputSource;
    import org.xml.sax.XMLReader;

    import android.app.Activity;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    import android.widget.ViewFlipper;
    import xml.parser.dataset;



   public class XmlParserActivity extends Activity implements OnClickListener {


    private final String MY_DEBUG_TAG = "WeatherForcaster";
  //  private dataset myDataSet;
    private LinearLayout layout;
    private int temp= 0;

    /** Called when the activity is first created. */
    //the ViewSwitcher
    private Button btn;
    private ViewFlipper flip;
//  private TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            layout=(LinearLayout)findViewById(R.id.linearlayout1);
            btn=(Button)findViewById(R.id.btn);
            btn.setOnClickListener(this);
            flip=(ViewFlipper)findViewById(R.id.flip);                              
            //when a view is displayed
            flip.setInAnimation(this,android.R.anim.fade_in);
            //when a view disappears
            flip.setOutAnimation(this, android.R.anim.fade_out); 
      //    String postcode = null;

        //  public String getPostcode {
          //      return postcode;
     //   }

                  //URL newUrl = c;

                //  myweather.setText(c.toString());


            /* Create a new TextView to display the parsingresult later. */
            TextView tv = new TextView(this);





           // run(0);
            //WeatherApplicationActivity postcode = new WeatherApplicationActivity();
            try {

                    /* Create a URL we want to load some xml-data from. */
                URL url = new URL("http://new.myweather2.com/developer/forecast.ashx?uac=gcV3ynNdoV&output=xml&query=G41");

                //String url = new String("http://new.myweather2.com/developer/forecast.ashx?uac=gcV3ynNdoV&output=xml&query="+WeatherApplicationActivity.postcode );



                //URL url = new URL(url);
                    //url.toString( );
                   //myString(url.toString() + WeatherApplicationActivity.getString(postcode));
                   // url + WeatherApplicationActivity.getString(postcode);
                    /* Get a SAXParser from the SAXPArserFactory. */
                    SAXParserFactory spf = SAXParserFactory.newInstance();
                    SAXParser sp = spf.newSAXParser();

                    /* Get the XMLReader of the SAXParser we created. */
                    XMLReader xr = sp.getXMLReader();
                    /* Create a new ContentHandler and apply it to the XML-Reader*/
                    handler myHandler = new handler();
                    xr.setContentHandler(myHandler);

                    /* Parse the xml-data from our URL. */
                    xr.parse(new InputSource(url.openStream()));
                    /* Parsing has finished. */

                    /* Our ExampleHandler now provides the parsed data to us. */
                    dataset parsedDataSet =
                                                                    myHandler.getParsedData();

                    /* Set the result to be displayed in our GUI. */
                    tv.setText(parsedDataSet.toString());


            } catch (Exception e) {
                    /* Display any Error to the GUI. */
                    tv.setText("Error: " + e.getMessage());
                    Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
            }



            temp = Integer.parseInt(xml.parser.dataset.getTemp());


                if(temp <0){
                    //layout.setBackgroundColor(Color.BLUE);
                    //layout.setBackgroundColor(getResources().getColor(R.color.silver));
                    findViewById(R.id.flip).setBackgroundColor(Color.BLUE);
                }
                else if(temp > 0 && temp < 9)
                { 
                    //layout.setBackgroundColor(Color.GREEN);
                    //layout.setBackgroundColor(getResources().getColor(R.color.silver));
                    findViewById(R.id.flip).setBackgroundColor(Color.GREEN);
                }
                else
                {
                    //layout.setBackgroundColor(Color.YELLOW);
                    //layout.setBackgroundColor(getResources().getColor(R.color.silver));
                    findViewById(R.id.flip).setBackgroundColor(Color.YELLOW);
                }


      /* Display the TextView. */
    this.setContentView(tv);
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub onClick(View arg0) {

        // TODO Auto-generated method stub
        flip.showNext();
         //specify flipping interval             
         //flip.setFlipInterval(1000);           
         //flip.startFlipping();
     }  

    }       

This is my dataset:

package xml.parser;



public class dataset {

 static String temp = null;

//  private int extractedInt = 0;


public static String getTemp() {
   return temp;
 }
public void setTemp(String temp) {
   this.temp = temp;
 }

This is my handler:

public void characters(char ch[], int start, int length) {
 if(this.in_temp){
           String setTemp = new String(ch, start, length);
          // myParsedDataSet.setTempUnit(new String(ch, start, length));
        //   myParsedDataSet.setTemp;
          }

For the dataset and handler I only pasted the code that involves the temp as I know they work when I take out the if statement. However even then my ViewFlipper wont work.
This is my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearlayout1"
>
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="25dip"
    android:text="Flip Example"
/>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="25dip"
        android:id="@+id/tv"
    />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="25dip"
    android:text="Flip"
    android:id="@+id/btn"
    android:onClick="ClickHandler"
/>
<ViewFlipper
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/flip">
    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="25dip"
            android:text="Item1a"
        />


    </LinearLayout>
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="25dip"
        android:id="@+id/tv2"
    />

</ViewFlipper>
</LinearLayout>

This is my Logcat:

04-01 18:02:24.744: E/AndroidRuntime(7331): FATAL EXCEPTION: main
04-01 18:02:24.744: E/AndroidRuntime(7331): java.lang.RuntimeException: Unable to start activity ComponentInfo{xml.parser/xml.parser.XmlParserActivity}: java.lang.NumberFormatException: unable to parse 'null' as integer
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.os.Looper.loop(Looper.java:150)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.ActivityThread.main(ActivityThread.java:4293)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at java.lang.reflect.Method.invokeNative(Native Method)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at java.lang.reflect.Method.invoke(Method.java:507)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at dalvik.system.NativeStart.main(Native Method)
04-01 18:02:24.744: E/AndroidRuntime(7331): Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer
04-01 18:02:24.744: E/AndroidRuntime(7331):     at java.lang.Integer.parseInt(Integer.java:356)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at java.lang.Integer.parseInt(Integer.java:332)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at xml.parser.XmlParserActivity.onCreate(XmlParserActivity.java:118)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
04-01 18:02:24.744: E/AndroidRuntime(7331):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
  • 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-01T09:58:49+00:00Added an answer on June 1, 2026 at 9:58 am

    Right now you’re trying to parse as an int a null String(you are calling the static method from dataset that will return null, because the object it returns(temp) is set to null). You probably want to parse as an int the result of the xml parsing, so instead of :

    temp = Integer.parseInt(xml.parser.dataset.getTemp());
    

    use the parsedDataSet variable:

     temp = Integer.parseInt(parsedDataSet.getTemp());
    

    Example:

        //....
        dataset parsedDataSet;
        try {
            URL url = new URL(
                    "http://new.myweather2.com/developer/forecast.ashx?uac=gcV3ynNdoV&output=xml&query=G41");
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            handler myHandler = new handler();
            xr.setContentHandler(myHandler);
            xr.parse(new InputSource(url.openStream()));
            parsedDataSet = myHandler.getParsedData();
            tv.setText(parsedDataSet.toString());
        } catch (Exception e) {
            tv.setText("Error: " + e.getMessage());
            Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
        }
    
        temp = Integer.parseInt(parsedDataSet.getTemp());
        //...
    

    Also I see other errors in your code:

    -In the xml parser, do you actually set the parsed String in the result?

    // I guess that myParsedDataSet is another dataset object that you return with
    // myHandler.getParsedData(), do you set the temp variable in that class?? // myParsedDataSet.setTemp(setTemp);
    if(this.in_temp){
               String setTemp = new String(ch, start, length);
              // myParsedDataSet.setTempUnit(new String(ch, start, length));
            //   myParsedDataSet.setTemp;
              }
    

    -Also you parse the xml, check the value from parseInt and then replace the main layout of the activity with this.setContentView(tv);?!

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

Sidebar

Related Questions

int diffanalysis=Integer.parseInt(history.getDiffanalysisHours()) ; int AnalysisHours= Integer.parseInt(project.getAnalysisHours()); history.setDiffanalysisHours(String.valueOf(AnalysisHours-diffanalysis)); projectService.saveorupdate(history); I have a problem , I
So I'm making a quiz for android and I have a problem. I parse
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run

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.