@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.upArrow:
upSound.start();
En_description.setText("\"Straight Ahead\"");
break;
case R.id.downArrow:
downSound.start();
En_description.setText("\"Down\"");
break;
case R.id.rightArrow:
rightSound.start();
En_description.setText("\"Right\"");
break;
case R.id.leftArrow:
leftSound.start();
En_description.setText("\"Left\"");
break;
default:
}
}
The code is simple when I press on an arrow it types the direction of it and plays sound
for some reason it works sometime and other times I get a force close HELP
Thanks this is the log
05-24 17:52:20.384: W/dalvikvm(343): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-24 17:52:20.394: E/AndroidRuntime(343): Uncaught handler: thread main exiting due to uncaught exception
05-24 17:52:20.404: E/AndroidRuntime(343): java.lang.NullPointerException
05-24 17:52:20.404: E/AndroidRuntime(343): at com.aboutera.learnArabic.Directions.onClick(Directions.java:77)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.View.performClick(View.java:2364)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.View.onTouchEvent(View.java:4179)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.View.dispatchTouchEvent(View.java:3709)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-24 17:52:20.404: E/AndroidRuntime(343): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
05-24 17:52:20.404: E/AndroidRuntime(343): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
05-24 17:52:20.404: E/AndroidRuntime(343): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.os.Looper.loop(Looper.java:123)
05-24 17:52:20.404: E/AndroidRuntime(343): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-24 17:52:20.404: E/AndroidRuntime(343): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 17:52:20.404: E/AndroidRuntime(343): at java.lang.reflect.Method.invoke(Method.java:521)
05-24 17:52:20.404: E/AndroidRuntime(343): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-24 17:52:20.404: E/AndroidRuntime(343): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-24 17:52:20.404: E/AndroidRuntime(343): at dalvik.system.NativeStart.main(Native Method)
05-24 17:52:20.414: I/dalvikvm(343): threadid=7: reacting to signal 3
05-24 17:52:20.414: E/dalvikvm(343): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-24 17:52:22.534: I/Process(343): Sending signal. PID: 343 SIG: 9
Check to verify that upSound, downSound, leftSound, rightSound are all initialized(not null) before using them
do for downSound, leftSound, rightSound also
You can initialize the sounds on the fly to make sure if the sound is null it gets played anyways..
Additionally, your textView
En_descriptionmay also be null which could cause this crash as well.Make sure wherever you are retrieving
En_description(using findViewById) it is completing successfully