5 Replies - 2861 Views - Last Post: 15 November 2012 - 11:49 AM Rate Topic: -----

#1 ChrisRedfield  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-November 12

main method not found in class

Posted 14 November 2012 - 06:31 AM

I have been staring at this all night and i can't figure out why it says that main method cannot be found when i have clearly put it in there. It compiles with no errors but when i try to run it i get this:
Error: Main method not found in class assignment3, please define the main method as:
public static void main(String[] args)



import java.io.*;
import java.util.*;
        
public class assignment3 {
    
                        
                public static class makeLowerCase {
                    public static String toLower(String str) {
                            return str.toLowerCase();
                    
                }
                    //performs required manipulations
                    public static class manipString {
                        
                        //trims white space
                        public static String trimmed(String str) {
                            if (str == null) {
                            return "";
                            }
                            return str.trim();
                            }
                        
                        public static String trimmed(String str, int len) {
                            String retVal = manipString.trimmed(str);
                            if (len > retVal.length()) {
                                len = retVal.length();
                            }
                                    return retVal.substring(0, len);
                                }
                        //makes double space single space
                        public static String squeeze(String str) {
                            return str.replace("  ", " ");
                        }
                        
                        public static void main(String [] args) 
                                                throws FileNotFoundException {
                        Scanner inFile = 
                            new Scanner(new FileReader("C:\\input.txt"));
                                while(inFile.hasNext()) {
                                String inputTxt = inFile.nextLine();
                        //used only to shorten length of System.out.println lines
                        String asEntered1 = "As entered but trimmed and squeezed:\n";
                        String asEntered2 = "As entered but trimmed and squeezed, and shortened to 10 characters:\n";
                        String asEntered3 = "As entered but trimmed, squeezed, converted to lower case, and shortened to 20 characters:\n";
                        
                        System.out.println(asEntered1 + manipString.trimmed(manipString.squeeze(inputTxt)));
                        System.out.println(asEntered2 + manipString.trimmed(manipString.squeeze(manipString.trimmed(inputTxt, 10))));
                        System.out.println(asEntered3 + makeLowerCase.toLower(manipString.trimmed(manipString.squeeze(manipString.trimmed(inputTxt, 20)))));
                        System.out.print("\n");   
                        
                        
                                }
                        }
                    }
                }
}                        



Is This A Good Question/Topic? 0
  • +

Replies To: main method not found in class

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1406
  • View blog
  • Posts: 3,121
  • Joined: 05-April 11

Re: main method not found in class

Posted 14 November 2012 - 06:38 AM

I bet that there is missing a curly bracket somewhere in your code, I haven't checked though

I hope your code is more organized than this, and hope it was the web editor that messed it up

Why are you having a static class?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: main method not found in class

Posted 14 November 2012 - 10:27 AM

Your main() is in manipString not in assignment3

Why so many classes ? And why static ?

And respect Java conventions, class name start with a Capital letter so Assignment3 and ManipString
Was This Post Helpful? 0
  • +
  • -

#4 ChrisRedfield  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-November 12

Re: main method not found in class

Posted 14 November 2012 - 07:14 PM

I apologize for the improper class names, I will make sure to correct that in the future. They are static because that's what the assignment calls for.
Was This Post Helpful? 0
  • +
  • -

#5 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 849
  • Posts: 2,591
  • Joined: 29-July 11

Re: main method not found in class

Posted 14 November 2012 - 07:17 PM

Works fine for me.
Was This Post Helpful? 1
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: main method not found in class

Posted 15 November 2012 - 11:49 AM

View Postfarrell2k, on 14 November 2012 - 10:17 PM, said:

Works fine for me.

That's funny... I guess it is the static in the inner classes that allows to search for a static void main() down the stream
I'll go to bed less dum tonigh
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1