Have a class within a classs, how can I call setMethod from inner class from a separate class?

Lets say I have a class like this, that also has another class within it:

Then I have a separate class called App. How do I call the setDeviceId method from the MeasurementProject.ProjectDevice() class? Here is some code to illustrate:

So in this class I need to set MeasurementProect.ProjectDevice.deviceId using its set method, but I have been having trouble figuring out how. Ive tried quite a few things but nothing seems to be working.

Java Tutorial wrote:To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
OuterClass.InnerClass innerObject = outerObject.new InnerClass();

If you made your MeasurementProject.ProjectDevice class static then the above code would work. However, the ProjectDevice class would NOT have access to the non-static members of the MeasurementProject class (such as "name" and "permissions").

Java Tutorial wrote:To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
OuterClass.InnerClass innerObject = outerObject.new InnerClass();

Unless you've got an inner class declared in a static context. Which is not the same thing as an inner class. Ye gods, what a mess Sun has made of their nomenclature.

David Sharpe
Ranch Hand

Joined: Jun 15, 2009
Posts: 32

posted Jun 28, 2009 13:44:24

0

Matt Kohanek wrote:Yeah I know it would be easier to just have the ProjectDevice() as its own class. But I was trying an experiment. But it is taking too long to get anything out of it so Im moving on anyhow.
Thanks

Yes, there are (or were, if you've given up on the "experiment") simpler methods. I'm not suggesting the following code is what you were looking for; I'm suggesting it's a more conventional (?) approach.

You seem to be toying with some pretty advanced syntax, e.g. MeasurementProject.ProjectDevice project = new MeasurementProject.ProjectDevice; without really appreciating the difference between a Class and an Object. Slow down!