• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with java.beans.*;  RSS feed

 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:
I was seeing some classes from java.beans.*package, more specificly Expression and Statement classes. This pagefrom Java Almanac shows how gets getters and setters methods using these classes.
So, I created a test class. In this class I try to use getters and setters from a Internal class, a external class but in same java file than test class and a external class in another java file.
It follows the code from test class:

Now external class code:

Well, I runned this test class and I got this:

java.lang.NoSuchMethodException: TestaStatement$InnerClass0.setValue(Integer0);
at java.beans.Statement.invoke(Statement.java:489)
at java.beans.Statement.execute(Statement.java:119)
at TestaStatement.executeSetter(TestaStatement.java:11)
at TestaStatement.testInnerClass(TestaStatement.java:26)
at TestaStatement.main(TestaStatement.java:72)
java.lang.NoSuchMethodException: <unbound>=TestaStatement$InnerClass0.getValue();
at java.beans.Statement.invoke(Statement.java:489)
at java.beans.Statement.execute(Statement.java:119)
at TestaStatement.executeGetter(TestaStatement.java:17)
at TestaStatement.testInnerClass(TestaStatement.java:32)
at TestaStatement.main(TestaStatement.java:72)
java.lang.NoSuchMethodException: OuterClass0.setValue(Integer1);
at java.beans.Statement.invoke(Statement.java:489)
at java.beans.Statement.execute(Statement.java:119)
at TestaStatement.executeSetter(TestaStatement.java:11)
at TestaStatement.testOuterClass(TestaStatement.java:42)
at TestaStatement.main(TestaStatement.java:73)
java.lang.NoSuchMethodException: <unbound>=OuterClass0.getValue();
at java.beans.Statement.invoke(Statement.java:489)
at java.beans.Statement.execute(Statement.java:119)
at TestaStatement.executeGetter(TestaStatement.java:17)
at TestaStatement.testOuterClass(TestaStatement.java:48)
at TestaStatement.main(TestaStatement.java:73)
java.lang.NoSuchMethodException: ExternClass0.setValue(Integer2);
at java.beans.Statement.invoke(Statement.java:489)
at java.beans.Statement.execute(Statement.java:119)
at TestaStatement.executeSetter(TestaStatement.java:11)
at TestaStatement.testExternClass(TestaStatement.java:58)
at TestaStatement.main(TestaStatement.java:74)
java.lang.NoSuchMethodException: <unbound>=ExternClass0.getValue();
at java.beans.Statement.invoke(Statement.java:489)
at java.beans.Statement.execute(Statement.java:119)
at TestaStatement.executeGetter(TestaStatement.java:17)
at TestaStatement.testExternClass(TestaStatement.java:64)
at TestaStatement.main(TestaStatement.java:74)

I do not understand why beans are called "TestaStatement$InnerClass0", "OuterClass0" e "ExternClass0". Where did this "0" come? Did I do something wrong in my code. What do you think?
Thanks,
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to Java in General (beginner).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid this one's a might' bit too complicated for us simple folk. For us, beans is somethin' we eat out of a can. Sometimes they're hot. Sometimes they're cold.
I'm moving this on over to the Intermediate forum. Hopefully, some fancy talkers there can give you a hand.
[ August 17, 2003: Message edited by: Dirk Schreckmann ]
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rafael,
i like the idea!! and solved the problem as well.
the problem is -
InnerClass is "private" in TestaStatement class so only code from the TestaStatement can access that InnerClass object. Now, java.bean.Statement is java API class which means it is in separate package altogether , right? as Statement is external class it can't access InnerClass and so in turn can't see if there is setValue/getValue methods in it.
If v want this code to work then make InnerClass public in declaration. it would work.
similar problem will be with OuterClass because its having no access specifier which means its a "defaut" access specifier and so Statement class again can't access its methods and will give u runtime errors. So, you have to make OuterClass public. Now, u can't have two Public classes in one Java file so u'd endup having OuterClass.java as a separate file where u declare OuterClass as public but that would be essentially same as ur ExternClass , right???
so ....i hope u got my point..
also, in above description Statement and Expression both terms will be interchangeable as both are external (in java API package) to the TestaStatement class...so all similar arguments would apply to Expression that is used for invoking getValue() things...
regards
maulin
 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maulin:
Your suggestions worrk, thanks. I try use protected with InnerClass yet. But it did not work, throwing same exception. It is very curious.
Thanks,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!