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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:19:33+00:00 2026-06-15T20:19:33+00:00

I get in a lot of errors for my app about this, im new

  • 0

I get in a lot of errors for my app about this, im new in coding so I would appreciate some help.

I have an app with some images that the user can set as wallpapers, the images are in drawable and I have them in a HorizontalScrollView and I have also a ImageView that shows the selected images.

This is how my Main.java looks:

public class Main extends Activity implements OnClickListener {

ImageView display;
int wallPaper;
private AdView adView;
Bitmap setWall2;
Bitmap setWall3;

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


    /* START OF AdMob */

    // Create the adView
    adView = new AdView(this, AdSize.BANNER, "***************");

    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    TableRow layout = (TableRow)findViewById(R.id.adView);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());

    /* END OF AdMob */


    wallPaper = R.drawable.image1;

    display = (ImageView) findViewById(R.id.iViewMain);
    ImageView image1 = (ImageView) findViewById(R.id.image1);
    ImageView image2 = (ImageView) findViewById(R.id.image2);
    ImageView image3 = (ImageView) findViewById(R.id.image3);
    ImageView image4 = (ImageView) findViewById(R.id.image4);
    ImageView image5 = (ImageView) findViewById(R.id.image5);
    ImageView image6 = (ImageView) findViewById(R.id.image6);
    ImageView image7 = (ImageView) findViewById(R.id.image7);
    ImageView image8 = (ImageView) findViewById(R.id.image8);
    ImageView image9 = (ImageView) findViewById(R.id.image9);
    ImageView image10 = (ImageView) findViewById(R.id.image10);
    ImageView image11 = (ImageView) findViewById(R.id.image11);
    ImageView image12 = (ImageView) findViewById(R.id.image12);
    ImageView image13 = (ImageView) findViewById(R.id.image13);

    Button setWall = (Button) findViewById(R.id.setWall);

    image1.setOnClickListener(this);
    image2.setOnClickListener(this);
    image3.setOnClickListener(this);
    image4.setOnClickListener(this);
    image5.setOnClickListener(this);
    image6.setOnClickListener(this);
    image7.setOnClickListener(this);
    image8.setOnClickListener(this);
    image9.setOnClickListener(this);
    image10.setOnClickListener(this);
    image11.setOnClickListener(this);
    image12.setOnClickListener(this);
    image13.setOnClickListener(this);

    setWall.setOnClickListener(this);

}

@SuppressWarnings("deprecation")
public void onClick(View v) {
    // TODO Auto-generated method stub

    switch (v.getId()) {
    case R.id.image1:
        display.setImageResource(R.drawable.image1);
        wallPaper = R.drawable.image1;
        break;
    case R.id.image2:
        display.setImageResource(R.drawable.image2);
        wallPaper = R.drawable.image2;
        break;
    case R.id.image3:
        display.setImageResource(R.drawable.image3);
        wallPaper = R.drawable.image3;
        break;
    case R.id.image4:
        display.setImageResource(R.drawable.image4);
        wallPaper = R.drawable.image4;
        break;
    case R.id.image5:
        display.setImageResource(R.drawable.image5);
        wallPaper = R.drawable.image5;
        break;
    case R.id.image6:
        display.setImageResource(R.drawable.image6);
        wallPaper = R.drawable.image6;
        break;
    case R.id.image7:
        display.setImageResource(R.drawable.image7);
        wallPaper = R.drawable.image7;
        break;
    case R.id.image8:
        display.setImageResource(R.drawable.image8);
        wallPaper = R.drawable.image8;
        break;
    case R.id.image9:
        display.setImageResource(R.drawable.image9);
        wallPaper = R.drawable.image9;
        break;
    case R.id.image10:
        display.setImageResource(R.drawable.image10);
        wallPaper = R.drawable.image10;
        break;
    case R.id.image11:
        display.setImageResource(R.drawable.image11);
        wallPaper = R.drawable.image11;
        break;
    case R.id.image12:
        display.setImageResource(R.drawable.image12);
        wallPaper = R.drawable.image12;
        break;
    case R.id.image13:
        display.setImageResource(R.drawable.image13);
        wallPaper = R.drawable.image13;
        break;
    case R.id.setWall:

        InputStream setWall3 = getResources().openRawResource(wallPaper);
        Bitmap setWall2 = BitmapFactory.decodeStream(setWall3);
        try {
            getApplicationContext().setWallpaper(setWall2);
            Context context = getApplicationContext();
            CharSequence text = "Wallpaper set!";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0);
            toast.show();
        } catch(IOException e) {
            e.printStackTrace();
        }

        break;

    }
    System.gc();
}


@Override
protected void onResume() {
    // TODO Auto-generated method stub
    System.gc();
    super.onResume();

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    display = null;
    setWall2 = null;
    setWall3 = null;
    System.gc();
    super.onPause();
}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub

    ImageView image1 = (ImageView) findViewById(R.id.image1);
    image1.setImageDrawable(null);
    ImageView image2 = (ImageView) findViewById(R.id.image2);
    image2.setImageDrawable(null);
    ImageView image3 = (ImageView) findViewById(R.id.image3);
    image3.setImageDrawable(null);
    ImageView image4 = (ImageView) findViewById(R.id.image4);
    image4.setImageDrawable(null);
    ImageView image5 = (ImageView) findViewById(R.id.image5);
    image5.setImageDrawable(null);
    ImageView image6 = (ImageView) findViewById(R.id.image6);
    image6.setImageDrawable(null);
    ImageView image7 = (ImageView) findViewById(R.id.image7);
    image7.setImageDrawable(null);
    ImageView image8 = (ImageView) findViewById(R.id.image8);
    image8.setImageDrawable(null);
    ImageView image9 = (ImageView) findViewById(R.id.image9);
    image9.setImageDrawable(null);
    ImageView image10 = (ImageView) findViewById(R.id.image10);
    image10.setImageDrawable(null);
    ImageView image11 = (ImageView) findViewById(R.id.image11);
    image11.setImageDrawable(null);
    ImageView image12 = (ImageView) findViewById(R.id.image12);
    image12.setImageDrawable(null);
    ImageView image13 = (ImageView) findViewById(R.id.image13);
    image13.setImageDrawable(null);

    display = null;
    setWall2 = null;
    setWall3 = null;
    System.gc();
    super.onDestroy();
}

}

Thanks!

  • 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-15T20:19:34+00:00Added an answer on June 15, 2026 at 8:19 pm

    Are you following the tutorials on Youtube? I started with some of those too, but learned some pretty inefficient coding practices in regards to composite views/ViewGroups. First, you really shouldn’t be creating so many imageView objects statically and setting individual listeners to each. This is REALLY REALLY bad practice. So avoid this approach altogether. My point is, get used to doing things the correct way from now, so you won’t have to come back and change/re-learn/bang your head against the wall too much :), like I did!

    You need to use a GridView, ListView, ViewFlipper, Gallery or another type of container that was built specifically for this purpose. You will constantly run into bitmap and OOM errors while using your current approach

    TUTORIAL ON GRIDVIEW

    TUTORIAL ON GALLERY

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

Sidebar

Related Questions

I have some code that at one part will get executed a lot, and
I may get some heat for this question because there are a lot out
We have a lot of queries select * from tbl_message that get stuck on
I know that there are a lot of questions and answers exactly about this
I have a .png file I would like to use in my app. This
I have read a lot of topics about this error message but I can't
I'm trying make it work. And I have a lot of errors, but this
Yesterday I testet a lot on my device. Suddenly I get this error message
I try to do an app but I get a lot of crash an
UPDATE 1/31/10 : Since this thread continues to get a lot of views...I am

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.