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

  • Home
  • SEARCH
  • 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 8528823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:53:20+00:00 2026-06-11T08:53:20+00:00

I’m trying to teach myself to create android app in eclipse. My project is

  • 0

I’m trying to teach myself to create android app in eclipse. My project is to create an app that shows pictures from an tumblr account.

I found som existing code from and similar app for twitter.

I have tried to alter the code in the way where i thought i my app for tumblr could run. After spending hours trying to figure out whats wrong and why the emulator keeps crashing i hope to find some help here.

My code looks like this:

package com.example.example;

public class Example extends Activity {

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

    ArrayList<Tweet> tweets = getTweets("my api key");

    ListView listView = (ListView) findViewById(R.id.ListViewId);
    listView.setAdapter(new UserItemAdapter(this, R.layout.listitem, tweets));
}

public class UserItemAdapter extends ArrayAdapter<Tweet> {
    private ArrayList<Tweet> tweets;

    public UserItemAdapter(Context context, int imageViewResourceId,
            ArrayList<Tweet> tweets) {
        super(context, imageViewResourceId, tweets);
        this.tweets = tweets;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.listitem, null);
        }

        Tweet tweet = tweets.get(position);
        if (tweet != null) {

            ImageView image = (ImageView) v.findViewById(R.id.avatar);

            if (image != null) {
                image.setImageBitmap(getBitmap(tweet.image_url));
            }
        }
        return v;
    }
}

public Bitmap getBitmap(String bitmapUrl) {
    try {
        URL url = new URL(bitmapUrl);
        return BitmapFactory.decodeStream(url.openConnection()
                .getInputStream());
    } catch (Exception ex) {
        return null;
    }
}

public ArrayList<Tweet> getTweets(String key) {
    String searchUrl = "http://api.tumblr.com/v2/blog/www.richkidsofinstagram.tumblr.com/posts?api_key="
            + key;

    ArrayList<Tweet> tweets = new ArrayList<Tweet>();

    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(searchUrl);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    String responseBody = null;
    try {
        responseBody = client.execute(get, responseHandler);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    JSONObject jsonObject = null;
    JSONParser parser = new JSONParser();

    try {
        Object obj = parser.parse(responseBody);
        jsonObject = (JSONObject) obj;

    } catch (Exception ex) {
        Log.v("TEST", "Exception: " + ex.getMessage());
    }

    JSONArray arr = null;

    try {
        Object j = jsonObject.get("results");
        arr = (JSONArray) j;
    } catch (Exception ex) {
        Log.v("TEST", "Exception: " + ex.getMessage());
    }

    for (Object t : arr) {
        Tweet tweet = new Tweet(((JSONObject) t).get("photos").toString());
        tweets.add(tweet);
    }

    return tweets;
}

public class Tweet {

    public String image_url;

    public Tweet(String url) {

        this.image_url = url;
    }
}

}

The log in eclipse gives me these errors

08-30 15:58:34.549: D/dalvikvm(330): GC_FOR_MALLOC freed 1827 objects / 187744 bytes in 60ms
08-30 15:58:34.879: D/dalvikvm(330): GC_FOR_MALLOC freed 9343 objects / 277800 bytes in 60ms
08-30 15:58:34.969: D/AndroidRuntime(330): Shutting down VM
08-30 15:58:34.969: W/dalvikvm(330): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-30 15:58:34.989: E/AndroidRuntime(330): FATAL EXCEPTION: main
08-30 15:58:34.989: E/AndroidRuntime(330): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.example/com.example.example.Example}: java.lang.NullPointerException
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.os.Looper.loop(Looper.java:123)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-30 15:58:34.989: E/AndroidRuntime(330):  at java.lang.reflect.Method.invokeNative(Native Method)
08-30 15:58:34.989: E/AndroidRuntime(330):  at java.lang.reflect.Method.invoke(Method.java:521)
08-30 15:58:34.989: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-30 15:58:34.989: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-30 15:58:34.989: E/AndroidRuntime(330):  at dalvik.system.NativeStart.main(Native Method)
08-30 15:58:34.989: E/AndroidRuntime(330): Caused by: java.lang.NullPointerException
08-30 15:58:34.989: E/AndroidRuntime(330):  at com.example.example.Example.getTweets(Example.java:119)
08-30 15:58:34.989: E/AndroidRuntime(330):  at com.example.example.Example.onCreate(Example.java:35)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-30 15:58:34.989: E/AndroidRuntime(330):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-30 15:58:34.989: E/AndroidRuntime(330):  ... 11 more

Anybody that can spot the problem?
Any help is highly appriciated!

  • 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-11T08:53:21+00:00Added an answer on June 11, 2026 at 8:53 am

    hard to tell without line numbers, but try this in getTweets instead:

    for ( int i=0 ; i<arr.length() ; i++ ) {
        Tweet tweet = new Tweet( arr.getJSONObject( i ).getString( "photos" ) );
        tweets.add( tweet );
    }
    

    also, you’ll need some exception handling around it


    Related to JSONArray undefined methods:

    Try editing your code which is creating the jsonArray:

    try {
        arr = jsonObject.getJSONArray("results");
    } catch (Exception ex) {
        Log.v("TEST", "Exception: " + ex.getMessage());
    }
    

    try to use the specific methods when possible, instead of the generic get()

    Not sure if this will help with the errors, but it will help keep the code a bit cleaner.

    Update

    It seems the original code was for JSONSimple.

    Android comes with JSON parsing, so there isn’t much point in using this, unless you need something specific from it.

    To parse using the Android default:

    import org.json.JSONObject;
    import org.json.JSONArray;
    

    –

    JSONObject jsonObject = new JSONObject(responseBody);
    

    and remove the existing JSONParser code.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.