Results 1 to 14 of 14
  1. #1
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Exclamation java.lang.reflect.InvocationTargetException - help!!!

    Hello

    I am trying to write a simple program but for some reason I cannot run it.
    This is applet.

    The only thing I get it is java.lang.reflect.InvocationTargetException and nothing more.

    The whole applet code is too long so I want to show you just the class which extends JApplet because the exception happens right in the init() method.

    I know the problem is somewhere in classes imports but I cannot find it. :confused:

    Please watch my attached file

    http://www.filefactory.com/file/b279...artApplet.java
    Last edited by gafa; 07-09-2010 at 05:33 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Normally this error occurs when java compiler finds two different classes with same name in two different packages. When you are importing both classes at a time and create object of that class it throws InvocationTargetException. Did you do that in your application?

    Simple solution for this is, when you want to create the object of the class use package name also along with class name. So that compiler can clearly identify them.

  3. #3
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Normally this error occurs when java compiler finds two different classes with same name in two different packages. When you are importing both classes at a time and create object of that class it throws InvocationTargetException. Did you do that in your application?

    Simple solution for this is, when you want to create the object of the class use package name also along with class name. So that compiler can clearly identify them.
    Thank you, Eranga

    That is the thing I want to do... But I cannot find these "both classes" in different packages :(
    Please help me to find these classes. Or advise how to :confused:

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Write a simple Java class to read all the file names in your project folder and list them on the console. Simply you can find the matching.

  5. #5
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    It's greate, Eranga, but i am not sure how :confused:

    the project contains so many subfolders...

    Is there some standard way?

  6. #6
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    what if the problem class is in the libs' jars?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gafa View Post
    It's greate, Eranga, but i am not sure how :confused:

    the project contains so many subfolders...

    Is there some standard way?

    Read each folder content, recursively. If you find a file then get the name, else recursively process the sub-folder.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gafa View Post
    what if the problem class is in the libs' jars?
    Do you have JAR files in your project as well? If so your simple code no longer simple. You've to process Jar files as well.

    One more trick you can try. Using Notepad++ search all files with the extension .java (actually .class if you have jars) within the folder you want.

  9. #9
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Question

    Quote Originally Posted by Eranga View Post
    Do you have JAR files in your project as well? If so your simple code no longer simple. You've to process Jar files as well.

    One more trick you can try. Using Notepad++ search all files with the extension .java (actually .class if you have jars) within the folder you want.
    So maybe I should better use windows search thing with *.java or *.class params ;)
    But what should me do with the jars? :confused:

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    That's why I told you to use the notepad++, it's capable of searching the zip folders and all such packages. Give a try and see.

  11. #11
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post

    Read each folder content, recursively. If you find a file then get the name, else recursively process the sub-folder.
    I know the java.io.File class but I don't know how to get subfolder with this thing :confused:

  12. #12
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    Is there an IDE function to look for these duplicated classes?

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm not sure that using NetBeans search it's possible to dig into packages. I think it's possible, with the extension.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gafa View Post
    I know the java.io.File class but I don't know how to get subfolder with this thing :confused:
    isDirectory() and list() from the File class.

Similar Threads

  1. Replies: 5
    Last Post: 03-17-2011, 03:26 PM
  2. sun.reflect
    By koxy in forum Networking
    Replies: 1
    Last Post: 03-22-2010, 03:51 PM
  3. Replies: 0
    Last Post: 01-06-2010, 02:19 PM
  4. Replies: 1
    Last Post: 05-20-2009, 12:03 AM
  5. How to reflect the changes
    By priyanka_t in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-05-2007, 02:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •