Results 1 to 4 of 4
  1. #1
    darkblue24 is offline Member
    Join Date
    Jan 2010
    Posts
    36
    Rep Power
    0

    Cool 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

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by darkblue24 View Post
    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}; 
    }
    ...
    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]
      }

    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
    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:

    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);
    kind regards,

    Jos

  3. #3
    darkblue24 is offline Member
    Join Date
    Jan 2010
    Posts
    36
    Rep Power
    0

    Default

    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;
      }

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by darkblue24 View Post
    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;
      }
    You are initializing a local variable also named workingDaysCal and not the member variable with the same name; change that line in your constructor to:

    Java Code:
    workingDaysCal = new TreeSet<Integer>(makeCalendar(MeetingMakerHelper.workingDays));
    kind regards,

    Jos

Similar Threads

  1. compiling error should be a simple fix.
    By bottlecap in forum New To Java
    Replies: 2
    Last Post: 01-23-2010, 07:07 AM
  2. Simple DATABASE FROM MSACCESS But ERROR!!!!!!!!
    By Elshan0011 in forum New To Java
    Replies: 2
    Last Post: 12-15-2009, 07:46 PM
  3. Simple "if" statement problem....compiling error.
    By CYANiDE in forum New To Java
    Replies: 4
    Last Post: 10-14-2009, 10:56 PM
  4. Replies: 6
    Last Post: 02-24-2009, 03:50 PM
  5. [SOLVED] Simple Calculator Applet Weird Error
    By sari in forum New To Java
    Replies: 5
    Last Post: 01-28-2009, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •