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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:45:20+00:00 2026-05-27T01:45:20+00:00

I need to store a load of content which I retrieved from http. I

  • 0

I need to store a load of content which I retrieved from http. I have created a method to do the retrieving of contents. But I need to store it in an array which is declared outside. I am having troubles doing return value.

My question is:

1)Where do I place my return statement?

2)How do I store the contents from searchInfo into the array mStrings[]?

This is my code.

public class MainActivity extends Activity
{
ListView list;
Adapter adapter;

private static final String targetURL ="http://www.google.com/images";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    list=(ListView)findViewById(R.id.list);
    adapter=new Adapter(this, mStrings);
    list.setAdapter(adapter);
    }

    public String searchInfo()
{
    try {
        // Get the URL from text box and make the URL object

        URL url = new URL(targetURL);

        // Make the connection
        URLConnection conn = url.openConnection();
        BufferedReader reader = new BufferedReader(
         new InputStreamReader(conn.getInputStream()));

        // Read the contents line by line (assume it is text),
        // storing it all into one string
        String content ="";
        String line = reader.readLine();  
        Pattern sChar = Pattern.compile("&.*?;");
        Matcher msChar = sChar.matcher(content);
        while (msChar.find()) content = msChar.replaceAll("");

        while (line != null) {

            if(line.contains("../../"))
            {                   
                content += xyz;
                line = reader.readLine();                   
            }

            else if (line.contains("../../") == false)
            {
                line = reader.readLine();
            }

        }

        // Close the reader
        reader.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }   

}

private String[] mStrings={searchImage()};

}
  • 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-05-27T01:45:21+00:00Added an answer on May 27, 2026 at 1:45 am

    You have a few options:

    1. You can declare mStrings[] as an instance variable (put protected String[] mStrings; right after the line where you declare the Adapter) and then initialize it in your onCreate method (mStrings = new String[SIZE];) where SIZE is the size for your array. After that, your searchInfo method can just add items to mString and doesn’t have to return anything (since a instance variable is visible to all members fo the class).

    2. You can change searchInfo’s signature so it returns String[] and then declare a temp string array inside that method, add the items to it and return it to the caller ( mStrings = searchInfo();)

    In both the cases above, it assumes you know the length of the array (so you can initialize it). You could use an ArrayList instead of a String array since those can grow dynamically. You can then convert the arrayList to an array with:

    yourArrayList.toArray(mStrings);
    

    as long as you’ve initialize mStrings to something non-null (i.e. mStrings = new String[1];)

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

Sidebar

Related Questions

I have id values for products that I need store. Right now they are
I need to store a lot of data coming in from a server into
I need to store a char array inside a class and then return it.
I have an ASP.NET page (WebForm) on which I set the content of a
I am new to JQuery and need som direction. I have created a page
I need to modify a (xml-)file from Apache Ant. loadfile task allows to load
I need to store various info about some movies, books, games, and maybe other
I need to store IP address in the most compact way possible, searching is
I need to store up to tens or even hundreds of millions of pieces
I need to store a series of configuration values in a database. A couple

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.