944,038 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3853
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Oct 16th, 2009
0
Re: java class reference problem - why?
please what you mean by this declaration:
public class ValidRecords<Student>
Reputation Points: 16
Solved Threads: 57
Posting Whiz
moutanna is offline Offline
385 posts
since Oct 2009
Oct 16th, 2009
0
Re: java class reference problem - why?
This is a standard way of declaring a java class that implements 'generics' ( sun has a pdf you can download on generics... )
There is a load of stuff on the web about generics in java; we are expected to make use of generics in our programming course when generics make sense... In this case I am making the type ArrayList<Student> an arraylist that is only able to have Student class elements stored in it... type safety...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bentlogic is offline Offline
19 posts
since Oct 2009
Oct 16th, 2009
0
Re: java class reference problem - why?
It's the .class files that need to be in the Assignments dir; the source .java files' locations are irrelevant to this.
The classpath must point to the folder that contains the Assignments folder, NOT to the folder where the files are.
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is online now Online
5,801 posts
since Apr 2008
Oct 16th, 2009
0
Re: java class reference problem - why?
yep, that's the case. I realize this but alas there's no change to my situation... the clocks ticking and I don't know which wire to cut, red or blue???

This really has to be simple surely, but what have I missed? Maybe I'll try another computer in case it's environmental (or just mental).
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bentlogic is offline Offline
19 posts
since Oct 2009
Oct 16th, 2009
0
Re: java class reference problem - why?
Are you sure?
Click to Expand / Collapse  Quote originally posted by bentlogic ...
1. i put both classes into a directory called Assignment
2. i changed the package declarations (in both files) to be "package Assignment;"
3. i changed the classpath to the absolute pathname where the source files are
1. If the second compile always fails you cannot have a second .class file to put into the directory.
2. Thay already had that. What did you change?
3. This is wrong - the classpath must point to the folder that contains the "Assignment" folder that contains the class files. It's irrelevant where you out the source files.
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is online now Online
5,801 posts
since Apr 2008
Oct 16th, 2009
0
Re: java class reference problem - why?
yes, I can always get Student.java to compile producing a .class file. I have never been able to get ValidRecords.java to compile.

The classpath is correct and is C:\ST152-Warwick\Assignment currently; this is where the files reside (the 2 source files and the Student.class file)...

I have just tried on another computer with EXACTLY the same result.
public class ValidRecords<Student> {

I am wondering about the generic declaration for ValidRecords class but not sure about any of this... reason:
compiler throws-
ValidRecords.java:74: unexpected type
found : type parameter Student
required : class
Student sCopy = new Student( s1 );
^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bentlogic is offline Offline
19 posts
since Oct 2009
Oct 16th, 2009
0
Re: java class reference problem - why?
the whitespace in front of the ^ (caret) has been blown away by the formatter thingy on this site; oops!

so the caret in above post should go under the 'S' in Student after the new keyword. So the constructor bit NOT the first Student in front of the sCopy

Hope that's clear
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bentlogic is offline Offline
19 posts
since Oct 2009
Oct 16th, 2009
0
Re: java class reference problem - why?
Remove "<Student>" from ValidRecords class opening, problem solved...

java Syntax (Toggle Plain Text)
  1. package Assignment;
  2.  
  3. import java.util.*;
  4. /**
  5.  *
  6.  * @author Nigel Novak
  7.  */
  8. public class ValidRecords {
  9.  
  10. // Class Fields and Constants Follow
  11. private ArrayList<Student> list;
  12. private int sortOrder;
Last edited by peter_budo; Oct 16th, 2009 at 7:14 pm.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004
Oct 16th, 2009
0
Re: java class reference problem - why?
[QUOTE=peter_budo;1017052]Remove "<Student>" from ValidRecords class opening, problem solved...

Peter that's Sensational!

was under the impression that i needed that for the generic stuff to work, i.e. ArrayList<Student> ...

Obviously I don't understand generics too well (what newbie does )?

Is ArrayList<ClassName> or any valid var name placeholder a special case of generics? I understand the type safety side but why don't I need to make the class declaration with this generic placeholder present for compiler??

Anyway, thanks so much for your help. Really appreciated!

Also, interested in the LJC Undergrad website although down-under in Perth, Western Australia.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bentlogic is offline Offline
19 posts
since Oct 2009
Oct 17th, 2009
-1
Re: java class reference problem - why?
Click to Expand / Collapse  Quote originally posted by bentlogic ...
Peter that's Sensational!

was under the impression that i needed that for the generic stuff to work, i.e. ArrayList<Student> ...

Obviously I don't understand generics too well (what newbie does )?

Is ArrayList<ClassName> or any valid var name placeholder a special case of generics? I understand the type safety side but why don't I need to make the class declaration with this generic placeholder present for compiler??

Anyway, thanks so much for your help. Really appreciated!

Also, interested in the LJC Undergrad website although down-under in Perth, Western Australia.
Nothing special, already another user questioned your use of class declaration placeholder.
I guess your reference to Sun tutorial on generics in PDF format is to this article Generics in the Java Programming Language. It is my opinion that this is not well presented. Try to read SCJP Sun Certified Programmer for Java 6 Study Guide from chapter 7 and see if that makes more sense for you (definitely easier to read then my endless rumbling).

As for anything similar to Java user/meetup groups I'm member in London I did not found anything in your location through meetup site, however your best chance would be get in touch with Australia Java Champion Mike Cannon-Brookes and see if he is aware of any Java group in your area. Good luck
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to make Java Application to a Windows Service
Next Thread in Java Forum Timeline: Java recursive binary tree





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC