Hi James, logcat (the system log dumper) will be your new best friend. Try running it from a command line to see what caused your crash.
Cheers, James On Sat, Oct 10, 2009 at 10:58 PM, James Duncan <james.w.dun...@gmail.com>wrote: > Hi List > > I am just trying to write a simple app that plays an MP3 when one clicks on > an Image Button. > > I had the app starting up in the emulator fine but when I add the > MediaPlayer code I get the error: > > "Sorry! The application EasyButton (process com.example.helloandroid) has > stopped unexpectedly. Please Try Again" > > I assemble bits a pieces of code together so I might have done some thing > wrong, as I've never programmed in Java (well..anything) before. > > My Java (I left in my first attempts, commented out): > > EasyButton.java > > package com.example.helloandroid; > > import android.app.Activity; > import android.os.Bundle; > import android.media.MediaPlayer; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.ImageButton; > > //public class EasyButton extends Activity { > /** Called when the activity is first created. */ > // @Override > // public void onCreate(Bundle savedInstanceState) { > // super.onCreate(savedInstanceState); > // setContentView(R.layout.main); > > // final ImageButton button = (ImageButton) > findViewById(R.id.ImageButton); > // button.setOnClickListener(new OnClickListener() { > // public void onClick(View v) { > // // Perform action on clicks > // MediaPlayer mp = MediaPlayer.create(getBaseContext(), > R.raw.easy1); > // mp.start(); > // } > // }); > // } > //} > > public class EasyButton extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle icicle) { > super.onCreate(icicle); > setContentView(R.layout.main); > > final MediaPlayer mplayer = MediaPlayer.create(EasyButton.this, > R.raw.easy1); > > // PLAY button > ImageButton play = (ImageButton) > this.findViewById(R.id.ImageButton); > play.setOnClickListener(new OnClickListener() { > public void onClick(View arg0) { > > // mp.prepare(); > mplayer.start(); > } > }); > } > } > > main.xml > > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:layout_centerVertical="true" > android:layout_centerHorizontal="true" > > > <TextView > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:text="@string/hello" > android:textSize="14sp" > android:typeface="sans" > /> > > <ImageButton id="@+id/ImageButton" > android:src="@drawable/easybutton" > android:layout_gravity="center_horizontal|bottom" > android:layout_width="285px" > android:layout_height="372px" > /> > > </LinearLayout> > > The error console said everything is working ok. I'm using Eclipse 3.5.1. > with the Android Development Toolkit 0.9.3 (I just downloaded everything > today) on osX 10.5.6 > > These are just mis-mashed code snippets I've used to try and learn all of > this, so forgive me for any glaring mistakes. This is a great list to find > btw. Feel free to reply off list if this is a too big mess to deal with > here... > > Cheers > James > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---