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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:17:22+00:00 2026-06-01T12:17:22+00:00

I’m a novice programmer and I’m trying to learn Android coding using Eclipse. This

  • 0

I’m a novice programmer and I’m trying to learn Android coding using Eclipse.
This is my first time using StackOverflow.

Just for tutorial purposes, I want to make a simple Animal Encyclopedia.

So in my Home class, there are some buttons: “Dog”, “Cat”, “Bird”, etc. When I click the button, it will bring me to the same layout but of course with different content.

  • So I created a class named AnimalData that holds the
    ArrayList<Integer> to store R.drawable.xxx and ArrayList<String>
    to store the text that I will put below the picture (like “Bulldog”
    or “Husky”)

  • Then I created a class named ChangeContent to set all those drawable
    and text to the XML

  • But whenever I click the button, it results in Stopped Unexpectedly Error

Below are the shortened Home class, The “crash-maker” isn’t here. I have checked the whole code line per line using Thread.sleep(2000), so if my app crashes before 2 second, the error is before the sleep() code and vice versa.

public class Home extends Activity implements OnClickListener{
    Button dog, cat, bird;
    AnimalData ad;
    ChangeContent cc;

    private ArrayList<Integer> drawable;
    private ArrayList<String> title;

public Home(){
    ad = new AnimalData();
    cc = new ChangeContent(ad);
    drawable = new ArrayList<Integer>();
    title = new ArrayList<String>()
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    //set the findViewById for all the buttons
    //set onClickListener() to all the buttons
}

public void onClick(View v) {
    switch (v.getId()){
    case R.id.bDog:
        drawable.add(R.drawable.xxx);
        drawable.add(R.drawable.yyy);
        title.add("Bulldog");
        title.add("Husky");
        break;
    case R.id.Cat:
        //same
        break;
    case R.id.bBird:
        //same
        break;
    }
    ad.setDrawable(drawable);
    ad.setTitle(title);
    Intent i = new Intent("animal.ChangeContent"); //from Manifest
    startActivity(i);
}
}

The AnimalData is just a typical getter setter, so I will just skip the code for that

The error is right after ChangeContent started because even when I put the sleep() on the first line of constructor, it doesn’t have any effect.

public class ChangeContent extends Activity {

    TextView title1, title2;
    ImageView pic1, pic2;
    private ArrayList<Integer> drawable;
    private ArrayList<String> title;

public ChangeContent(AnimalData data){
    drawable = new ArrayList<Integer>();
    title = new ArrayList<String>();
    drawable = data.getDrawable();
    title = data.getTitle();
}
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.animal_info);

    //findViewById for the TextView and ImageView
    //setText() for TextView and setImageResource() for ImageView
}
}

Sorry for the long question, I tried to make it as short as possible
Can you guys help me figure the error out?
Thanks before

  • 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-01T12:17:23+00:00Added an answer on June 1, 2026 at 12:17 pm

    You are trying to get arraylist from intent, whereas you are not putting putStringArrayList and putIntegerArrayList methods.

    putIntegerArrayListExtra(String name, ArrayList<Integer> value)
    
    putStringArrayListExtra(String name, ArrayList<String> value)
    

    so Change calling activity to following:

    Intent i = new Intent(Home.this, ChangeContent.class); //from Manifest
    i.putIntegerArrayListExtra("drawables", drawable);
    i.putStringArrayListExtra("titles", titles);
    startActivity(i);
    

    and get data from intent in onCreate method by following methods:
    getIntegerArrayListExtra, and getStringArrayListExtra

    you also can do following by making contentChanged method to static, by this you wont need to do much changes in your application code, just do following:

    public class ChangeContent extends Activity {
    
        TextView title1, title2;
        ImageView pic1, pic2;
        private static ArrayList<Integer> drawable;
        private static ArrayList<String> title;
    
    public static ChangeContent(AnimalData data){
        drawable = new ArrayList<Integer>();
        title = new ArrayList<String>();
        drawable = data.getDrawable();
        title = data.getTitle();
    }
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.animal_info);
    
        //findViewById for the TextView and ImageView
        //setText() for TextView and setImageResource() for ImageView
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
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
I have just tried to save a simple *.rtf file with some websites and
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
Basically, what I'm trying to create is a page of div tags, each has

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.