Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Java.lang.reflect.invocationTargetException

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java.lang.reflect.invocationTargetException

    I am doing a project on "Email Reader Extension in Thunderbird".

    I have written a java script file where ,i have used Live Connect to get acess to java Library from Java script.
    we have used Free TTS to add voice to our Strings( i.e email's-- msg, date,from address etc... which we have extracted).

    Free TTS has java classes which has Text to speech method. so, now in our java script we have called methods from those classes.so, to invoke thes methods, we used invoke(null,[parametres]) where null bcoz we are passing parameters to a main method in Freetts and since main is static we pass null and parameters, but here we are getting an Exception

    "java.lang.reflect.invocationTargetException". ... can any one help me how to handle this exception?

  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Java.lang.reflect.invocationTargetException

    I think it might be nice to see some more code then that and also the full exception rather than just the type of it.

    // Json

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java.lang.reflect.invocationTargetException

    my javascript code
    speak1:function(str){   // HERE WE PASS OUR STING THAT TO BE READ.
     
          try
        {
            alert("entered");
            var central=java.lang.Class.forName("com.sun.speech.freetts.FreeTTS",true,cl); 
     
             parameters = java.lang.reflect.Array.newInstance(java.lang.Class.forName("java.lang.String"),2);
            parameters[0]= "-text";
            parameters[1]=str;
     
            var voice=central.getMethod("main",[parameters.getClass()]);
    	if(voice)
            alert(voice.toString());
     
            try
            {
            alert(voice.invoke(null,[parameters]));     // HERE I AM GETTING EXCEPTION
            }
            catch(err)
            { alert(err); // JAVA.LANG.REFLECT.TARGETINVOCATION EXCEPTION
             }
     
     }
     catch(err3)
     {
         alert(err3);
     }
    }
    we have Freetts class files from which we want to invoke method. that code is very huge. but we compiled that freetts java file ..it worked fine. so we felt problem is with invocation probably
    Last edited by helloworld922; November 3rd, 2009 at 10:36 AM.

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java.lang.reflect.invocationTargetException

    sir,

    if want to view freetts code...

    Browse FreeTTS Files on SourceForge.net can download "freetts-1.2.2.src"

    here u can view freetts/com/sun/speech/freetts/FreeTTS.java where u have main method and we in our java script passing our parameters to this main.

    sir, on XP system.. its speaking once and giving exception "JVm process exit abruptly" while on VISTA system,it directly invoking Exception "java.lang.reflect.targetInvocationException"

    please,kindly help me...y the bug has occured..i am screwed up with it. I am in end phase, if it spell and no exception occurs my job is done.... but y the bug has occured? i am unable to fix it...

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Java.lang.reflect.invocationTargetException

    I'm not too familiar with using JavaScript to call Java like this to be honest.

    // Json

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Java.lang.reflect.invocationTargetException

    Based on your exception, I'd say your javascript isn't getting access to the class file. Check your pathing, permissions, and spelling/case.

    edit:

    I think I might see your problem... in calling the invoke method, you passed 2 parameters, one null and one that contains an array of Strings. The main method in Java programs accept only 1 parameter, an array of Strings. Try removing the null.

    alert(voice.invoke([parameters]));
    Last edited by helloworld922; November 3rd, 2009 at 10:42 AM.

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 04:30 PM
  2. Replies: 1
    Last Post: October 25th, 2009, 12:54 PM
  3. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 11:46 PM
  4. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java SE API Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 10:42 AM
  5. [SOLVED] Facing java error "cannot be applied to (java.lang.String)"
    By tazjaime in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2009, 11:19 AM