File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using my own types on a Script Engine....

 
Vinicius Souza
Ranch Hand
Posts: 70
1
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ppls how are you doing?
Im trying to expose some of my own types using the 'put' method from the java Script Engine but its guive-me a error. See my code:

See, the Actor class is a custom class of mine so when I try to use getY() method java return an error tell me that the method does not exists. Whats wrong ? Can I use my own object or only the java native ones?
Thanks in advance!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried your code. I had to make up my own class Actor because you didn't post yours. It worked without any errors and printed 200.

Does your class Actor have a public method called getY?

Here's my Actor class, very simple:
 
Vinicius Souza
Ranch Hand
Posts: 70
1
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its weird because my Actor class is on the same package com.xcretor and the method getX() is public. Im getting this error:
"sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function getY in object com.xcreator.Actor@53187f60. (<Unknown source>#1) in <Unknown source> at line number 1"
Its really weird....
Here is my actor class:

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinicius Souza wrote:Its weird because my Actor class is on the same package com.xcretor and the method getX() is public.

Yes, but this is about the getY method, not the getX method.

And looking at your code, the getX and getY methods are not public, they have default access.

You're writing in a kind of C++-style. Specifying access specifiers in Java does not work the same as in C++. Look at this:


Do you understand what's happening here? Only the variable x has private access. All the other variables have default access. The indentation you've used is misleading - as if all the variables are private. This is the same as:


You are doing the same with the constructor and methods:

The constructor is public, but all the methods have default access.

You have to specify private or public for all variables and methods separately.
 
Vinicius Souza
Ranch Hand
Posts: 70
1
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hummm, thanks a lot friend. Solved my problem! I really was thinking like a C programmer ehehehehe.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic