Results 1 to 5 of 5
  1. #1
    ToastyBainey is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default Problems With my Main

    Hi
    First off, I do have a main :)


    I am trying to write a soundex program for a java class. It is divided into three files so far, one that deals with string inputs and produces a hash value, another one that puts it into a binary file of a certain length, and the third one I am working on is making a GUI for it.

    I had the second one working perfectly, but when I tried to make the GUI, it could not access the methods within the second one because they were not static. So I changed them all to static, and it compiles, but when I run, I think it is saying it cannot find the main. But as I said, the main is there, at the bottom, I can find it D:

    So I was wondering if someone could tell me why it is doing this and how to fix it.

    Thanks

    The error is:

    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Interactive Session Ended


    Here is my code:


    Java Code:
    import java.io.*;
    import java.util.*;
    
    
    public class RandomFileTest{
    	public static File diskFile;
    	public static RandomAccessFile testFile;
    	public static final String EMPTY = "000000000000000";//15 zeros
    	//end of declarations
    	
    	public RandomFileTest(String fileName){
    		diskFile = new File(fileName);
    	}//end random file test
    	
    	public static void createRandomFile(){
    		if(diskFile.exists())
    			diskFile.delete();
    		
    		try{
    			testFile = new RandomAccessFile(diskFile,"rw");
    			for(int i = 0; i < 25656; i++){
    				testFile.writeBytes(EMPTY);//makes 25656 empty slots
    			}//end for
    			
    			testFile.close();
    		}//end if try
    		catch(IOException e){
    			System.out.println("Error in createRandomFile(): " + e.toString());
    		}//end of catch
    	}//end craterandomfile
    	
    	
    	public static void openForReading(){
    		try{
    			if(!diskFile.exists())
    				throw new IOException("The File " + diskFile.getName() + " does not exist!\n" );
    			
    			testFile = new RandomAccessFile(diskFile, "r");
    		}//end if try
    		catch(IOException e){
    			System.out.println("Error in openForReading() : "+e.getMessage());
    		}//end of catch
    	}//end open for reading
    	
    	public static void openForWriting(){
    		try{
    			if(!diskFile.exists())
    				throw new IOException("The File " + diskFile.getName() + " does not exist!\n" );
    			
    			testFile = new RandomAccessFile(diskFile, "rw");
    		}//end of try
    		catch(IOException e){
    			System.out.println("Error in openForWriting(): " + e.getMessage());
    		}//end of catch
    	}
    	
    	public static String read(int position){
    		byte[] byteData = new byte[15];
    		String stringData = " ";
    		position *= 15;//added this
    		
    		try{
    			if((position >= 0) && (position / 15 < testFile.length())){
    				testFile.readFully(byteData);
    				stringData = new String(byteData);
    				stringData = stringData.trim();
    			}//end of if
    			else
    				throw new IOException("Attempt to read past end of file: " + position);
    		}//end of try
    		catch(IOException e){
    			System.out.println("Error in read() : " + e.getMessage());
    		}//end of catch
    		
    		return stringData;
    	}	
    	
    	public static void close(){
    		try{
    			testFile.close();
    		}
    		catch(IOException e){
    			System.out.println("Error in close(): " + e.toString());
    		}
    	}//end close
    	
    	
    	/*given a word, the soundex hash value ofr the word is calculated and the word is insterted
    	into the file at that hash value*/
    	
    	public static void append2(int data, String X){
    		openForWriting();
    		String Y = X.trim();
    		int Ylength = Y.length();
    		String inputData = "";
    		boolean go = false;
    		int originalPosition = data;
    		int n = 1;
    		int m = 15;
    		data = data*15;
    		if(data > 0)
    			data += -15;
    		
    		if(Y.length() > 15){
    			Y = Y.substring(0, 15);
    		}
    		else if(Y.length() < 15) {
    			for(int i = Ylength; i < 15; i++){
    				Y = Y + " ";
    			}
    		}
    		
    		
    		try{
    			
    			
    			testFile.seek(data);//goes to that spot in the file
    			System.out.println("file pointer1 = " + testFile.getFilePointer());
    			
    			
    			while(go == false && data >= 0){//always starts out at 0
    				
    				if(read(data).equals(EMPTY)){
    					go = true;
    					System.out.println("file pointer2 = " + testFile.getFilePointer());
    				}
    				else{
    					if(n == 1 && data >= 0){
    						n = 0;
    						data = data+m;
    						m=m+15;
    						if(data >= (int)testFile.length()){
    							data = data - (int)testFile.length();
    						}
    					}
    					else if(n == 0 && data >= 0){
    						n = 1;
    						data = data-m;
    						m=m+15;
    						if(data <= 0){
    							data = data + (int)testFile.length();
    						}
    					}
    					testFile.seek(data);
    				}
    			}//end if
    			
    			testFile.seek(data);//moves the pointer back
    			
    			System.out.println("file pointer3 = " + testFile.getFilePointer());
    			testFile.writeBytes(Y);
    			
    			
    		}//end of try
    		catch(IOException e){
    			System.out.println("Error in append2(): " + e.toString());
    		}
    	}//end append
    	
    	public static void main(String args){
    		RandomFileTest test = new RandomFileTest("random.bin");
    		test.createRandomFile();
    		String userInput = "";
    		String exit = "@exit";
    		int foo;
    		boolean continuue = true;
    		
    		
    		while(continuue == true){
    			System.out.println("Please type a word: ");
    			Scanner input = new Scanner(System.in);
    			userInput=input.next();
    			
    			if(userInput.equals(exit)){
    				continuue = false;
    			}
    			else{
    				foo = teest.soundex(userInput);
    				test.append2(foo,userInput);
    			}
    			
    			
    		}
    		
    	}//end of main :)
    	
    }//end randomfile test

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I had the second one working perfectly, but when I tried to make the GUI, it could not access the methods within the second one because they were not static. So I changed them all to static, and it compiles...
    Probably not what you really should be doing here as it's really taking a big step backwards. Instead you might want to create an instance of the second class and call methods on this instance.

  3. #3
    ToastyBainey is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default

    Actually I just figured it out D: I feel like a dork
    had to have String[] args instead of String args

  4. #4
    ToastyBainey is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default

    Oh okay good idea.Thanks :) I will try that.

  5. #5
    ToastyBainey is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default

    That worked perfectly. Thanks :)
    Sorry if it was easy fix. I am still new to this :)

Similar Threads

  1. Replies: 5
    Last Post: 10-06-2008, 12:11 AM
  2. Arguments in Main
    By CyberFrog in forum New To Java
    Replies: 2
    Last Post: 03-30-2008, 09:37 PM
  3. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  4. problems to find the main method
    By christina in forum Eclipse
    Replies: 2
    Last Post: 08-06-2007, 07:51 PM
  5. Replies: 1
    Last Post: 08-06-2007, 09:11 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
  •