Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.

test: Reply
 
LinkBack Thread Tools
Old December 17th, 2011, 01:14 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Sad java.lang.NullPointerException when using Talktospeech objects

I am trying to create a mobile app, when the app is launched it should speak some words(Say for example Welome to this app... etc etc). but somehow i am unable to come up with a solution. Can someone please help me in this?

package com.example.helloworld;
import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.widget.Toast;

public class HelloAndroid extends Activity implements OnInitListener
{
TextToSpeech myTTS;
private static final int MY_DATA_CHECK_CODE = 1;


/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTIO N_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);


}

@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
String words = "Hi hi hi hi hi hi hi hi hi hi hi";
speakWords(words);

}

//speak the user text
private void speakWords(String speech) {
myTTS.setLanguage(Locale.US);

//speak straight away
myTTS.speak("Hello welcome to this app......", TextToSpeech.QUEUE_FLUSH, null);
}

//act on result of TTS data check
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
//the user has the necessary data - create the TTS
myTTS = new TextToSpeech(this, this);
}
else {
//no data - install it now
Intent installTTSIntent = new Intent();
installTTSIntent.setAction(TextToSpeech.Engine.ACT ION_INSTALL_TTS_DATA);
startActivity(installTTSIntent);
}
}
}
//setup TTS
public void onInit(int initStatus) {

//check for successful instantiation

}
}




Thanks in advance for your help

Advertisements
siddhushettar is offline  
Reply With Quote
sponsored links
Old December 17th, 2011, 01:15 PM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Sad Below is the error message from console logs

12-17 12:34:02.414: W/dalvikvm(392): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
12-17 12:34:02.424: E/AndroidRuntime(392): Uncaught handler: thread main exiting due to uncaught exception
12-17 12:34:02.454: E/AndroidRuntime(392): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld/com.example.helloworld.HelloAndroid}: java.lang.NullPointerException
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2496)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2512)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.access$2200(ActivityThr ead.java:119)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1863)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.os.Handler.dispatchMessage(Handler.java:99 )
12-17 12:34:02.454: E/AndroidRuntime(392): at android.os.Looper.loop(Looper.java:123)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.main(ActivityThread.jav a:4363)
12-17 12:34:02.454: E/AndroidRuntime(392): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 12:34:02.454: E/AndroidRuntime(392): at java.lang.reflect.Method.invoke(Method.java:521)
12-17 12:34:02.454: E/AndroidRuntime(392): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:860)
12-17 12:34:02.454: E/AndroidRuntime(392): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:618)
12-17 12:34:02.454: E/AndroidRuntime(392): at dalvik.system.NativeStart.main(Native Method)
12-17 12:34:02.454: E/AndroidRuntime(392): Caused by: java.lang.NullPointerException
12-17 12:34:02.454: E/AndroidRuntime(392): at com.example.helloworld.HelloAndroid.speakWords(Hel loAndroid.java:43)
12-17 12:34:02.454: E/AndroidRuntime(392): at com.example.helloworld.HelloAndroid.onStart(HelloA ndroid.java:37)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.Instrumentation.callActivityOnStart(In strumentation.java:1129)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.Activity.performStart(Activity.java:37 23)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2468)
12-17 12:34:02.454: E/AndroidRuntime(392): ... 11 more
12-17 12:34:02.484: I/dalvikvm(392): threadid=7: reacting to signal 3
12-17 12:34:02.644: I/dalvikvm(392): Wrote stack trace to '/data/anr/traces.txt'
12-17 12:34:07.995: I/Process(392): Sending signal. PID: 392 SIG: 9
12-17 12:35:31.255: D/AndroidRuntime(418): Shutting down VM
12-17 12:35:31.255: W/dalvikvm(418): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
12-17 12:35:31.267: E/AndroidRuntime(418): Uncaught handler: thread main exiting due to uncaught exception
12-17 12:35:31.285: E/AndroidRuntime(418): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld/com.example.helloworld.HelloAndroid}: java.lang.NullPointerException
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2496)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2512)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.access$2200(ActivityThr ead.java:119)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1863)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.os.Handler.dispatchMessage(Handler.java:99 )
12-17 12:35:31.285: E/AndroidRuntime(418): at android.os.Looper.loop(Looper.java:123)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.main(ActivityThread.jav a:4363)
12-17 12:35:31.285: E/AndroidRuntime(418): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 12:35:31.285: E/AndroidRuntime(418): at java.lang.reflect.Method.invoke(Method.java:521)
12-17 12:35:31.285: E/AndroidRuntime(418): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:860)
12-17 12:35:31.285: E/AndroidRuntime(418): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:618)
12-17 12:35:31.285: E/AndroidRuntime(418): at dalvik.system.NativeStart.main(Native Method)
12-17 12:35:31.285: E/AndroidRuntime(418): Caused by: java.lang.NullPointerException
12-17 12:35:31.285: E/AndroidRuntime(418): at com.example.helloworld.HelloAndroid.speakWords(Hel loAndroid.java:43)
12-17 12:35:31.285: E/AndroidRuntime(418): at com.example.helloworld.HelloAndroid.onStart(HelloA ndroid.java:37)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.Instrumentation.callActivityOnStart(In strumentation.java:1129)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.Activity.performStart(Activity.java:37 23)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2468)
12-17 12:35:31.285: E/AndroidRuntime(418): ... 11 more
12-17 12:35:31.325: I/dalvikvm(418): threadid=7: reacting to signal 3
12-17 12:35:31.447: I/dalvikvm(418): Wrote stack trace to '/data/anr/traces.txt'
12-17 12:35:35.284: I/Process(418): Sending signal. PID: 418 SIG: 9
siddhushettar is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:12 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.