0

Error: Main method not found in class jsone.testing, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

package jsone;

import java.io.File;
import java.io.IOException;

import org.apache.xpath.operations.String;
import org.testng.annotations.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

 public class testing {
    @Test
    public static void main(String args[]) {   
                ObjectMapper mapper = new ObjectMapper();
                try {
                    File jsonInputFile = new File("D:\\workspace\\jsone\\car.json");
                    car emp = mapper.readValue(jsonInputFile, car.class);
                    System.out.println(emp);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

package jsone;

public class car{
    private String colour;

    public String getcolour() {
        return colour;
    }

    public void setcolour(String colour) {
        this.colour = colour;
    }

    @Override
    public String toString() {
       StringBuilder sb = new StringBuilder();
       sb.append("\n----- Employee Information-----\n");
       sb.append("Colour: " + getcolour() + "\n");
       sb.append("*****************************");
       return sb.toString();
    }
}
Michał Ziober
  • 31,576
  • 17
  • 81
  • 124

1 Answers1

0

In your example String class comes from org.apache.xpath.operations.String package which is wrong. You should use java.lang.String class instead. Classes from java.lang package are visible in class by default so you have to delete below line:

import org.apache.xpath.operations.String;

and it should start work. Also, your main method should not be annotated with @Test annotation.

Also, please take a look on this question:

  1. Error: Main method not found in class MyClass, please define the main method as…
Michał Ziober
  • 31,576
  • 17
  • 81
  • 124