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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:25:19+00:00 2026-05-26T22:25:19+00:00

Ok, facing the problem I can’t parse my data from inside the try{} to

  • 0

Ok, facing the problem I can’t parse my data from inside the try{} to something outside.
What is my goal to complete here…

The for-loop will run and add a string (img) to the array (image).
Actually it parses something to the array.. but I can’t get it outside the
try/catch-block. Can somebody help me with this?

Kind regards!

        protected void onPostExecute(Void unused)
        {
                try
                {           

                     jArray = new JSONArray(result);
                     String[] image = new String[jArray.length()];
                     Log.v("Crash Detect", "onPostExecute -> try");
                     JSONObject json_data=null;

                     for(int i=0;i<jArray.length();i++)
                     {
                         Log.v("Crash Detect", "onPostExecute -> forloop");
                        json_data = jArray.getJSONObject(i);


                        merk=json_data.getString("printerMerk");
                        type=json_data.getString("printerType");
                        content = json_data.getString("content");
                        img = json_data.getString("Img");



                        Arrays.fill(image, img);


                    } 
                 }
                 catch(JSONException e1)
                 {
                     Toast.makeText(getBaseContext(), "Niks gevonden" ,Toast.LENGTH_LONG).show();
                 } 
                catch (ParseException e1) 
                {
                       e1.printStackTrace();
                }   



            dialog.dismiss();


            Button home = (Button) findViewById(R.id.home);
            Button printerType = (Button) findViewById(R.id.printerType);

            home.setText(merk);
            printerType.setText(type);


            list=(ListView)findViewById(R.id.list);
            adapter=new LazyAdapter(doc.this, image);
            list.setAdapter(adapter);
        }
  • 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-26T22:25:19+00:00Added an answer on May 26, 2026 at 10:25 pm

    Declare the variable outside the try/catch and then check if it is set when you want to use it.

      protected void onPostExecute(Void unused)
      {
           String[] image = null;
            try
            {           
                jArray = new JSONArray(result);
                image = new String[jArray.length()];
                // extra code
    
            }
            catch(JSONException e1)
            {
                Toast.makeText(getBaseContext(), "Niks gevonden" ,Toast.LENGTH_LONG).show();
            } 
            catch (ParseException e1) 
            {
                e1.printStackTrace();
            }   
            // perform extra code
    
            // NOTE: be sure to check image before using it as it might be null if exception is thrown!
            if(image != null)
            {
                // use image 
                adapter=new LazyAdapter(doc.this, image);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have facing problem in listview i am getting data from server and after
I am facing a problem to call https from Android. Can any one please
I'm facing this problem again and again, but can't find any solution (except mine,
I'm facing a problem with my scrollview (horizontal, paging enabled, can be 50 pages
I'm facing what I think is a simple problem with Hibernate, but can't solve
I'm facing a problem with IE6. I took the toggle function from this website
I am migrating an applciation from windows to linux. I am facing problem with
I am facing some problem in generating oauth_signature for flickr api. Can you please
Evening, I'm facing a small problem which I can't get fixed. I'm having one
Im facing problem with poor performance of css prompting mechanism. Can I dissable this

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.