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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:21+00:00 2026-05-24T23:58:21+00:00

I having some problem with changing the resource of an imageview when i click

  • 0

I having some problem with changing the resource of an imageview when i click an item.
I know that any graphical updates should be done in the UI thread and I have tried two ways without success:

…my code WITHOUT a handler:

public class AvatarPicker extends Activity {

ImageView iv; 

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

public void clicked(View v){
    iv = (ImageView) findViewById(v.getId());
    iv.setImageResource(R.drawable.avatar_0);
}}

…my code WITH a handler and runnable:

public class AvatarPicker extends Activity {

ImageView iv;
private Handler mHandler;

private Runnable updateImg = new Runnable() {
    @Override
    public void run() {
       iv.setImageResource(R.drawable.avatar_0);
    }
};

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

    mHandler = new Handler(){};

}

public void clicked(View v){
    iv = (ImageView) findViewById(v.getId());
    mHandler.post(updateImg);
}

}

I have set the onClick in the layout XML to “clicked” and given all the clickable images an unique id. When i put Log.d() almost everywhere in the code i notice that it halts at the iv.setImageResource(R.drawable.avatar_0); command.

Can someone help me out here please? What am i missing? Thanks

Here is some additional LOGCAT info:

06-17 19:23:09.877: INFO/ActivityManager(1184): Process com.google.android.apps.maps:FriendService (pid 4580) has died.
06-17 19:23:09.907: INFO/ActivityManager(1184): Displayed activity weldeborn.avatar/.AvatarPicker: 1008 ms (total 1008 ms)
06-17 19:23:10.077: DEBUG/ddm-heap(4602): Got feature list request
06-17 19:23:10.157: DEBUG/dalvikvm(1701): GC freed 2115 objects / 112440 bytes in 99ms
06-17 19:23:12.607: DEBUG/AndroidRuntime(4602): Shutting down VM
06-17 19:23:12.607: WARN/dalvikvm(4602): threadid=3: thread exiting with uncaught exception (group=0x40026160)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602): Uncaught handler: thread main exiting due to uncaught exception
06-17 19:23:12.617: ERROR/AndroidRuntime(4602): java.lang.NullPointerException
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at weldeborn.avatar.AvatarPicker$1.run(AvatarPicker.java:21)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at android.os.Handler.handleCallback(Handler.java:587)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at android.os.Looper.loop(Looper.java:123)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at android.app.ActivityThread.main(ActivityThread.java:4370)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at java.lang.reflect.Method.invokeNative(Native Method)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at java.lang.reflect.Method.invoke(Method.java:521)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602):     at dalvik.system.NativeStart.main(Native Method)
06-17 19:23:12.627: ERROR/SemcCheckin(4602): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump
06-17 19:23:12.627: WARN/ActivityManager(1184): Unable to start service Intent { act=com.sonyericsson.android.jcrashcatcher.action.BUGREPORT_AUTO cmp=com.sonyericsson.android.jcrashcatcher/.JCrashCatcherService (has extras) }: not found
06-17 19:23:12.627: INFO/Process(1184): Sending signal. PID: 4602 SIG: 3
06-17 19:23:12.627: INFO/dalvikvm(4602): threadid=7: reacting to signal 3
06-17 19:23:12.627: ERROR/dalvikvm(4602): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
06-17 19:23:12.667: ERROR/SemcCheckin(1687): Get Crash Level : java.io.FileNotFoundException: /data/semc-checkin/crashdump
06-17 19:23:15.557: DEBUG/WifiService(1184): ACTION_BATTERY_CHANGED pluggedType: 2
06-17 19:23:17.547: DEBUG/WifiService(1184): ACTION_BATTERY_CHANGED pluggedType: 2
06-17 19:23:22.707: DEBUG/dalvikvm(1852): GC freed 5128 objects / 468256 bytes in 150ms

The first lines that are being orange/red is these three:

06-17 19:23:12.607: WARN/dalvikvm(4602): threadid=3: thread exiting with uncaught exception (group=0x40026160)
06-17 19:23:12.617: ERROR/AndroidRuntime(4602): Uncaught handler: thread main exiting due to uncaught exception
06-17 19:23:12.617: ERROR/AndroidRuntime(4602): java.lang.NullPointerException
  • 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-05-24T23:58:22+00:00Added an answer on May 24, 2026 at 11:58 pm

    The code in general is ok, you dont need a handler because you change the resource from the main activity.

    I think the problem is that you get the imageView from v.getId()

    Is the onclick on the imageView? You can directly ((ImageView)v).setImageResource(…) or get the image in the onCreate method

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

Sidebar

Related Questions

I'm having a problem with some code that used to work in PHP 4.X
I'm having a problem passing parameters that I think I should be able to
I'm having some problems changing the DataTemplate that is used for a TreeViewItem when
I am having an application that is changing some settings of another application (it
I'm having some problem with MKMapView / annotations / UINavigationController. Basically, i manage my
I am working on a windows form project and having some problem with UserControl
I'm having some difficulties with the following problem: I'm making a little game where
I've been having some difficulty in understanding the source of a problem. Below is
I am having some trouble with this code . The problem is when i
Hey, I'm having some difficulty with CSS and IE6 compatibility. URL : http://bit.ly/dlX7cS Problem

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.