Java code works on Mac, but not on PC

Asked

Viewed 106 times

1

The following code works on my mac and not on the pc. I really need to get to work on the pc, so I appreciate any help you can give me. I’m using Eclipse Java Oxygen on both platforms.

Code:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class coordinates {

public static void main(String[] args) {

   try {

       BufferedReader in = new BufferedReader(new FileReader(new File("C:\\Users\\TelmoG\\Desktop\\06092017.txt")));
       PrintWriter out = new PrintWriter("C:\\Users\\TelmoG\\Desktop\\outputFile.csv");

       String newLine ="";
       int index = 0;
       String line = "";

       while((line = in.readLine()) != null){
          // System.out.println(line);
           index++;

           if (index %2 == 0){
               newLine += ";" + line.substring(34);
               out.println(newLine);
           } else {
               newLine = line.substring(34);
           };  
       } 
       in.close();
       out.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
    }      
 }
 }

Error:

Exception in thread "main" java.lang.Error: Unresolved Compilation problem:

coordinates.coordinatdinates.main(coordinates.java:25)

Line 25:

public Static void main(String[] args) {

  • Is this file inside a folder? Or is it loose in the root of the sources directory?

  • The txt file is on the desktop

1 answer

5


This is due to a build error - in eclipse should say which error - check out the View "Problems" or the annotation to the left of the panel with the code, probably in the first line of the code and eventually with the following message:

The declared package "" does not match the expected package "coordinates"

By the code you posted, or the package statement is missing:

package coordinates;

or the file coordinates.java is in the wrong directory: move to the 'parent' directory of coordinates (or the Eclipse project is with the Source folder wrong).

  • Problem solved. Thank you very much.

  • 1

    Hi @Telmo Garcia. If Carlos' answer solved your problem, accept it (https://answall.com/help/accepted-answer). So whoever is looking for a resolution for a similar case will know that here is an answer that potentially solves. And it’s also a way to thank Carlos.

  • Okay. It’s already accepted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.