• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Speak(read) a text when app is launched

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?



Thanks in advance for your help
 
sid shettar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the below error when i run my app.


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(ActivityThread.java:2496)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread$H.handleMessage(ActivityThread.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.java: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$MethodAndArgsCaller.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(HelloAndroid.java:43)
12-17 12:34:02.454: E/AndroidRuntime(392): at com.example.helloworld.HelloAndroid.onStart(HelloAndroid.java:37)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.Activity.performStart(Activity.java:3723)
12-17 12:34:02.454: E/AndroidRuntime(392): at android.app.ActivityThread.performLaunchActivity(ActivityThread.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(ActivityThread.java:2496)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread$H.handleMessage(ActivityThread.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.java: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$MethodAndArgsCaller.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(HelloAndroid.java:43)
12-17 12:35:31.285: E/AndroidRuntime(418): at com.example.helloworld.HelloAndroid.onStart(HelloAndroid.java:37)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.Activity.performStart(Activity.java:3723)
12-17 12:35:31.285: E/AndroidRuntime(418): at android.app.ActivityThread.performLaunchActivity(ActivityThread.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
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Caused by: java.lang.NullPointerException at
com.example.helloworld.HelloAndroid.speakWords(HelloAndroid.java:43)


So which line is line 43? Which object is null?
 
sid shettar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Line number 43 is the method speakWords

" private void speakWords(String speech) { "

 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt that, since there's no method call in that line. Once you have determined which one is the actual line, the more important question is:

Which object is null?


From looking at the code it is already clear which object is null, but it's good practice for you to figure that out yourself.
 
sid shettar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried my best but unable to identify it
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What, exactly, have you done trying to identify which object is null?
 
sid shettar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried all the possible ways i understood. I am stuck at this point from 4-5 days. Thanks in advance for your help. I am just trying for a simple solution. When an activity is launched its should speak out some words related to that activity without any user interaction
 
Tim Moores
Bartender
Posts: 7645
178
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again:

Tim Moores wrote:What, exactly, have you done trying to identify which object is null?


If you don't tell us what you did trying to make progress with this issue, then we won't be able to suggest what else you might try. How about this: do you know what a NullPointerException is? And what causes it?

Also: Are you aware of the concept of writing certain information to a log file during developing and/or debugging an application? If yes, are you familiar with the android.util.Log class and the logcat command of the ADB tool?
 
sid shettar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,
Yeah, i know about nullpointers. Here in my code the the line "myTTS.speak("Hello welcome to this app......", TextToSpeech.QUEUE_FLUSH, null); " is causing this Null exception which means the object "MyTTS" is pointing to Null because its not being initialized.

But what i could not figure out is, why is it not being initialized because as per my understanding it should had been initialized in the method "onActivityResult" (in my above code).

I know my code is not a good one as I'm just newbie to android here. I have a strong feeling that i am supposed. but my code works as per my expectation when i do this way. but i need to understand how to make my app speak when its started using the start method and also speak when its resumed using resume method. Iam unable to figure out a solution although its the very basic stuff....

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
{
private TextToSpeech myTTS;
//private static final int MY_DATA_CHECK_CODE = 0;


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

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

Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

myTTS = new TextToSpeech(this, this);


}



//setup TTS
public void onInit(int initStatus) {

//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS) {
if(myTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
myTTS.setLanguage(Locale.US);

myTTS.speak("", TextToSpeech.QUEUE_FLUSH, null);
}
else if (initStatus == TextToSpeech.ERROR) {
Toast.makeText(this, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
}
}



}

 
sid shettar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Tim Moores
 
Ranch Hand
Posts: 40
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sid shettar wrote:Hi Tim,
  Yeah, i know about nullpointers. Here in my code the the line "myTTS.speak("Hello welcome to this app......", TextToSpeech.QUEUE_FLUSH, null); " is causing this Null exception which means the object "MyTTS" is pointing to Null because its not being initialized.

But what i could not figure out is, why is it not being initialized because as per my understanding it should had been initialized in the method "onActivityResult" (in my above code).

I know my code is not a good one as I'm just newbie to android here. I have a strong feeling that i am supposed. but my code works as per my expectation when i do this way. but i need to understand how to make my app speak when its started using the start method and also speak when its resumed using resume method. Iam unable to figure out a solution although its the very basic stuff....

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  
{
   private TextToSpeech myTTS;
   //private static final int MY_DATA_CHECK_CODE = 0;
   

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

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

       Intent checkIntent = new Intent();
       checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
       
       myTTS = new TextToSpeech(this, this);

       
   }

 
   
   //setup TTS
public void onInit(int initStatus) {

       //check for successful instantiation
   if (initStatus == TextToSpeech.SUCCESS) {
       if(myTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
           myTTS.setLanguage(Locale.US);
       
       myTTS.speak("", TextToSpeech.QUEUE_FLUSH, null);
   }
   else if (initStatus == TextToSpeech.ERROR) {
       Toast.makeText(this, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
   }
}


   
}



Did you try to move the line myTTS = new TextToSpeech(this, this); to te top of your class?
Maybe you have to create te tts object before getting into the onCreate method?

Wim
 
Sheriff
Posts: 9012
655
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We hope user solved this issue in the past 5 years.
Welcome to the Ranch
 
reply
    Bookmark Topic Watch Topic
  • New Topic