Results 1 to 3 of 3
  1. #1
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default toast crashing my app

    I am tring to create a toast in my app. In my button I create (I create this outside of the main activity)

    I call the toast in this way
    Java Code:
    		CharSequence message = "Audio Bufferig, to cancle please click the back button";
    		int duration = Toast.LENGTH_SHORT;
    		
    		Toast userAlert = Toast.makeText(activity, message, duration);
    		userAlert.show();
    		
    		startAudio.start();
    To set the context object (as seen in the code above) I have the following method
    Java Code:
    	public void setContext(Context context) {
    		this.context = context;
    		try {
    			activity = (Activity) context;
    		}
    		catch (ClassCastException e) {
    			Log.e("MyApp","We are boned could not cast the context to an activity");
    		}
    	}
    I assume this is an activity object as there is only one place I call this method (and that is from the Main Activity see code below, as called from the onCreate in the MainActivity.)
    Java Code:
                    MediaControl playButton = MediaControl.getMediaControl(this);
    		playButton.setContext(this);
    
    		this.mediaControl.setOnClickListener(playButton);
    There is all the pertinent code above When I try to run my code (and press the playButton) I get the following Exception: RuntimeException: Can't create handler inside thread that has not called Looper.prepare();
    The crash happens on the "Toast userAlert = Toast.makeText(activity, message, duration);" line.

    I will also note that this is in a separate thread then the UI of the app as the media is coming off the internet and I don't want to have the UI stalled when I pull the media.
    Last edited by Drun; 01-16-2012 at 12:03 AM.
    Michael P. O'Connor
    http://www.mikeoconnor.net

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: toast crashing my app


  3. #3
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default Re: toast crashing my app

    eRaaaa, thanks, admittedly not the answer I wanted, but lets me get done what I want done, I just moved the Toast out of the button thread, and moved it in the the service thread that plays the audio.

    Long and short, thanks eRaaaa, it is appreciated. Now how do I mark a thread as answered/solved.
    Last edited by Drun; 01-16-2012 at 04:10 AM.
    Michael P. O'Connor
    http://www.mikeoconnor.net

Similar Threads

  1. Why is my Comparator Crashing?
    By dragstang86 in forum New To Java
    Replies: 5
    Last Post: 10-05-2011, 04:51 AM
  2. Method crashing
    By TyCox94 in forum AWT / Swing
    Replies: 2
    Last Post: 09-25-2011, 05:01 AM
  3. Crashing code
    By ke5awf in forum Advanced Java
    Replies: 2
    Last Post: 08-23-2011, 10:27 AM
  4. the eclipse is crashing
    By miko5054 in forum Eclipse
    Replies: 1
    Last Post: 06-07-2010, 07:11 PM
  5. While loop crashing?
    By ToplessGrunt in forum New To Java
    Replies: 6
    Last Post: 10-20-2008, 11:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •