• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Homework Trouble: Not understood syntax error, Instance of a generic BST class

 
Frank Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey folks, my Data Structures class has me creating a generic tree and filling it with a Comparable object known as SceneObject, compared by trig functions based on 4 ints.

If I had to guess where my problem lay, it would be in the declarative line for one of my classes.

First, the tree class: It shows no errors, which of course doesn't mean it's not where the problem lies. :-p



And here is the class that implements the tree class, creating a new tree known as Space. I have tried this for both the SceneObject class I created, as well as creating another tree of Integers. Same problem...When using a function defined in either class...for instance space.whatever, it starts off by not showing the Smart Insert options that you would expect to see when typing space. or temp., and when you enter in the function it gives the errors commented in the code below.



Thanks in advance for your advice!
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank:

For your last syntax error, compare line 60 of your first class, and line 12 of your second class. That should give you the reason.

John.
 
Frank Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops...Good eye, but that was not the problem. I got a little confused there because I had been trying to use a similar function that probably wasn't camel-cased.

From what I can tell from research online, the error on line 8 of my SpaceTree class, Syntax error on token "temp", VariableDeclaratorId expected after this token, means that when the compiler looks to see what function this is referring to, it can't find one...it's as though it thinks I'm declaring a method right then and there.

Furthermore, it seems to be treating "temp," an instance of SceneObject declared above, as a datatype. Why on earth might that be?

I didn't quote the SceneObject code because I didn't want to clutter the message...in case it would be useful, I'll post it at the bottom of this message.

It should just be treated as an object class that implements Comparable, which as far as I can tell just means it needs to have a compareTo(SceneObject o) function of type int in it. It does, and it's public.

Showing it to my roommate, he thinks the errors in the SpaceTree class have something to do with a function improperly nested in another function instead of just out there in the class...but I have searched high and low for such a problem to no avail.

 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can't just put code anywhere. It has to be in a constructor, initializer, or method.

Henry
 
Frank Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...oh jeez. I got it, thanks. I've been coding in java for almost a year now, and I am pretty damn embarrassed by this rookie mistake.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic