aspose file tools*
The moose likes Beginning Java and the fly likes Called abstract class methods  from another class returns null value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Called abstract class methods  from another class returns null value" Watch "Called abstract class methods  from another class returns null value" New topic
Author

Called abstract class methods from another class returns null value

Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Here is the problem
I have a one abstract class named MovingObject.java and I want to call some of methods in abstract class. I have written one class named MyMovingObject.java which extends from abstract class and I have written constructors to override super-class constructors. I guess Now the subclass will contain all the superclass methods with defined methods init. Then I have created one more class named Simulator.java and this class extends from MyMovingObject.java and I have created object to MyMovingObject class but when I am calling methods from abstract class, I am getting null as a returned values for all methods,I want to call routePlan() method in MovingObject.java
these are the programs

this is the I have written one class which extends from abstract class


Now I have written one more class which extends MyMovingObject.java and this is the code I have written
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't even say what the problem is, where it is, or anything. You can't expect someone to dig through a thousand lines+ of code and GUESS what your issues are.

Did you test any of the code first? Can't you reduce the issue to a *small* usecase that's possible to understand *easily*?
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Yes David I changed the code and mentioned clearly what is the problem have
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
How do you suppose it to return something else when you never call setRoutePlan ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

thanks for your reply I tried with that option also but giving errors in that setRoutePlan() method we need to pass something ,Here I tried with pasing same arguments and got the error, and I am confused what else I need to pass setRoutePlan() method when I am calling
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
how about a Route object ?
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Route object will have one constructor and some methods init
here is the code
Route.java
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
So how does that solve anything. setRoute takes a Route object. So pass a Route object, and routePlan won't return null.
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

ofcourse you are right I passes the Route Object like this correct me if I am wrong
mo.setRoutePlan(Route rt);

got the compilation Error
Error
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
No, you did not understand the whole concept of object creation.

Check out a general java tutorial.

This is the way it would work

Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

its returning zero for route and routePlan when I passed different values

Output
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
i don't really understand what you are saying ??
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

by passing value 1 while creating object to Route class is the size of the ArrayList right? I ran the code and got zero as a output.But it will return list of objects(that is actually RoutePlan-RoutePLan will have list of motionless Objects) ,but its not returning expected value and what might be the solution to get expected output..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Change what you're printing?
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Sorry I didn't get you David
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Pretend you're the computer. Trace through the execution line by line.

Try posting what you think is happening; it should be an ordered list of steps from where you start executing until the end. Post the *exact* code that you believe is being executed by the steps you list. When you run the program, see if the code you believe is being executed is actually executed. If there's a discrepancy between what is happening and you *think* should be happening, try to figure out why.

Remember: we don't have your computer in front of us. It's difficult to figure out what *is* happening vs. what *should* be happening and compare both to your expectations. If you have to, post the entire code again, and maybe somebody will copy it in to their IDE and see if we can point you in the right direction.
 
wood burning stoves
 
subject: Called abstract class methods from another class returns null value