Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java.lang.VerifyError

Options
  • 03-06-2003 1:25pm
    #1
    Closed Accounts Posts: 536 ✭✭✭


    This exception is evil!

    It gives you aboslutely no hint as to what is causing the problem.

    I'm getting the following error whenever I try to access on of my classes
    java.lang.VerifyError: (class:package/Myclass, method: MyMethod
    signature: (I)V) Illegal instruction found at offset 565

    at package.myApp$4.actionPerformed(myApp.java:305)

    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)

    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)

    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)

    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:227)

    at java.awt.Component.processMouseEvent(Component.java:5134)

    at java.awt.Component.processEvent(Component.java:4931)

    at java.awt.Container.processEvent(Container.java:1566)

    at java.awt.Component.dispatchEventImpl(Component.java:3639)

    at java.awt.Container.dispatchEventImpl(Container.java:1623)

    at java.awt.Component.dispatchEvent(Component.java:3480)

    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)

    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)

    at java.awt.Container.dispatchEventImpl(Container.java:1609)

    at java.awt.Window.dispatchEventImpl(Window.java:1590)

    at java.awt.Component.dispatchEvent(Component.java:3480)

    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)

    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    it happens when I try to reference a class contained in a vector :

    MyStatus my_stat = (MyStatus)myCont.my_status.elementAt(index);

    if(my_stat.index == 1)
    //do something


    if I change the variable my_stat.index to be a final int and assign it a value when I declare it then I don't have a problem.

    does anyone have any notion on how to fix verify errors? :confused:


Comments

  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    Parenthases have a highter precedence that the dot operator. Think it may be evaluating as:

    ( (MyStatus)myCont.my_status).elementAt(index);

    Try changing it to:

    (MyStatus)(myCont.my_status.elementAt(index));


  • Closed Accounts Posts: 536 ✭✭✭flyz


    Originally posted by MrPinK
    Parenthases have a highter precedence that the dot operator. Think it may be evaluating as:

    ( (MyStatus)myCont.my_status).elementAt(index);

    Try changing it to:

    (MyStatus)(myCont.my_status.elementAt(index));

    Didn't work :(

    thanks anyway


  • Closed Accounts Posts: 39 GillyS


    First , I'd check that my classpath was correct with no old versions of the class existing in it. Next, I'd try recompiling all the code again and last but not least I'd download the latest jdk and recompile/run with that...

    I've had that error before and its usually been a classpath or compilation problem (Its definitely not your code which looks fine).

    Gilly


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes



    Thrown when the "verifier" detects that a class file, though well formed, contains some sort of internal inconsistency or security problem.

    You can get it if you forget to add all your class files to your codebase or try to break the security (for example read/write a local file from an applet).

    Doing either of these?


  • Closed Accounts Posts: 536 ✭✭✭flyz


    Originally posted by Hobbes
    You can get it if you forget to add all your class files to your codebase or try to break the security (for example read/write a local file from an applet).

    Doing either of these?

    Nope all I'm trying to do is cast an Object on a Vector to a class and access the members of the class


  • Advertisement
  • Closed Accounts Posts: 536 ✭✭✭flyz


    Originally posted by GillyS
    First , I'd check that my classpath was correct with no old versions of the class existing in it.
    Checked

    Next, I'd try recompiling all the code again
    Checked

    and last but not least I'd download the latest jdk and recompile/run with that...

    Checked

    Tried all of above and nothing worked :(

    Gilly


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by flyz
    if I change the variable my_stat.index to be a final int and assign it a value when I declare it then I don't have a problem.

    Exactly how do you have the .index property defined?

    jc


  • Closed Accounts Posts: 536 ✭✭✭flyz


    Originally posted by bonkey
    Exactly how do you have the .index property defined?

    jc

    it's declared as :

    public class MyStatus
    {

    int index;

    public MyStatus(int [] temp_array)
    {
    index = temp_array[0];
    }

    }
    but if I declare it as :

    final int index = 1;

    then it works


    but not if I declare it as :

    public class MyStatus
    {

    final int index;

    public MyStatus(int [] temp_array)
    {
    index = temp_array[0];
    }

    }


  • Closed Accounts Posts: 39 GillyS


    Strange, maybe its a compiler/optimizer bug. All versions of the code are valid java...

    Try compiling it with 1.4.2 and if it still fails then open a bug report with Sun...

    Gilly


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    public class MyStatus
    {
    
      final int index;
    
      public MyStatus(int [] temp_array)
      {
          index = temp_array[0];
      }
    
    }
    

    You can't assign a value to a final at runtime.

    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/finalVariables.html

    Try
    private int index
    

    Whoops let me expand on that. You should set the variable private then use a getter/setter method to change the value, instead of making it public.


  • Advertisement
  • Closed Accounts Posts: 536 ✭✭✭flyz


    Originally posted by Hobbes
    public class MyStatus
    {
    
      final int index;
    
      public MyStatus(int [] temp_array)
      {
          index = temp_array[0];
      }
    
    }
    

    You can't assign a value to a final at runtime.

    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/finalVariables.html

    Try
    private int index
    

    Whoops let me expand on that. You should set the variable private then use a getter/setter method to change the value, instead of making it public.


    well the way I've it declared is as follows :
    public class MyStatus
    {
    
      [B]int index;[/B]
    
      public MyStatus(int [] temp_array)
      {
          index = temp_array[0];
      }
    
    }
    
    I tried using the private and the get/set functions but that didn't work either :(

    Strange, maybe its a compiler/optimizer bug. All versions of the code are valid java...

    Try compiling it with 1.4.2 and if it still fails then open a bug report with Sun...

    The code I have used to work before.
    I spent all last week replacing all my SQL Statements with PreparedStatements and now the Vector code won't work even though I didn't change any of that code.

    I just don't understand why code that used to work so happily before refuses to work now :(


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Have you tried defining this code outside whatever application you are working on?

    If what you have is valid Java code... perhaps an inherited class before or after this code has some wierd code that is throwing this exception.

    Basically, if taking that code and putting it into a java application completely outside what you are doing, is causing an error then ... it must be some sort of bug with Java... else, it is probably a piece of code 'elsewhere' in your app that is manifesting itself as this bug.


  • Closed Accounts Posts: 39 GillyS


    code:
    public class MyStatus
    {

    final int index;

    public MyStatus(int [] temp_array)
    {
    index = temp_array[0];
    }

    }


    You can't assign a value to a final at runtime.

    Actually you can but only in the class constructor, so the code is valid.

    flyz - have you tried debugging it? I assume you are using some sort of IDE...

    Gilly


  • Registered Users Posts: 1,994 ✭✭✭lynchie


    How are you putting objects into the Vector?

    Is my_status declared as Vector my_status; ?

    What is myCont? Is my_status declared as a public property of myCont's class?

    If you change the code to
    Object o = myCont.my_status.elementAt(index);
    MyStatus my_stat = (MyStatus) o;

    does it work then?

    If you break the code down step by step to

    Vector v = myCont.my_status;
    Object o = v.elementAt(index);
    MyStatus my_stat = (MyStatus) o;

    does it still throw the error?


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Maybe I'm gone completely off track here, but the way that you have defined the constructor of MyStatus will allow you to instantiate an object without having an actual value put into your variable (index), won't it?

    If, however, you define your variable with an initial value, then the problem appears to go away, if I'm understanding what you're saying.

    So I'm wondering if its a feature/bug of the compiler you're using thats somehow related to this...

    I would suggest - cause its easy to check this - changing your constructor, so that it only accepts the correct number of parameters, rather than accepting an array of parameters of which you are only using one (and assuming it is present, which it may not be!).

    jc


Advertisement