1

I'm having throble with NoSuchMethodError in this line of my code:

    private CalendarPicker<PersianCalendar> calendarPicker = CalendarPicker.persianWithSystemDefaults();

It works fine when I run the project in intellij idea but the output jar file won't run. I exported the project in eclipse and got this error in eclipse.

I used this libraries:

1 - time4j-core-4.38

2 - time4j-ui-5.5

3 - time4j-calendar-4.38.jar

4 - time4j-base-5.5.jar

Full text of the error:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.util.ServiceConfigurationError: net.time4j.scale.LeapSecondProvider: Provider net.time4j.scale.spi.DefaultLeapSecondProviderSPI could not be instantiated
    at java.util.ServiceLoader.fail(Unknown Source)
    at java.util.ServiceLoader.access$100(Unknown Source)
    at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source)
    at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
    at java.util.ServiceLoader$1.next(Unknown Source)
    at net.time4j.base.ResourceLoader$StdResourceLoader.services(ResourceLoader.java:463)
    at net.time4j.scale.LeapSeconds.<init>(LeapSeconds.java:201)
    at net.time4j.scale.LeapSeconds.<clinit>(LeapSeconds.java:179)
    at net.time4j.SystemClock.calibrate(SystemClock.java:474)
    at net.time4j.SystemClock.<clinit>(SystemClock.java:95)
    at net.time4j.ui.javafx.CalendarPicker.lambda$persianWithSystemDefaults$15(CalendarPicker.java:761)
    at net.time4j.ui.javafx.CalendarControl.<init>(CalendarControl.java:82)
    at net.time4j.ui.javafx.CalendarPicker.<init>(CalendarPicker.java:178)
    at net.time4j.ui.javafx.CalendarPicker.create(CalendarPicker.java:1110)
    at net.time4j.ui.javafx.CalendarPicker.persian(CalendarPicker.java:785)
    at net.time4j.ui.javafx.CalendarPicker.persianWithSystemDefaults(CalendarPicker.java:759)
    at HomeScreenController.<init>(HomeScreenController.java:71)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at Main.start(Main.java:39)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
    ... 1 more
Caused by: java.lang.NoSuchMethodError: net.time4j.PlainDate.localFormatter(Ljava/lang/String;Lnet/time4j/format/ChronoPattern;)Lnet/time4j/format/TemporalFormatter;
    at net.time4j.scale.spi.DefaultLeapSecondProviderSPI.<init>(DefaultLeapSecondProviderSPI.java:77)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    ... 44 more
Exception running application Main
Ahmad
  • 77
  • 5

2 Answers2

4

A NoSuchMethodError normally means you have a dependency difference between your compile time and runtime environments.

In effect, it's likely that you have either: 1. multiple different versions of the net.time4j JAR on your classpath 2. a different net.time4j JAR on your runtime classpath than was used during compile time.

Since the call hierarchy seems to suggest net.time4j itself is calling a method it doesn't know about, I suspect multiple JAR versions on the classpath.

This seems to be consistent with the JARs you're talking about using. You're mixing version 4.38 and version 5.5. You should stick to using one version of all the libraries in the suite, as they will likely be designed to work together.

You're probably a bit confused because it seems that Time4J changed the packaging between the 4.x and 5.x versions, and time4j-core is probably now named time4j-base

There is a tutorial page on the Time4J website which seems to suggest you can simply remove your existing dependencies on time4-core and time4j-calendar.

ptomli
  • 11,187
  • 4
  • 36
  • 60
  • Yes, the old v4.38-dependencies can just be removed in favor of time4j-base-5.5.jar (and time4j-ui-5.5 for the JavaFX-component). One small correction though: the new base-module (in v5.x) is replacing the old core-module AND the old calendar-module (in v4.38). – Meno Hochschild Nov 12 '19 at 18:05
1

I've had had the same Issue, with a mix of the different time4j - Versions, because of different sources found online.

So this was the NOT WORKING - POM.XML - Configuration leading to the problem:

<!-- https://mvnrepository.com/artifact/net.time4j/time4j-core -->
       <dependency>
          <groupId>net.time4j</groupId>
          <artifactId>time4j-parent</artifactId>
          <version>5.5</version>
          <type>pom</type>
      </dependency>
        <dependency>
           <groupId>net.time4j</groupId>
           <artifactId>time4j-core</artifactId>
           <version>4.38</version>
       </dependency>      
<!-- https://mvnrepository.com/artifact/net.time4j/time4j-base -->
       <dependency>
           <groupId>net.time4j</groupId>
           <artifactId>time4j-base</artifactId>
           <version>5.5</version>
       </dependency>
       <dependency>
           <groupId>net.time4j</groupId>
           <artifactId>time4j-i18n</artifactId>
           <version>4.38</version>
       </dependency>
    </dependencies>

SOLUTION: Update of the MAVEN - Repository. Maven was still using 4.38, eventough I've changed to 5.5 - a cleanup (purging) of the repository was necessary.

<!-- https://mvnrepository.com/artifact/net.time4j/time4j-base -->
       <dependency>
           <groupId>net.time4j</groupId>
           <artifactId>time4j-base</artifactId>
           <version>5.5</version>
       </dependency>
    </dependencies>


    <build>
      <pluginManagement>
        <plugins>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-jar-plugin</artifactId>
             <configuration>
               <archive>
                 <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>fully.qualified.MainClass</mainClass>
                 </manifest>
               </archive>
             </configuration>
           </plugin>
           <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-dependency-plugin</artifactId>
              <version>3.1.1</version>
              <executions>
                 <execution>
                    <id>build-classpath</id>
                    <phase>generate-sources</phase>
                    <goals>
                       <goal>build-classpath</goal>
                       <goal>purge-local-repository</goal>
                     </goals>
                   <configuration>
                    <!-- configure the plugin here -->
                   </configuration>
                 </execution>
              </executions>
           </plugin>           
           <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
       </pluginManagement>
      <finalName>${project.artifactId}</finalName>
    </build>

Now it work's like a charm.