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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:50:06+00:00 2026-06-04T13:50:06+00:00

This work is based on Patel Deval example. The application intends to load ImageSwicher

  • 0

This work is based on Patel Deval example.

The application intends to load ImageSwicher Content based on selected radio button. During runtime uncaught exception (group=0x4001d800) is printed. Where am I wrong? Here is the code

private Gallery gallery;

private RadioGroup rdgSelection;

private ImageSwitcher isSwitcher;

private Boolean flag = true;

private int radioCheckedId = -1; //no radio button

//arrays of image for alerts

private Integer[] pics ={ R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,R.drawable.e,R.drawable.exit, R.drawable.plan, R.drawable.icon, R.drawable.plan };

private Integer[] others = {R.drawable.exit, R.drawable.plan, R.drawable.icon, R.drawable.plan,R.drawable.c };



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sendalert);

    gallery = (Gallery)findViewById(R.id.imgGallery);

    isSwitcher = (ImageSwitcher)findViewById(R.id.ImgSwith);

    rdgSelection = (RadioGroup)findViewById(R.id.radEvent);


    isSwitcher = setFactory(this);

    //get radio button id

    rdgSelection.check(rdgSelection.getChildAt(rdgSelection.getChildCount() - 1).getId());

    if (rdgSelection.getCheckedRadioButtonId()==R.id.radBtnAccident){

        flag = true;


                    gallery.setAdapter(new ImageAdapter(MsgToWeb.this));

    }else{

        flag=false;

        gallery.setAdapter(new ImageAdapter(MsgToWeb.this));

    }

     rdgSelection.setOnCheckedChangeListener(new OnCheckedChangeListener() {


            public void onCheckedChanged(RadioGroup group, int checkedId) {

                gallery.setAdapter(new ImageAdapter(MsgToWeb.this));

                if (rdgSelection.getCheckedRadioButtonId() == R.id.radBtnAccident)

                    flag = true;

                else

                    flag = false;
            }
        });

        gallery.setOnItemSelectedListener(this);

}


private ImageSwitcher setFactory(MsgToWeb msgToWeb) {
    // TODO Auto-generated method stub
    return null;
}


public class ImageAdapter extends BaseAdapter {

    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c; 

    }

    public Object getItemId() {
        // TODO Auto-generated method stub
        return null;
    }

    public int getCount() {
        //return num of arrays
        if (flag)
            return pics.length;
        else
            return others.length;
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        ImageView i = new ImageView(mContext);

        if(flag)
            i.setImageResource(pics[position]);
        else
            i.setImageResource(others[position]);

        return i;   
    }

}

public View makeView() {
    // TODO Auto-generated method stub

    ImageView iView = new ImageView(this);

    iView.setBackgroundColor(0xFF000000);

    iView.setScaleType(ImageView.ScaleType.FIT_CENTER);

    iView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

    return iView;

}


public void onItemSelected(AdapterView<?> arg0, View v, int position,long id) {
    // TODO Auto-generated method stub


    if(flag)
        isSwitcher.setImageResource(pics[position]);
    else
        isSwitcher.setImageResource(others[position]);


}


public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}


}

Here the log

05-24 10:07:03.394: W/dalvikvm(321): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-24 10:07:03.404: E/AndroidRuntime(321): FATAL EXCEPTION: main
05-24 10:07:03.404: E/AndroidRuntime(321): java.lang.NullPointerException
05-24 10:07:03.404: E/AndroidRuntime(321):  at com.moLaroute.mu.MsgToWeb.onItemSelected(MsgToWeb.java:147)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.widget.AdapterView.access$200(AdapterView.java:42)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.os.Handler.handleCallback(Handler.java:587)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.os.Looper.loop(Looper.java:123)
05-24 10:07:03.404: E/AndroidRuntime(321):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-24 10:07:03.404: E/AndroidRuntime(321):  at java.lang.reflect.Method.invokeNative(Native Method)
05-24 10:07:03.404: E/AndroidRuntime(321):  at java.lang.reflect.Method.invoke(Method.java:521)
05-24 10:07:03.404: E/AndroidRuntime(321):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-24 10:07:03.404: E/AndroidRuntime(321):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-24 10:07:03.404: E/AndroidRuntime(321):  at dalvik.system.NativeStart.main(Native Method)
05-24 10:07:07.014: I/Process(321): Sending signal. PID: 321 SIG: 9
  • 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-04T13:50:08+00:00Added an answer on June 4, 2026 at 1:50 pm

    isSwitcher = setFactory(this);

    ->

    setFactory returns null

    ->

    if(flag)
    isSwitcher.setImageResource(pics[position]);
    else
    isSwitcher.setImageResource(others[position]);

    throws NPE here because isSwitcher is null

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

Sidebar

Related Questions

I have a content scroller based on the great work at flowplayer. This has
Will this work for testing whether a value at position index exists or not,
Does this work in > iOS 5? .element { background: url(images/myImage.jpg) 50% 0 no-repeat
why doesn't this work? MsgBox(F6D8C47B-46E6-4E93-A393-00085ACA2242).ToString.Replace(-, )
Why does this work: List<?> list = new LinkedList<Integer>(); while this gives a type
why won't this work? function login(){ if(window.XMLHttpRequest){ ajax=new XMLHttpRequest(); }else if(window.ActiveXObject){ ajax=new ActiveXObject(Microsoft.XMLHTTP); }
Why won't this work? public static int[] GetListOfAllDaysForMonths() { static int[] MonthDays = new
Why doesn't this work? // spriteArray is an NSMutableArray int spriteWidth = [spriteArray objectAtIndex:0].contentSize.width;
Why doesn't this work <script src=jquery.js/> But this works <script src=jquery.js></script> ? Firefox 3.5.8
why does this work: def function1(): a = 10 def function2(): print a function2()

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.