static? public?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: static? public?

  1. #1
    Join Date
    Oct 2004
    Posts
    9

    static? public?

    I'm trying to mess around with this program and cannot seem to get the declarations right with the BoyerMoore constructor. Can someone help me?

    Error: Cannot resolve symbol: method BoyerMoore() ...

    Code:
    import java.io.*;
    
    public class BoyerMoore {
    
      public static final int ALPHABET_SIZE = Character.MAX_VALUE + 1;
    
      private static String text;
      private static String pattern;
    
      private int[] last;
      private int[] match;
      private int[] suffix;
    
      public static void main(String args[]) throws FileNotFoundException, IOException {
        DataInputStream f;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
        if (args.length == 0) // Read graph from standard input
        {
          System.out.println("Please include file in run parameters!");
          f = new DataInputStream(System.in);
        }
        else
        { // Data file entered as parameter
          f = new DataInputStream(new FileInputStream(args[0]));
        }
    
        text = f.readLine();
    
        pattern = in.readLine();
    
        BoyerMoore(pattern, text);  /* Error is here */
      }
    
    
      public BoyerMoore(String pattern, String text) {
        this.text = text;
        this.pattern = pattern;
        last = new int[ALPHABET_SIZE];
        match = new int[pattern.length()];
        suffix = new int[pattern.length()];
      }
    
      /*  other
            classes
    
            . . . 
    
      */
    }

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    Your constructor is fine, the problem is in how you're attempting to create a new object (the line you've highlighted in red). You've written it using the syntax that you would use to call a method, so the compiler thinks that is what you're trying to do. There is no method with that name, so it complains.

    To create the object you need to declare the type of object you're creating, and give it a name.

    Code:
    BoyerMoore boyerM = new BoyerMoore(string1, string2);
    .

  3. #3
    Join Date
    Dec 2004
    Location
    france
    Posts
    35
    Well Mike barr is absolutely right
    besides your methode seem to be non static method
    so it can't be used in static context
    As mikebarr putt
    you need to creat a new object that would embody the mothed it then work fine good like

  4. #4
    Join Date
    Oct 2004
    Posts
    9
    Thanks you guys. That worked! I need to learn java a lot more...

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