Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really simple program...strange error message

Status
Not open for further replies.

adamhutton

IS-IT--Management
Nov 12, 2002
20
0
0
US
I've built a simple program to modify a csv file depending on various conditons. The program works great in the NetBeans and JCreator compilers and runs great in both of them. It will compile using javac but it will not run for anything using java at the command line.

It's getting an "Exception in thread 'main' java.lang.NoSuchMethodError"

I'm stumped on this. Anybody have any ideas?

:Code:

/**
* Code Modifies records in a CSV file
* in the event of finding a "D/O" in a
* row.
*/

import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class ListMod{

/**
* Creates a new ListMod object
*/
public static void main(String[] args){
new ListMod();
}

/**
* Creates the GUI
*/
public ListMod(){
//create the GUI

//call mod
modCSV("sale.csv", "output.csv");
}


/**
* modCSV, method to perform the work on the csv file.
*
* @param in the file to read from
* @param out the file to write to
*/
public void modCSV(String in, String out){
int leaseCount = 0; //holds a count of leased vehicles
String str;
boolean isLeased = false;

try{
BufferedReader br = new BufferedReader(new FileReader(in));
BufferedWriter bw = new BufferedWriter(new FileWriter(out));

while((str = br.readLine()) != null){
String line = "";

//split up the row in by commas
String stArray[] = str.split(",");

//loop through each cell
for(int x = 0; x<stArray.length; x++){
stArray[x] = stArray[x].trim();

if(stArray[x].indexOf("D/O") != -1){
stArray[x] = stArray[x].replaceAll("D/O", "");
stArray[18] = "1";
}

//add the cell to the row
line = line + stArray[x] + ",";
}
//write the row to the file
bw.write(line+"\n");

} //end while to loop through the rows

//close the files
br.close();
bw.close();

} //end try
catch(IOException ioe){
ioe.printStackTrace();
}

} //end modCSV

} //end class
 
I've copy and pasted your program and I've gotten no such error. (I get file not found..no surprise there).

What version of Java are you running?

How are you running the command?

java ListMod

is correct.
 
I don't see any problem with the code. Just copied and compiled it, got the results.

Code:
import java.io.*;
//import javax.swing.*;
//import javax.swing.event.*;
//import java.awt.*;

public class ListMod
{

   public static void main(String[] args)
   {
      new ListMod();
   }
   public ListMod(){
      modCSV("c:/tmp/sales.csv","c:/tmp/output.csv");
   }
   public void modCSV(String in, String out){
      int leaseCount = 0;        //holds a count of leased vehicles
      String str;
      boolean isLeased = false;

      try{
          BufferedReader br = new BufferedReader(new FileReader(in));
          BufferedWriter bw = new BufferedWriter(new FileWriter(out));

          while((str = br.readLine()) != null){
              String line = "";

              //split up the row in by commas
              String stArray[] = str.split(",");

              //loop through each cell
              for(int x = 0; x<stArray.length; x++){
                  stArray[x] = stArray[x].trim();

                  if(stArray[x].indexOf("D/O") != -1){
                      stArray[x] = stArray[x].replaceAll("D/O", "");
                      stArray[18] = "1";
                  }

                  //add the cell to the row
                  line = line + stArray[x] + ",";
              }
              //write the row to the file
              bw.write(line+"\n");

          } //end while to loop through the rows

          //close the files
          br.close();
          bw.close();

      } //end try
      catch(IOException ioe){
          ioe.printStackTrace();
      }
   }
}

The only change I did is commented the import statments, but thats nothing to do with the error you are getting.

Version which I used.

C:\>java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)

C:\tmp>javac ListMod.java
C:\tmp>java ListMod

Contents of sales.csv

123,3,4,2,4,5
123,3,4,2,4,5
123,3,4,2,4,5


Contents of output.csv

123,3,4,2,4,5,
123,3,4,2,4,5,
123,3,4,2,4,5,

Information is not knowledge.
 
Thanks, its good to know that it might just be this version, I was going nuts trying to debug this thing. Ha.

I'm using the command "java ListMod". I'll try running it on a different version of java. I'm using 1.4.2_08 right now. I'll try 1.5
 
I am sure, its nothing to do with the version you are using. Its the path in your system. I tried to execute in the lower version the program works fine from the command line. Try this, go to the source directory and from their give the full path to the javac and java, like this.

C:\Documents and Settings\foo>cd \tmp
C:\tmp>C:\j2sdk1.4.2_04\bin\javac ListMod.java
C:\tmp>C:\j2sdk1.4.2_04\bin\java ListMod
C:\tmp>

Version

java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

Information is not knowledge.
 
That did it. It's all working now. Thanks a a ton. I'd never have thought that my path being messed up would have caused all that.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top