Author Topic: Automation interface: compile error in java code  (Read 3258 times)

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Automation interface: compile error in java code
« on: January 03, 2014, 12:51:36 am »
Hi,

I'm trying to get a package-object from the repository (get by id) and get the package name.

Here's a code snippet:

Code: [Select]
org.sparx.Package oPackage = null;
oPackage = repo.GetPackageByID(Integer.parseInt(packageID));
String sName = oPackage.Name;

When I run my script, I get the following compile error

Code: [Select]
deleteExternalRef.java:44: error: cannot find symbol
                String sName = oPackage.Name;
                                       ^
  symbol:   variable Name
  location: variable oPackage of type Package
1 error
...Run

What am I doing wrong???

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Re: Automation interface: compile error in java co
« Reply #1 on: January 06, 2014, 07:57:39 pm »
Problem solved: I had to use a method "package.GetName()" instead of a variable "package.Name".

I guess I'm using an old user guide or the user guide isn't up-to-date...

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13288
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Automation interface: compile error in java co
« Reply #2 on: January 06, 2014, 09:43:16 pm »
I think VB and C# use real properties, so you can indeed write
Code: [Select]
mystring = oPackage.Name or
Code: [Select]
oPackage.Name = mystringwhereas Java uses getter and setter methods.
So in Java that would be
Code: [Select]
myString = oPackage.GetName()or
Code: [Select]
oPackage.SetName(myString)
Geert

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Re: Automation interface: compile error in java co
« Reply #3 on: January 06, 2014, 11:30:53 pm »
Thanks for the additional info!

Greets