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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:12:36+00:00 2026-06-16T07:12:36+00:00

I’m parsing a JSON response from a weather feed and the data I receive

  • 0

I’m parsing a JSON response from a weather feed and the data I receive includes a url to an icon that corresponds with the conditions, then I display that icon in an ImageView. I was able to make this work in a sandbox app before moving the package of code into my project.

In the main project I use the latest versions of ActionBarSherlock and SlidingMenu for navigation, and both apps make use of Android-Async-Http-Client but now it has a fatal NullPointerException when trying to display the icon from that url in the ImageView. I don’t think this is caused by any of the libraries.

I’ve seen that sliding menus mostly consist of some type of ListView handled with an Adapter, which I’m doing in a portion of my sliding menu. But the only clue I have is that it crashes because now it’s an off-screen UI element that I’m trying to work with. Does it matter that I have something in my sliding menu that isn’t handled by an Adapter? I can’t imagine much else is different but maybe you guys some clue of what I’m missing. Hopefully it isn’t something basic that I’m just forgetting… or maybe it is 🙂

Alright, thanks for any ideas.

wireframe

public class MainActivity extends SlidingActivity implements
        ActionBar.OnNavigationListener {
    final String TAG = "MainActivity";
    private TextView mSelected;
    private String[] mLocations;
    ImageLoader imageLoader;
    ImageView weatherIcon;

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

        imageLoader = new ImageLoader(this);

        wireViews();

        getWeatherFeed();

        Context context = getSupportActionBar().getThemedContext();
        ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(
                context, R.array.activities, R.layout.sherlock_spinner_item);
        list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        getSupportActionBar().setListNavigationCallbacks(list, this);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        // set the Behind View
        setBehindContentView(R.layout.menu_frame);

        // SlidingMenu
        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setSlidingActionBarEnabled(false);

        ListView menuList = (ListView) findViewById(R.id.menuList);
        SlidingMenuItem[] data = new SlidingMenuItem[] {
                new SlidingMenuItem("Item1 Label", "Item1 Sub-label",getResources().getDrawable(R.drawable.item1)),
                new SlidingMenuItem("Item2 Label", "Item2 Sub-Label",getResources().getDrawable(R.drawable.item2)) };

        MenuAdapter adapter = new MenuAdapter(this, R.layout.sliding_menu_item,
                data);
        menuList.setAdapter(adapter);
    }

    private void updateWeatherUi(String degreeText, String descriptionText,
            String iconUrl) {
        Log.i(TAG, "Updating UI elements...");

        if (imageLoader != null) {
            Log.i(TAG, "IMAGE_LOADER NOT NULL!!!");
        }
        imageLoader.DisplayImage(iconUrl, weatherIcon);   // FIXME: FATAL CRASH HERE !!!
    }

    /** Build a Weather object from the JSON response.
     * @throws JSONException */
    private void buildWeatherObject(String rawResponse) throws JSONException {
        Log.i(TAG, "Building Weather ojbect...");

        JSONObject baseObject = new JSONObject(rawResponse);
        JSONObject data = new JSONObject(baseObject.getString(Key.DATA));

        JSONArray conditionArray = new JSONArray(
                data.getString(Key.CURRENT_CONDITION));

        for (int i = 0; i < conditionArray.length(); i++) {
            JSONObject conditionElement = new JSONObject(
                    conditionArray.getString(i));
            weather = new Weather();
            weather.tempMaxF = conditionElement.getString(Key.TEMP_F);

            JSONArray weatherDescriptionArray = new JSONArray(
                    conditionElement.getString(Key.W_WEATHER_DESC));
            for (int j = 0; j < weatherDescriptionArray.length(); j++) {
                JSONObject weatherDescriptionElement = new JSONObject(
                        weatherDescriptionArray.getString(j));
                weather.weatherDesc = weatherDescriptionElement
                        .getString(Key.VALUE);
            }

            JSONArray weatherIconArray = new JSONArray(
                    conditionElement.getString(Key.WEATHER_ICON_URL));
            for (int j = 0; j < weatherIconArray.length(); j++) {
                JSONObject weatherIconElement = new JSONObject(
                        weatherIconArray.getString(j));
                weather.weatherIconUrl = weatherIconElement
                        .getString(Key.VALUE);
                Log.i(TAG, weather.weatherIconUrl);
            }
            conditionElement = null;

            updateWeatherUi(weather.tempMaxF, weather.weatherDesc,
                    weather.weatherIconUrl);
        }
    }

    /** Asynchronously request and receive weather feed data. */
    private void getWeatherFeed() {
        Log.i(TAG, "Getting asynchronous JSON feed...");

        AsyncHttpClient client = new AsyncHttpClient();
        client.get(WEATHER_FEED_URL, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String response) {
                try {
                    buildWeatherObject(response);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Throwable arg0, String arg1) {
                super.onFailure(arg0, arg1);
                showToast("Sorry, the weather forecast wasn't available just then.");
            }
        });
    }

    private void wireViews() {
        Log.i(TAG, "Wiring UI elements...");
        mSelected = (TextView) findViewById(R.id.text);
        mLocations = getResources().getStringArray(R.array.activities);
        weatherIcon = (ImageView) findViewById(R.id.weatherIconView);
    }

12-21 01:01:11.130: I/MainActivity(28502): Building Weather ojbect...
12-21 01:01:11.170: I/MainActivity(28502): http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png
12-21 01:01:11.170: I/MainActivity(28502): Updating UI elements...
12-21 01:01:11.170: I/MainActivity(28502): IMAGE_LOADER NOT NULL!!!
12-21 01:01:11.170: D/AndroidRuntime(28502): Shutting down VM
12-21 01:01:11.170: W/dalvikvm(28502): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
12-21 01:01:11.180: E/AndroidRuntime(28502): FATAL EXCEPTION: main
12-21 01:01:11.180: E/AndroidRuntime(28502): java.lang.NullPointerException
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.eric.app.networkxml.ImageLoader.DisplayImage(ImageLoader.java:42)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.eric.app.MainActivity.updateWeatherUi(MainActivity.java:129)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.eric.app.MainActivity.buildWeatherObject(MainActivity.java:172)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.eric.app.MainActivity.access$0(MainActivity.java:137)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.eric.app.MainActivity$1.onSuccess(MainActivity.java:195)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.loopj.android.http.AsyncHttpResponseHandler.handleSuccessMessage(AsyncHttpResponseHandler.java:160)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:173)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.loopj.android.http.AsyncHttpResponseHandler$1.handleMessage(AsyncHttpResponseHandler.java:85)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at android.os.Looper.loop(Looper.java:150)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at android.app.ActivityThread.main(ActivityThread.java:4263)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at java.lang.reflect.Method.invokeNative(Native Method)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at java.lang.reflect.Method.invoke(Method.java:507)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-21 01:01:11.180: E/AndroidRuntime(28502):    at dalvik.system.NativeStart.main(Native Method)

Yikes! I tried to post a “snippet” but maybe I should’ve posted the complete file…

  • 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-16T07:12:37+00:00Added an answer on June 16, 2026 at 7:12 am

    Putting the updateWeatherUi() logic at inside the end of buildWeatherObject() fixed this for me.

    The problem is that I’m still not sure what was occurring here previously. The Logs were showing the proper data right up to the point of imageLoader.DisplayImage(String, ImageView) in my original code but I kept crashing there with NullPointerException.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using jsonparser to parse data and images obtained from json response. When
I am using JSon response to parse title,date content and thumbnail images and place
I am confused How to use looping for Json response Array in another Array.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.