LocalDateTime Error

Hi,
I have the problem, that each Time I want to send my code with java.time.LocalDateTime includet it throws an Excepiton. Code without any Libarys works just fine. Want’s the Problem und how can I solve it?

@Americanjoghurt ===
what is the exception???
can you put some code which reproduces the error?

import java.time.LocalDateTime;

void setup() {
  fullScreen();
  background(255, 100, 0);
}

void draw() {
  Timer t = new Timer();

public  class Timer {

  boolean x;
  LocalDateTime Opentimer;
  LocalDateTime acttimer;
  public Timer() {

    Opentimer = LocalDateTime.of(2019, 5, 12, 12, 0, 0);
    acttimer = LocalDateTime.now();
    x = ueberschritten(acttimer, Opentimer);
  }
  public boolean  ueberschritten(LocalDateTime a, LocalDateTime b) {
    if (a.isAfter(b)) return true;
    return false;
  }
  public String Ausgabe(LocalDateTime a, LocalDateTime b) {
    int Day = b.getDayOfMonth() - a.getDayOfMonth();
    int Hour = b.getHour() -a.getHour();
    int Minute = b.getMinute() - a.getMinute();
    int sec = b.getSecond() - a.getSecond();
    if (sec < 0) {
      sec = sec +60;
      Minute--;
    }
    if (Minute < 0) {
      Minute = 60 +Minute;
      Hour--;
    }
    if (Hour < 0)
    { 
      Hour = Hour +24;
      Day--;
    }
    return "Noch "+Day+ " Tage " + Hour+" Stunden " +Minute + "Minuten und " + sec + " Sekunden !!";
  }
Exception: 
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalDateTime;
	at processing.test.muttertagtest.Muttertagtest$Timer.<init>(Muttertagtest.java:51)
	at processing.test.muttertagtest.Muttertagtest.draw(Muttertagtest.java:29)
	at processing.core.PApplet.handleDraw(PApplet.java:1855)
	at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:476)
	at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:516)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime" on path: DexPathList[[zip file "/data/app/processing.test.muttertagtest-2/base.apk"],nativeLibraryDirectories=[/data/app/processing.test.muttertagtest-2/lib/arm, /system/lib, /vendor/lib]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
	... 5 more

Please format your code with </> when posting to the forum.

Also, your draw and Timer are missing their closing }

FWIW the example code runs fine in PDE Java mode with those corrections.

@Americanjoghurt ===
-as @jeremydouglass pointed out there are two missing brackets in your code
-as for the error it s probably caused by the fact that java.Time was added only for API 26 (Oreo)
-Anyway you can easily get hour and date with android using Calendar and creating some simple function:

import java.util.Locale;
import java.text.SimpleDateFormat;
import java.util.Calendar;

///////

void setup(){
String dateHeure = quelleDate();
println(dateHeure);
}
public static String quelleDate() {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy  - hh mm ", Locale.FRENCH);
        String strDate = sdf.format(c.getTime());
        // System.out.println("aujourdhui =======" +strDate);
        return strDate;
    }
1 Like