Results 1 to 4 of 4
Thread: Simple Error ???
- 03-25-2010, 08:10 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 36
- Rep Power
- 0
Simple Error ???
Hi All
I have MeetingMakerHelper class:
Java Code:public class MeetingMakerHelper { public static int[] workingDays = {1,2,3,4,5,8,9,10,11,12,15,16,17,18,19,22,23,24,25,26,29,30};
and MeetingMaker class that has MeetingMaker method:
Java Code:public class MeetingMaker { private SortedSet<Integer> workingDaysCal; /** * Constructor for objects of class MeetingMaker */ public MeetingMaker() { super(); [COLOR="DarkOrange"] [B] SortedSet<Integer> workingDaysCal = new this.MeetingMakerHelper.workingDays[int]; // this does not compile[/B][/COLOR] } /** * It turns int Arrays to sorted Sets */ public Set MeetingMaker(int[] anArray) { Set<Integer> MetMakerSet = new TreeSet<Integer>(); for (int i = 0; i < anArray.length; i++) { MetMakerSet.add(anArray[i]); } return MetMakerSet; } }
My constructor does not compile: <identifier> expected error
workingDaysCal should be initialised to a new sorted set
that holds the dates given by the array referenced by the MeetingMakerHelper class’s static variable workingDays.
Do you know why does not compile?
M
- 03-25-2010, 08:26 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
The 'new' operator needs a type, not some instance thereof; but above all why do you use an array for the numbers 1 ... 30? All you're doing with that array is try to put it in a SortedSet. There's an easier way to fill a set like that:
kind regards,Java Code:SortedSet<Integer> yourSet= new TreeSet<Integer>(); ... // fill the set: for (int i= 1; i <= 30; i++) if (i%7 != 6 && i%7 != 0) yourSet.add(i);
Jos
- 03-25-2010, 09:14 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 36
- Rep Power
- 0
Hi Jos
This array must be created in this particular way (its not numbers from 1 to 30 - but its working days in month)
Anyway.. I made some changes to the code and compiles fine but when I am inspecting created object value in atribute workingDaysCall is null.
What am I doing wrong?
Java Code:public class MeetingMaker { private SortedSet<Integer> workingDaysCal; private SortedSet<Integer> adamNotInCal; /** * Constructor for objects of class MeetingMaker */ public MeetingMaker() { super(); [B][COLOR="Red"] SortedSet<Integer> workingDaysCal = new TreeSet<Integer>(makeCalendar(MeetingMakerHelper.workingDays)); // ERROR IS HERE[/COLOR][/B] } /** * It turns int Arrays to sorted Sets */ public SortedSet<Integer> makeCalendar(int[] anArray) { SortedSet<Integer> sorted = new TreeSet<Integer>(); for (int number : anArray) { sorted.add(number); } return sorted; }
- 03-26-2010, 08:15 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
compiling error should be a simple fix.
By bottlecap in forum New To JavaReplies: 2Last Post: 01-23-2010, 06:07 AM -
Simple DATABASE FROM MSACCESS But ERROR!!!!!!!!
By Elshan0011 in forum New To JavaReplies: 2Last Post: 12-15-2009, 06:46 PM -
Simple "if" statement problem....compiling error.
By CYANiDE in forum New To JavaReplies: 4Last Post: 10-14-2009, 09:56 PM -
Error message in executing a simple program from DOS window
By betelgeuse in forum New To JavaReplies: 6Last Post: 02-24-2009, 02:50 PM -
[SOLVED] Simple Calculator Applet Weird Error
By sari in forum New To JavaReplies: 5Last Post: 01-28-2009, 04:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks