weird error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: weird error

  1. #1
    Join Date
    Mar 2004
    Posts
    635

    weird error

    I keep getting this error: "cannot resolve symbol - constructor MyFileStructure()". I do have a class with that name, and in fact, the first time I tried to compile the code below, BlueJ even drew the arrow to the class. So why then can it not friggin see it? I even copy and pasted to make sure I had no dumb spelling mistakes in the class name.

    Code:
        public static void main(String[] args)
        {
            if(args.length != 0)
            {
                MyFileStructure mf = new MyFileStructure();
                mf.setDirName(args[0]);
                mf.build();
                mf.list();
            }
        }

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    can you post more of the code?

    you ahvent done soemthing daft like this have you?:

    Code:
    public class MyFileStructure{
    
      public void MyFileStructure(){
        ...
    thats a method with the same name as the clas, not a coinstructor.. constructors have no return type:

    public MyFileStructure(){
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    Nope, didn't do that.

    Code:
    public class MyFileStructure
    {
        
        private String dirName; //name of top directory
        private MyDir mdir;     //name of top MyDir(holding complete directory structure)
    
        public MyFileStructure(String dirName)
        {
            dirName = dirName;
        }
    }
    I thought that a constructor that took no parameters was valid, whether I put one in or not. I just added a no argument constructor, and my test class compiled ok. Still can't run it, cause something is wrong with the machine. Keeps locking up when I try to run. I hate school computers.

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    if you don't specify any constructor at all i believe a default one is added for you when you compile it, but if you specify a constructor that takes parameters then no default constructor is added. You need to add one yourself (like you did).

  5. #5
    Join Date
    Feb 2004
    Posts
    808
    i.e. the EMPTY constructor is only available when a class contains ZERO other constructors. modify your code:

    Code:
    public class MyFileStructure
    {
        
        private String dirName; //name of top directory
        private MyDir mdir;     //name of top MyDir(holding complete directory structure)
    
        public MyFileStructure(){}
    
        public MyFileStructure(String dirName)
        {
            dirName = dirName;
        }
    }
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center