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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:38:22+00:00 2026-06-17T11:38:22+00:00

I have created an application to parse data and putting it into a string

  • 0

I have created an application to parse data and putting it into a string array. I am doing this task in background. What I want to implement is, to read the string for whatever data the background process has parsed. In order to do that, I have made the array static and I am trying to read from it in another class, but my program is failing with the following error. Could anyone please take a look and help me out. Thanks.

01-17 09:43:07.927: E/AndroidRuntime(1167): FATAL EXCEPTION: main
01-17 09:43:07.927: E/AndroidRuntime(1167): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pro1/com.example.pro1.Secactivity}: java.lang.NullPointerException
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.os.Looper.loop(Looper.java:137)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.ActivityThread.main(ActivityThread.java:5039)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at java.lang.reflect.Method.invoke(Method.java:511)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at dalvik.system.NativeStart.main(Native Method)
01-17 09:43:07.927: E/AndroidRuntime(1167): Caused by: java.lang.NullPointerException
01-17 09:43:07.927: E/AndroidRuntime(1167):     at com.example.pro1.Secactivity.onCreate(Secactivity.java:29)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.Activity.performCreate(Activity.java:5104)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-17 09:43:07.927: E/AndroidRuntime(1167):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-17 09:43:07.927: E/AndroidRuntime(1167):     ... 11 more

Here is my main class where I am executing the asynctask:

public class MainActivity extends Activity {
    EditText uid;
    EditText password;
    Button submit;
    static String Sarray1[] = new String[50];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        submit = (Button)findViewById(R.id.submit);
        submit.setOnClickListener(new View.OnClickListener() {

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

                uid = (EditText)findViewById(R.id.id);
                password = (EditText)findViewById(R.id.password);
                String userid = uid.getText().toString();
                String pwd = password.getText().toString();
                Loginauth log = new Loginauth();
                if(!userid.equals("")&&!pwd.equals(""))
                {
                    String result = log.Login(userid,pwd);
                    if(result.equals(""))
                    {
                        Toast toast = Toast.makeText(getApplicationContext(), "Login Error: Check id and Password", Toast.LENGTH_LONG);
                        toast.show();
                    }
                    else
                    {
                        Toast toast = Toast.makeText(getApplicationContext(), "Login Successfull", Toast.LENGTH_SHORT);
                        toast.show();
                        SAXParserActivity ab = new SAXParserActivity();
                        ab.execute();
                        for (int j = 0; j<15;j++)
                    {
                        Log.d("Array",Sarray1[j].toString());
                    }
                        startActivity(new Intent("com.example.pro1.ABC"));
                    }

                }
                else
                {
                    Toast toast = Toast.makeText(getApplicationContext(), "Invalid id or password", Toast.LENGTH_LONG);
                    toast.show();
                }

            }
        });


    }
    class SAXParserActivity extends AsyncTask<Void,Void,Void> {

        XMLGettersSetters data;
        @Override
        protected Void doInBackground(Void... params) {
            Log.i("Abe","Abe");
            try {
                SAXParserFactory saxPF = SAXParserFactory.newInstance();
                SAXParser saxP = saxPF.newSAXParser();
                XMLReader xmlR = saxP.getXMLReader();
                URL url = new URL("http://www.xmlfiles.com/examples/cd_catalog.xml"); // URL of the XML             
                XMLHandler myXMLHandler = new XMLHandler();
                xmlR.setContentHandler(myXMLHandler);
                xmlR.parse(new InputSource(url.openStream()));

            } catch (Exception e) {
                System.out.println(e);
            }

            data = XMLHandler.data;                 
            for (int i = 0; i < data.getTitle().size(); i++) {

                Sarray1[i] =data.getTitle().get(i);
                //System.out.printf("Sarray",Sarray[i].toString());
                //Log.d("Abe",Sarray);
                //Sarray1[i]=Sarray;

                Log.d("Abe",Sarray1[i].toString());
            }

            return null;
        }
    }


}

Here is the class from where I am trying to access the array:

package com.example.pro1;


import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.TabHost;

public class Secactivity extends FragmentActivity {
    TabHost tHost;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main1);

    tHost = (TabHost) findViewById(android.R.id.tabhost);
    tHost.setup();
    String array[] = new String[50];
    for(int i = 0;i<MainActivity.Sarray1.length;i++)
    {
        array[i] = MainActivity.Sarray1[i];
        Log.d("Secactivity",MainActivity.Sarray1[i]);
    }

    /** Defining Tab Change Listener event. This is invoked when tab is changed */
    TabHost.OnTabChangeListener tabChangeListener = new TabHost.OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {
                android.support.v4.app.FragmentManager fm =   getSupportFragmentManager();
                Protab1 androidFragment = (Protab1) fm.findFragmentByTag("ST");
                Protab2 appleFragment = (Protab2) fm.findFragmentByTag("CSI");
                android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();

                /** Detaches the androidfragment if exists */
                if(androidFragment!=null)
                    ft.detach(androidFragment);

                /** Detaches the applefragment if exists */
                if(appleFragment!=null)
                    ft.detach(appleFragment);

                /** If current tab is android */
                if(tabId.equalsIgnoreCase("ST")){

                    if(androidFragment==null){      
                        /** Create AndroidFragment and adding to fragmenttransaction */
                        ft.add(R.id.realtabcontent,new Protab1(), "ST");                        
                    }else{
                        /** Bring to the front, if already exists in the fragmenttransaction */
                        ft.attach(androidFragment);                     
                    }

                }else{  /** If current tab is apple */
                    if(appleFragment==null){
                        /** Create AppleFragment and adding to fragmenttransaction */
                        ft.add(R.id.realtabcontent,new Protab2(), "CSI");                       
                    }else{
                        /** Bring to the front, if already exists in the fragmenttransaction */
                        ft.attach(appleFragment);                       
                    }
                }
                ft.commit();                
            }
        };


        /** Setting tabchangelistener for the tab */
        tHost.setOnTabChangedListener(tabChangeListener);

        /** Defining tab builder for Andriod tab */
    TabHost.TabSpec tSpecAndroid = tHost.newTabSpec("ST");
    tSpecAndroid.setIndicator("ST");        
    tSpecAndroid.setContent(new DummyTabContent(getBaseContext()));
    tHost.addTab(tSpecAndroid);


    /** Defining tab builder for Apple tab */
    TabHost.TabSpec tSpecApple = tHost.newTabSpec("CSI");
    tSpecApple.setIndicator("CSI");        
    tSpecApple.setContent(new DummyTabContent(getBaseContext()));
    tHost.addTab(tSpecApple);

}   

}
  • 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-17T11:38:23+00:00Added an answer on June 17, 2026 at 11:38 am

    Don’t use fix sized Array like this,

    static String Sarray1[] = new String[50];
    

    Change that to ArrayList,

    ArrayList<String> Sarray1 = new ArrayList<String>();
    

    And then add data to that to use furhter,

    Sarray1.add(data.getTitle().get(i));
    

    In your case if you loop with MainActivity.Sarray1.length then it will always run for 50 times even though there is only 10 data entries. So there are changes of getting null values for remaining indexes.

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

Sidebar

Related Questions

I have created application where i just need to access data form assets folder.
I have created Windows Application. In this, I have multiple tables in dataset, now
We have created an application which we want to run in a 64 bit
We have created a multi-threaded application which process/parse big files (few hundred MB's) simultaneously.
i have created one application which parsed the data and it will displyed in
I have created an application, using ARC, that parses data from an online XML
Background: In my application written in C++, I have created 3 threads: AnalysisThread (or
I have created an application in windows form. Once I submit the application, the
I have created an application that connect on a web-server and reads an xml
I have created an application in facebook,all is working fine except the publish to

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.