Thanks Here is what I did.
Created Instance variable
protected Context context;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
//
Intent myIntent = null;
MediaPlayer bismiallh2 =null;
if(position==0){
Toast.makeText(Alphabet.this, "" + "Alif",Toast.LENGTH_SHORT).show();
bismiallh2 = MediaPlayer.create(context,R.raw.alif);
bismiallh2.start();
}
if(position==1){
Toast.makeText(Alphabet.this, "" + "Baaa",Toast.LENGTH_SHORT).show();
bismiallh2 = MediaPlayer.create(context,R.raw.alif);
bismiallh2.start();
}
}
});
When I click on the image I get an error.
Logcat
04-06 17:10:20.181: DEBUG/AndroidRuntime(495): Shutting down VM
04-06 17:10:20.181: WARN/dalvikvm(495): threadid=1:
thread exiting with uncaught exception (group=0x40015560)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): FATAL EXCEPTION: main
04-06 17:10:20.720: ERROR/AndroidRuntime(495): java.lang.NullPointerException
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.media.MediaPlayer.create(MediaPlayer.java:662)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at com.bismiallah.alphabet.Alphabet$1.onItemClick(Alphabet.java:42)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.os.Handler.handleCallback(Handler.java:587)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.os.Handler.dispatchMessage(Handler.java:92)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.os.Looper.loop(Looper.java:123)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at java.lang.reflect.Method.invoke(Method.java:507)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-06 17:10:20.720: ERROR/AndroidRuntime(495): at dalvik.system.NativeStart.main(Native Method)
04-06 17:10:20.729: WARN/ActivityManager(62): Force finishing activity com.bismiallah.alphabet/.Alphabet
04-06 17:10:21.320: WARN/ActivityManager(62): Activity pause timeout for HistoryRecord{407592b0 com.bismiallah.alphabet/.Alphabet}