-1

I use this code for reading a tag by a specific URL:

public static String ter(final String PRIVATE) {
    JsonParser parser = new JsonParser();
    try {
        Object obj = parser.parse(new FileReader("my url string"));
        JSONObject jsonObject = (JSONObject) obj;
        String event = (String) jsonObject.get("EVENT");
        return event;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return PRIVATE;
}

Then I set my subTitle with PRIVATE in this way:

getActionBar().setSubtitle("test"+ter(PRIVATE));

But when I run my app, in subTitle I read only text "test" with text "null" and it doesn't read the tag of JSON. Anyone has any idea? Is my code wrong?

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
dev_
  • 395
  • 1
  • 3
  • 16

2 Answers2

0

Because you may have not initializes your variable therefore it is pointing towards null values....

When ever we create object,either by calling that method or by initializing variable at declaration, we can avoid null pointer exception...

Please refer to this POST

Community
  • 1
  • 1
Iamat8
  • 3,888
  • 9
  • 25
  • 35
  • I Mohit. I have create PRIVATE variable before. String PRIVATE = null and i would like to set a tag json into this value – dev_ Aug 17 '15 at 13:52
  • If you performing this in your `Async Task` try to set your SubTitle in `onPostMethod` – Iamat8 Aug 18 '15 at 05:35
0

You are setting the subtitle to PRIVATE, but if your parsing succeeds, you're returningevent. You're also sending PRIVATE into this function, for some reason.

Tim
  • 2,089
  • 1
  • 12
  • 21