• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

code works on one machine but not another - simple code

Hi,
I have the following code, I compile it on one machine and produce the class file. I then take the class to another computer running xp. The machine has had no java compiler etc installed on it, it just comes with whatever windows installs by default. I have not set up class paths etc as i presume this will be done already by windows. I type java in at the command prompt and it gives me all the info relating to the jvm...
The code is as follows:

import java.util.*;
import java.io.PrintStream;
import java.io.File;
import java.io.FileNotFoundException;

public class panasert1
{
      public static String x;
      public static String y;
      public static String w;
      public static String v;
      public static Scanner data_input = new Scanner(System.in);
      
      public static void convert(String source, String destination)
      {
            Scanner read_in;
            Scanner line;
            String record;
            PrintStream write_out;
            
            try
            {
                  // Create new file
                  write_out = new PrintStream(new File(destination));
                  
                  read_in = new Scanner(new File(source));
                  // read in one line at a time
                  read_in.useDelimiter(System.getProperty("line.separator"));
                  while (read_in.hasNext())
                  {
                        // read in record
                        record = new String(read_in.next());
                        
                        line = new Scanner(record);
                        line.useDelimiter("\\s*,\\s*");
                        x = line.next();
                        y = line.next();
                        v = line.next();
                        w = line.next();
                        // Increment record count
                        
                        
                        // Output a record
                        write_out.print("x"+x);
                        write_out.print(",");
                        write_out.print("y"+y);
                        write_out.print(",");
                        write_out.print("v"+v);
                        write_out.print(",");
                        write_out.println("w"+w);
                  }
                  // Close file
                  write_out.close();
            }
            catch (FileNotFoundException e)
            {
                  e.printStackTrace();
            }
            
      }
      
      
      
      
      public static void main(String[] args)
      {
            String destinationFilename;
            String sourceFilename;
            
            System.out.println("Enter the source file name in full");
            sourceFilename = new String(data_input.next());
            System.out.println("Enter the destination file name in full");
            destinationFilename = new String(data_input.next());
            convert(sourceFilename,destinationFilename);
      }
}


When i put the class file in the my documents and type: java panasert1 it just says exception in thread main etc and a list of other details..
i really want it to run on a windows 98 machine in the future though, but need to get it to run on xp first..
Can anyone help?
Cheers
John
0
jdav3579
Asked:
jdav3579
2 Solutions
 
CEHJCommented:
>>and a list of other details..

Please post them
0
 
jdav3579Author Commented:
Hi,
On this ocassion when i ran it. the message simply said:
Exception in thread "main"  java.lang.thread.NoClassDefFoundError: panasert1
Cheers
0
 
jdav3579Author Commented:
Sorry the message was not NoClassDefFoundError it was unsupportedClassVersionError and then lots of other stuff. I can list it all if you want.
t just says
at java.lang.classLoader etc etc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
Thats saying the code is compiled for a later version of the vm than what is installed on that machine.
Either install it for the required version (java-version) using -target option,
or install the latest vm
0
 
hoomanvCommented:
0
 
CEHJCommented:
You need to run it with a Java runtime corresponding with the compiler you're using. If you do

javac -version

and

java -version

you will probably find that the latter is lower than the former. Set your PATH variable to point to the later version of java.exe you installed. If you're on Windows, look under 'Environment Variables' in Windows help

0
 
jdav3579Author Commented:
Thanks very much, apologies for such a basic question, I am relatively new to java. I dont understand though why with the code I posted above that the version should make a difference as the code is hardly cutting edge, so I would have thought it would compile to the same file as on any other version.
But thanks anyway.
John
0
 
CEHJCommented:
:-)

>>so I would have thought it would compile to the same file as on any other version.

No - by default the compiler produces bytecode for the same jvm version as javac's version
0
 
jdav3579Author Commented:
Thanks.
John
0
 
CEHJCommented:
:-)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now