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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:54:38+00:00 2026-06-10T20:54:38+00:00

I have two classes, the XMLParser.java extends the activity and imports the ClassAsyncTask.java(from my

  • 0

I have two classes, the “XMLParser.java” extends the activity and imports the “ClassAsyncTask.java”(from my own library). Now Im having problem in my XMLParser, it says that the linearlayout is not visible, How can I fix this error? thanks

public class XMLParser extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ClassAsyncTask aObj = new ClassAsyncTask(
            "http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml", this);
    aObj.execute();

    //THIS IS MY PROBLEM, "The field ClassAsyncTask.linearLayout is not visible"
    aObj.linearLayout = new LinearLayout(this);
    aObj.linearLayout.setOrientation(1);

    /* Set the ContentView to layout for display */
    this.setContentView(aObj.linearLayout);

}

}

This is the ClassAsyncTask.java(from my own Library) that was imported by XMLParser.java

public class ClassAsyncTask extends AsyncTask<String, Void, String> {


String targetURL;
TextView name[], website[], category[];
LinearLayout linearLayout;
Context context;

public ClassAsyncTask(String site, Context ctx){
    targetURL = site;
    context = ctx;
}


@Override
protected String doInBackground(String... urls) {

    try {

        /* Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        /* Send URL to parse XML Tags */
        URL sourceUrl = new URL(targetURL);

        /* Create handler to handle XML Tags ( extends DefaultHandler ) */
        MyXMLHandler myXMLHandler = new MyXMLHandler();
        xr.setContentHandler(myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));

    } catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
    }
    return null;
}

/* Return-value from doInBackground */
protected void onPostExecute(String result) {

    /* Get result from MyXMLHandler SitlesList Object */
    SiteList sitesList = MyXMLHandler.sitesList;

    /* Assign TextView array length by arrayList size */
    name = new TextView[sitesList.getName().size()];
    website = new TextView[sitesList.getName().size()];
    category = new TextView[sitesList.getName().size()];

    int h = sitesList.getName().size();
    /* Set the result text in TextView and add it to layout */
    for (int i = 0; i < h; i++) {

        name[i]= new TextView(getApplicationContext());
        name[i].setText("Name = " + sitesList.getName().get(i));
        website[i]= new TextView(getApplicationContext());
        website[i].setText("Website = " + sitesList.getWebsite().get(i));
        category[i]= new TextView(getApplicationContext());
        category[i].setText("Website Category = " + sitesList.getCategory().get(i));
        linearLayout.addView(name[i]);
        linearLayout.addView(website[i]);
        linearLayout.addView(category[i]);

    }
}

}
  • 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-10T20:54:40+00:00Added an answer on June 10, 2026 at 8:54 pm

    I suggest you don’t access LinearLayout that way, and instead have setters and getters for it.

    In your ClassAsyncTask.java

    LinearLayout linearLayout;
    
    public void setLinearLayout(LinearLayout linearLayout){
        this.linearLayout = linearLayout;
    }
    
    
    public LinearLayout getLinearLayout(){
        return linearLayout;
    }
    

    And then in your XMLParser.java, just do LinearLayout myLinearLayout = aobj.getLinearLayout() do the edits you want to the layout, then return it back to ClassAsyncTask via aobj.setLinearLayout(myLinearLayout).

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

Sidebar

Related Questions

I have two classes, this one is XMLParser.java extends the activity and execute the
I have two classes(activites) in android: ProfileScreen. FillDetailScreen. Now from activity 1 I am
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes A and B generated by cxf-codegen-plugin from my WSDL. A
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two classes, Item and SoldItem . SoldItem inherits from Item adding some
I have two classes, one that inherits from the other. The base class is
I have two classes, TestA and TestB . TestA extends QObject . I have
I have two classes(Book,Software) that inherit from the Product class. these two classes have
have two classes, A and B, where B extends A and has one attribute

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.