Java FX NullPointerException, ObservableList wird in View nicht angezeigt..

Jackcarver12

Mitglied
Hallo!
Ich bin im Rahmen eines privaten Projekts auf folgendes Problem gestoßen:
Immer wenn ich folgenden Command absetze, wird eine Exception geworfen.

[CODE lang="java" title="Problematischer Code" highlight="13"] Bestellposition[] bp= controller.getBestellungen();//gefüllt und nicht null
for (Bestellposition bpos : bp)
{
bpList.add(bpos);//objekt gefüllt und nicht null
System.out.println("ID" + bpos.getRid() + " Tisch: " + bpos.getTableno() + " DRINK: " + bpos.getDrink());
}
// System.out.println(bpList.get(1));//null ?????????????????????????????????????????
//BP ist gefüllt
//aber sobald es auf ObservableArray übertragen wird: collecting data
if(bpList != null)
{
//wie kann eine Nullpointerexception auftreten wenn ich !=null abfange?
listBPos.setItems(FXCollections.observableList(bpList));
//listBPos.getItems().setAll(bpList); //hier gehts schief
}[/CODE]

Ich arbeite in Gradle. Meine Oberfläche startet, sobald ich den problematischen Code in Zeile 13 auskommentiere.
Die Datenerhebung funktioniert einwandfrei. Durch einen Sysout in den entsprechenden Methoden zur generieren der benötigten Collections weiss ich, dass die returnten Listen nicht leer sind. Auch das Debugging beweist, dass die Listen gefüllt sind und es einen anderen Grund für die NullPointerException geben muss.

[CODE lang="java" title="Gradle Built"]plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'

}
mainClassName='newP.BKPR'
group 'example.org'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

javafx {
version = "15.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
//"javafx.graphics"


sourceSets {
main {
resources {
srcDirs = ["src/main/java"]
includes = ["**/*.fxml"]
}
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.8.8'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8'
compile 'com.squareup.okhttp:eek:khttp:2.5.0'
compile 'javax.mail:mail:1.4.7'

}
[/CODE]

Hier meine FXML
[CODE lang="java" title="FXML-Code"]<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.layout.AnchorPane?>
<!--xmlns="http://javafx.com/javafx/8.0.141" -->
<AnchorPane prefHeight="496.0" prefWidth="796.0" style="-fx-background-color: lightblue;" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="newP.BKPR">
<children>
<Label fx:id="lblOutput" layoutX="91.0" layoutY="129.0" prefHeight="17.0" prefWidth="118.0" />
<Button layoutX="646.0" layoutY="29.0" mnemonicParsing="false" text="Say Hello" />
<ListView fx:id="listBPos" layoutX="25.0" layoutY="84.0" prefHeight="298.0" prefWidth="249.0" />
<ListView fx:id="listMPos" layoutX="293.0" layoutY="84.0" prefHeight="298.0" prefWidth="242.0" />
<MenuBar layoutY="2.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</AnchorPane>
[/CODE]
[CODE lang="java" title="Oberflächencontroller"]package newP;

import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;

import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

import javax.mail.MessagingException;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class BKPR extends Application {
@FXML
private Label lblOutput;

@FXML
private ListView<Bestellposition> listBPos;
@FXML
private ListView<Mailobject> listMPos;


private Controller controller;
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws IOException, MessagingException, InterruptedException {
controller = new Controller();
Parent root = FXMLLoader.load(getClass().getResource("BKPR.fxml"));

Scene scene = new Scene(root, 800, 600);

primaryStage.setTitle("FXML Welcome");
primaryStage.setScene(scene);
primaryStage.show();
listenLaden();

}
public void listenLaden() throws IOException, InterruptedException, MessagingException {
//Für Bestellpositionen
ObservableList<Bestellposition> bpList = new ObservableList<Bestellposition>() {
@Override
public void addListener(ListChangeListener<? super Bestellposition> listChangeListener) {

}

@Override
public void removeListener(ListChangeListener<? super Bestellposition> listChangeListener) {

}

@Override
public boolean addAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public boolean setAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public boolean setAll(Collection<? extends Bestellposition> collection) {
return false;
}

@Override
public boolean removeAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public boolean retainAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public void remove(int i, int i1) {

}

@Override
public int size() {
return 0;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object o) {
return false;
}

@Override
public Iterator<Bestellposition> iterator() {
return null;
}

@Override
public Object[] toArray() {
return new Object[0];
}

@Override
public <T> T[] toArray(T[] ts) {
return null;
}

@Override
public boolean add(Bestellposition bestellposition) {
return false;
}

@Override
public boolean remove(Object o) {
return false;
}

@Override
public boolean containsAll(Collection<?> collection) {
return false;
}

@Override
public boolean addAll(Collection<? extends Bestellposition> collection) {
return false;
}

@Override
public boolean addAll(int i, Collection<? extends Bestellposition> collection) {
return false;
}

@Override
public boolean removeAll(Collection<?> collection) {
return false;
}

@Override
public boolean retainAll(Collection<?> collection) {
return false;
}

@Override
public void clear() {

}

@Override
public Bestellposition get(int i) {
return null;
}

@Override
public Bestellposition set(int i, Bestellposition bestellposition) {
return null;
}

@Override
public void add(int i, Bestellposition bestellposition) {

}

@Override
public Bestellposition remove(int i) {
return null;
}

@Override
public int indexOf(Object o) {
return 0;
}

@Override
public int lastIndexOf(Object o) {
return 0;
}

@Override
public ListIterator<Bestellposition> listIterator() {
return null;
}

@Override
public ListIterator<Bestellposition> listIterator(int i) {
return null;
}

@Override
public List<Bestellposition> subList(int i, int i1) {
return null;
}

@Override
public void addListener(InvalidationListener invalidationListener) {

}

@Override
public void removeListener(InvalidationListener invalidationListener) {

}
};
ObservableList<Bestellposition> emptyList= new ObservableList<Bestellposition>() {
@Override
public void addListener(ListChangeListener<? super Bestellposition> listChangeListener) {

}

@Override
public void removeListener(ListChangeListener<? super Bestellposition> listChangeListener) {

}

@Override
public boolean addAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public boolean setAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public boolean setAll(Collection<? extends Bestellposition> collection) {
return false;
}

@Override
public boolean removeAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public boolean retainAll(Bestellposition... bestellpositions) {
return false;
}

@Override
public void remove(int i, int i1) {

}

@Override
public int size() {
return 0;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object o) {
return false;
}

@Override
public Iterator<Bestellposition> iterator() {
return null;
}

@Override
public Object[] toArray() {
return new Object[0];
}

@Override
public <T> T[] toArray(T[] ts) {
return null;
}

@Override
public boolean add(Bestellposition bestellposition) {
return false;
}

@Override
public boolean remove(Object o) {
return false;
}

@Override
public boolean containsAll(Collection<?> collection) {
return false;
}

@Override
public boolean addAll(Collection<? extends Bestellposition> collection) {
return false;
}

@Override
public boolean addAll(int i, Collection<? extends Bestellposition> collection) {
return false;
}

@Override
public boolean removeAll(Collection<?> collection) {
return false;
}

@Override
public boolean retainAll(Collection<?> collection) {
return false;
}

@Override
public void clear() {

}

@Override
public Bestellposition get(int i) {
return null;
}

@Override
public Bestellposition set(int i, Bestellposition bestellposition) {
return null;
}

@Override
public void add(int i, Bestellposition bestellposition) {

}

@Override
public Bestellposition remove(int i) {
return null;
}

@Override
public int indexOf(Object o) {
return 0;
}

@Override
public int lastIndexOf(Object o) {
return 0;
}

@Override
public ListIterator<Bestellposition> listIterator() {
return null;
}

@Override
public ListIterator<Bestellposition> listIterator(int i) {
return null;
}

@Override
public List<Bestellposition> subList(int i, int i1) {
return null;
}

@Override
public void addListener(InvalidationListener invalidationListener) {

}

@Override
public void removeListener(InvalidationListener invalidationListener) {

}
};
Bestellposition leereBPos = new Bestellposition();
leereBPos.setName("keine Bestellungen verfügbar");
//Für Mails
ObservableList<Mailobject> mlList = new ObservableList<Mailobject>() {
@Override
public void addListener(ListChangeListener<? super Mailobject> listChangeListener) {

}

@Override
public void removeListener(ListChangeListener<? super Mailobject> listChangeListener) {

}

@Override
public boolean addAll(Mailobject... mailobjects) {
return false;
}

@Override
public boolean setAll(Mailobject... mailobjects) {
return false;
}

@Override
public boolean setAll(Collection<? extends Mailobject> collection) {
return false;
}

@Override
public boolean removeAll(Mailobject... mailobjects) {
return false;
}

@Override
public boolean retainAll(Mailobject... mailobjects) {
return false;
}

@Override
public void remove(int i, int i1) {

}

@Override
public int size() {
return 0;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object o) {
return false;
}

@Override
public Iterator<Mailobject> iterator() {
return null;
}

@Override
public Object[] toArray() {
return new Object[0];
}

@Override
public <T> T[] toArray(T[] ts) {
return null;
}

@Override
public boolean add(Mailobject mailobject) {
return false;
}

@Override
public boolean remove(Object o) {
return false;
}

@Override
public boolean containsAll(Collection<?> collection) {
return false;
}

@Override
public boolean addAll(Collection<? extends Mailobject> collection) {
return false;
}

@Override
public boolean addAll(int i, Collection<? extends Mailobject> collection) {
return false;
}

@Override
public boolean removeAll(Collection<?> collection) {
return false;
}

@Override
public boolean retainAll(Collection<?> collection) {
return false;
}

@Override
public void clear() {

}

@Override
public Mailobject get(int i) {
return null;
}

@Override
public Mailobject set(int i, Mailobject mailobject) {
return null;
}

@Override
public void add(int i, Mailobject mailobject) {

}

@Override
public Mailobject remove(int i) {
return null;
}

@Override
public int indexOf(Object o) {
return 0;
}

@Override
public int lastIndexOf(Object o) {
return 0;
}

@Override
public ListIterator<Mailobject> listIterator() {
return null;
}

@Override
public ListIterator<Mailobject> listIterator(int i) {
return null;
}

@Override
public List<Mailobject> subList(int i, int i1) {
return null;
}

@Override
public void addListener(InvalidationListener invalidationListener) {

}

@Override
public void removeListener(InvalidationListener invalidationListener) {

}
};
ObservableList<Mailobject>emptyMList = new ObservableList<Mailobject>() {
@Override
public void addListener(ListChangeListener<? super Mailobject> listChangeListener) {

}

@Override
public void removeListener(ListChangeListener<? super Mailobject> listChangeListener) {

}

@Override
public boolean addAll(Mailobject... mailobjects) {
return false;
}

@Override
public boolean setAll(Mailobject... mailobjects) {
return false;
}

@Override
public boolean setAll(Collection<? extends Mailobject> collection) {
return false;
}

@Override
public boolean removeAll(Mailobject... mailobjects) {
return false;
}

@Override
public boolean retainAll(Mailobject... mailobjects) {
return false;
}

@Override
public void remove(int i, int i1) {

}

@Override
public int size() {
return 0;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object o) {
return false;
}

@Override
public Iterator<Mailobject> iterator() {
return null;
}

@Override
public Object[] toArray() {
return new Object[0];
}

@Override
public <T> T[] toArray(T[] ts) {
return null;
}

@Override
public boolean add(Mailobject mailobject) {
return false;
}

@Override
public boolean remove(Object o) {
return false;
}

@Override
public boolean containsAll(Collection<?> collection) {
return false;
}

@Override
public boolean addAll(Collection<? extends Mailobject> collection) {
return false;
}

@Override
public boolean addAll(int i, Collection<? extends Mailobject> collection) {
return false;
}

@Override
public boolean removeAll(Collection<?> collection) {
return false;
}

@Override
public boolean retainAll(Collection<?> collection) {
return false;
}

@Override
public void clear() {

}

@Override
public Mailobject get(int i) {
return null;
}

@Override
public Mailobject set(int i, Mailobject mailobject) {
return null;
}

@Override
public void add(int i, Mailobject mailobject) {

}

@Override
public Mailobject remove(int i) {
return null;
}

@Override
public int indexOf(Object o) {
return 0;
}

@Override
public int lastIndexOf(Object o) {
return 0;
}

@Override
public ListIterator<Mailobject> listIterator() {
return null;
}

@Override
public ListIterator<Mailobject> listIterator(int i) {
return null;
}

@Override
public List<Mailobject> subList(int i, int i1) {
return null;
}

@Override
public void addListener(InvalidationListener invalidationListener) {

}

@Override
public void removeListener(InvalidationListener invalidationListener) {

}
};
Mailobject emptyMo = new Mailobject();
emptyMo.setSender("Keine Mails vorhanden");
emptyMList.add(emptyMo);
System.out.println("BPOSumsetzung");
//BPOS umsetzung bpList

Bestellposition[] bp= controller.getBestellungen();//gefüllt und nicht null
for (Bestellposition bpos : bp)
{
bpList.add(bpos);//objekt gefüllt und nicht null
System.out.println("ID" + bpos.getRid() + " Tisch: " + bpos.getTableno() + " DRINK: " + bpos.getDrink());
}
// System.out.println(bpList.get(1));//null ?????????????????????????????????????????
//BP ist gefüllt
//aber sobald es auf ObservableArray übertragen wird: collecting data
if(bpList != null)
{
//wie kann eine Nullpointerexception auftreten wenn ich !=null abfange?
listBPos.setItems(FXCollections.observableList(bpList));
//listBPos.getItems().setAll(bpList); //hier gehts schief
}
else
{
//emptyList.add(leereBPos);
// listBPos.getItems().setAll(emptyList);
}
//Mailobjects umsetzung
System.out.println("MPosumsetzung");

mlList = controller.getMails();
if(mlList!=null)
{
System.out.println("test");
// listMPos.getItems().setAll(mlList); //hier gehts schief
// listMPos.setItems(mlList);
}
else
{
// listMPos.getItems().setAll(emptyMList);
}


}
}
[/CODE]

Ich bin alle Methoden zur befüllung der Listen durchgegangen und in keinem Fall sind sie leer oder unbefüllt. Die Daten erhalte ich von einem Node.js Server der auch über die gesamte Zeit läuft. (Ich erhalte die korrekten Daten vom Server)

Mein Problem bezieht sich also auf die Ausgabe im der ListView.

Ich bin ehrlich gesagt langsam schon etwas entmutigt. Ich sitze schon einige Tage an diesem Exception. Der Invoke steht nur für die hinten angestellte NullPointerException:
[CODE lang="java" title="Fehlerausgabe"]20:30:42: Executing task 'run'...


> Configure project :
Project : => no module-info.java found

> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :configJavafxRun

> Task :run
BPOSumsetzung
ID1mhc6nmh8kpqn1eg4 Tisch: 3 DRINK: BermudaRose
ID1mhc6nmh8kpqn1eg5 Tisch: 3 DRINK: Cosmopolitan
ID1mhc6nbm0kps4oiez Tisch: 7 DRINK: AprilShower
ID1mhc6nbm0kps4oif1 Tisch: 7 DRINK: BermudaRose
ID1mhc6nbxgkps6prm2 Tisch: 4 DRINK: CubaLibre
ID1mhc6nbxgkps6prm4 Tisch: 4 DRINK: BermudaRose
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
at newP.BKPR.listenLaden(BKPR.java:739)
at newP.BKPR.start(BKPR.java:49)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Exception running application newP.BKPR

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2.4\jbr\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
4 actionable tasks: 3 executed, 1 up-to-date
20:30:47: Task execution finished 'run'.
[/CODE]

Für jeden Tipp, Ratschlag oder Hinweis bin ich äußerst dankbar.
Der Code ist nicht 100% sauber, ich versuche momentan über evolutionäres Prototyping zu arbeiten.
Dementsprechend wird dieser nach erwiesener Funktionalität neu aufbereitet.
LG J
 

Jackcarver12

Mitglied
Hallo! Vielen Dank für die Tipps erstmal!
@mrBrown diese Ergänzungen zur ObservableList wurden automatisch erstellt. Ich konnte sie leider bisher nicht anders implementieren.
Ich schaue mich mal in der Doku um und melde mich zurück!
LG J
 

Jackcarver12

Mitglied
Also ich habe meinen Code angepasst, zumindest meine ich die Anweisungen richtig umgesetzt zu haben:

[CODE lang="java" title="neuer Code fuelleListe"] public void listenLaden() throws IOException, InterruptedException, MessagingException {
ObservableList<Bestellposition> bpList
= FXCollections.observableArrayList();
//Für Bestellpositionen

ObservableList<Bestellposition> emptyList= FXCollections.observableArrayList();
Bestellposition leereBPos = new Bestellposition();
leereBPos.setName("keine Bestellungen verfügbar");
//Für Mails
ObservableList<Mailobject> mlList = FXCollections.observableArrayList();
ObservableList<Mailobject>emptyMList = FXCollections.observableArrayList();
Mailobject emptyMo = new Mailobject();
emptyMo.setSender("Keine Mails vorhanden");
emptyMList.add(emptyMo);
System.out.println("BPOSumsetzung");
//BPOS umsetzung bpList

bpList= controller.getBestellungen();//gefüllt und nicht null

// System.out.println(bpList.get(1));//null ?????????????????????????????????????????
//BP ist gefüllt
//aber sobald es auf ObservableArray übertragen wird: collecting data
if(bpList != null)
{
//wie kann eine Nullpointerexception auftreten wenn ich !=null abfange?
listBPos.getItems().setAll(bpList); //hier gehts schief
listBPos.setItems(FXCollections.observableList(bpList));

}
else
{
//emptyList.add(leereBPos);
// listBPos.getItems().setAll(emptyList);
}
//Mailobjects umsetzung
System.out.println("MPosumsetzung");

mlList = controller.getMails();
if(mlList!=null)
{
System.out.println("test");
// listMPos.getItems().setAll(mlList); //hier gehts schief
// listMPos.setItems(mlList);
}
else
{
// listMPos.getItems().setAll(emptyMList);
}


}[/CODE]
An der Stelle ist es vielleicht auch für euch hilfreich die getBestellung() Methode zu kennen. Da konnte ich aber gut debuggen und alle angeforderten Informationen werden auch über sysout ausgegeben. Listen sind gefüllt und können returned werden. Ich bin sehr ratlos und mir eigentlich sicher, dass das Problem kein logisches sondern ein technisches ist.
[CODE lang="java" title="getBestellung()"]public ObservableList<Bestellposition> getBestellungen() throws IOException, InterruptedException
{

//url ist eine IP und wurde daher hier entfernt
String positionenS = rq.makeGetRequest(url);

if(positionenS!=null)
{

GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson1 = gsonBuilder.create();

Bestellposition[] bp = gson1.fromJson(positionenS, Bestellposition[].class);

for (Bestellposition bpos : bp)//Liste befüllen
{
dlmPositionen.add(bpos);
System.out.println("ID" + bpos.getRid() + " Tisch: " + bpos.getTableno() + " DRINK: " + bpos.getDrink());
}


return dlmPositionen; //kann nicht null sein weil in foreach mit gefülltem
//objekt gefüllt
}
else
{
System.out.println("Leere Positionsliste");
return null;
}
//Pos füllen



}

}[/CODE]

Bin jetzt nochmal in den debugging Mode rein. Mir ist schon letztes mal aufgefallen, dass beim Inhalt der bpList immer angezeigt wird: Collecting Data:
fehler.PNG

In der getBestellungen() Methode ist das Array, das letztlich in die observable umgewandelt wird ebenfalls befüllt:
fehler2.PNG
Nun kann es natürlich sein, dass die Umwandlung selbst fehlschlägt.
dlmPositionen ist die Observable welche zurückgegeben wird.
[CODE lang="java" title="Fehlerausgabe" highlight="9,25"]BPOSumsetzung
ID1mhc6nmh8kpqn1eg4 Tisch: 3 DRINK: BermudaRose
ID1mhc6nmh8kpqn1eg5 Tisch: 3 DRINK: Cosmopolitan
ID1mhc6nbm0kps4oiez Tisch: 7 DRINK: AprilShower
ID1mhc6nbm0kps4oif1 Tisch: 7 DRINK: BermudaRose
ID1mhc6nbxgkps6prm2 Tisch: 4 DRINK: CubaLibre
ID1mhc6nbxgkps6prm4 Tisch: 4 DRINK: BermudaRose
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
at newP.BKPR.listenLaden(BKPR.java:78)
at newP.BKPR.start(BKPR.java:49)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Exception running application newP.BKPR

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2.4\jbr\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s[/CODE]

Ich danke wie immer für jeden Hinweis!
 

Jackcarver12

Mitglied
UPDATE:
Mittlerweise ist die bpList erfolgreich befüllt. Der Tipp mit den FXCollections war super @mrBrown !
Nach Ausführung erhalte ich ja doch noch eine Exception:
[CODE lang="java" title="java fx Exception"]Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
at newP.BKPR.listenLaden(BKPR.java:78)
at newP.BKPR.start(BKPR.java:48)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Exception running application newP.BKPR

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2.4\jbr\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3m 24s
4 actionable tasks: 3 executed, 1 up-to-date[/CODE]

Nun gilt es natürlich für mich herauszufinden was es damit auf sich hat.
Bisher war die Recherche im Internet nicht zielführend.
Wobei ich mir auch nicht sicher bin, ob ich unter dem richtigen Stichwort suche.
Ich hatte mir mal gemerkt, dass die InvocationTargetException nur ein Strohmann für weitere Exceptions ist.
Ich kann den Fehler nun auf diese Zeile einschränken:
[CODE lang="java" title="Code der die NullPointerException wirft" highlight="5"] if(bpList != null)
{
//wie kann eine Nullpointerexception auftreten wenn ich !=null abfange?

listBPos.setItems(bpList);

}[/CODE]

Im Debuggin komme ich auch bis zur Anweisung. Sobald ich aber weiter gehe, schmiert er mir ab.
LG J
 
K

kneitzel

Gast
Da fehlen uns die Details. Ist die Variable in einem Controller, so dass der FXMLLoader die setzen könnte (durch @FXML Annotation). Oder ist es kein Controller? Dann müsstest Du das ggf. selbst noch setzen. (Aber dann wäre da die Überlegung, wie man das in den Controller bekommen kann. Denn Zugriff auf die View außerhalb des Controllers ist nicht wünschenswert ...
 

mrBrown

Super-Moderator
Mitarbeiter
Du musst Application und Controller trennen – der Fehler kommt aktuell, weil du zwei Instanzen von BKPR hast:
Die von JavaFX erzeugte Application-Instanz und die von JavaFX erzeugte Controller-Instanz.

listenLaden rufst du in der Application-Instanz auf, initialisiert sind die Control-Elemente aber nur in der Controller-Instanz.
 

Jackcarver12

Mitglied
[CODE lang="java" title="ControllerCode"]package newP;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;

import javax.mail.MessagingException;
import java.io.IOException;
import java.util.*;


public class Controller
{
//public BKPR view;
private RequestHandler rq;
private MailChecker mc;
private ArrayList<Bestellposition> positionen= new ArrayList<>();
private Gson gson;
//private BKPR bkpr;
private ObservableList<Bestellposition> dlmPositionen;
private ObservableList<Mailobject>dlmMails;





public Controller() throws InterruptedException, IOException, MessagingException
{

// bkpr = new BKPR();
mc=new MailChecker();
dlmPositionen = FXCollections.observableArrayList();
dlmMails=FXCollections.observableArrayList();
MailChecker mc=new MailChecker();
rq = new RequestHandler();

//Befüllen der Listen
//getMails();
//getBestellungen();
// Application.launch(BKPR.class, args);

}


public ObservableList<Mailobject> getMails() throws IOException, MessagingException
{
//Mails füllen
dlmMails= mc.getAllMails();
return dlmMails;
/*
if(bkpr.getListBPos()==null)
{
System.out.println("Leere Liste");

}
else {
bkpr.getListMPos().setItems(dlmMails);
}

*/



/*
ListView<String> list = new ListView<String>();
ObservableList<String> items =FXCollections.observableArrayList (
"Single", "Double", "Suite", "Family App");
list.setItems(items);
*/
}


public boolean deleteOrder(Bestellposition bp) throws IOException
{
Bestellposition obj = new Bestellposition();
//obj aus Liste lesen
//zensierte URL
String json = gson.toJson(obj);
String bestellungJSON = "noch zu füllen";

rq.makePostRequest(url, bestellungJSON);
//try to check for success or failure
return true;
}

// public ObservableList<Bestellposition> getBestellungen() throws IOException, InterruptedException
public ObservableList<Bestellposition> getBestellungen() throws IOException, InterruptedException
{

//Zensierte URL
String positionenS = rq.makeGetRequest(url);

if(positionenS!=null)
{

GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson1 = gsonBuilder.create();

Bestellposition[] bp = gson1.fromJson(positionenS, Bestellposition[].class);

for (Bestellposition bpos : bp)//Liste befüllen
{
dlmPositionen.add(bpos);
System.out.println("ID" + bpos.getRid() + " Tisch: " + bpos.getTableno() + " DRINK: " + bpos.getDrink());
}


return dlmPositionen; //nicht null
}
else
{
System.out.println("Leere Positionsliste");
Bestellposition leererBP = new Bestellposition();
leererBP.setName("Keine Bestellungen");
dlmPositionen.clear();
dlmPositionen.add(leererBP);
return dlmPositionen;
}
//Pos füllen



}

}
[/CODE]

FXMLMain Code
Java:
package newP;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

import javax.mail.MessagingException;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class BKPR extends Application implements Initializable {

    @FXML
    private Label lblOutput;
    @FXML
    private ListView<Bestellposition> listBPos;
    @FXML
    private ListView<Mailobject> listMPos;

    private Controller controller;
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws IOException, MessagingException, InterruptedException {



        Parent root = FXMLLoader.load(getClass().getResource("BKPR.fxml"));
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setTitle("FXML Welcome");
        primaryStage.setScene(scene);
        primaryStage.show();
        controller = new Controller();
        listenLaden();


    }
    public void listenLaden() throws IOException, InterruptedException, MessagingException {
        ObservableList<Bestellposition> bpList
                = FXCollections.observableArrayList();
        //Für Bestellpositionen

        ObservableList<Bestellposition> emptyList= FXCollections.observableArrayList();
        Bestellposition leereBPos = new Bestellposition();
        leereBPos.setName("keine Bestellungen verfügbar");
        //Für Mails
        ObservableList<Mailobject> mlList = FXCollections.observableArrayList();
        ObservableList<Mailobject>emptyMList = FXCollections.observableArrayList();
        Mailobject emptyMo = new Mailobject();
        emptyMo.setSender("Keine Mails vorhanden");
        emptyMList.add(emptyMo);
        System.out.println("BPOSumsetzung");
        //BPOS umsetzung    bpList

        bpList= controller.getBestellungen();//gefüllt und nicht null

       // System.out.println(bpList.get(1));//null ?????????????????????????????????????????
        //BP ist gefüllt
        //aber sobald es auf ObservableArray übertragen wird: collecting data
        if(bpList != null)
        {
            //wie kann eine Nullpointerexception auftreten wenn ich !=null abfange?

            listBPos.setItems(bpList);

        }
        else
        {
            //emptyList.add(leereBPos);
          // listBPos.getItems().setAll(emptyList);
        }
        //Mailobjects umsetzung
        System.out.println("MPosumsetzung");

        mlList = controller.getMails();
        if(mlList!=null)
        {
            System.out.println("test");
           // listMPos.getItems().setAll(mlList); //hier gehts schief
           // listMPos.setItems(mlList);
        }
        else
        {
           // listMPos.getItems().setAll(emptyMList);
        }


    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {


    }
}
Ich erzeuge in meinem View-Controller einen weiteren Controller. Ok ich gebe zu, dass das nicht meine hellste Aktion war. Der Controller stellt sich allerdings als ganz normale Klasse dar. Ich habe im gesamten Programm nur eine Main() und die ist in der JavaFX-Applicaiton enthalten.
Dennoch sollte es beim erzeugen des Controllers kein Problem geben. Instanz der Oberfläche(BKPR) existiert meines Wissens nur einmal. Controller fungiert als gewöhnliche Klasse mit Methoden. Vielleicht ein Initialisierungsproblem?
LG J
 

mrBrown

Super-Moderator
Mitarbeiter
Durch das launch(args); in BKPR wird eine Instanz von BKPR erzeugt, die als Application genutzte wird.
Durch fx:controller="newP.BKPR"> in der FXML wird eine zweite Instanz von BKPR erzeugt, die als Controller genutzt wird.

Beide Instanzen haben nichts miteinander zu tun, die sind völlig unabhängig.


listenLaden wird in der ersten Instanz aufgerufen, listBPos wird aber nur in der zweiten Instanz initialisiert.
 

Jackcarver12

Mitglied
@mrBrown ok. Das ist ja schonmal eine heiße Spur.
Vielen Dank dafür!
Also muss ich es hinbekommen, dass hier nur eine, gemeinsame, Controller-Klasse referenziert wird.
Dass beim Kommando launch(args) eine neue Instanz erzeugt wird, war mir nicht klar.

Ich muss nun also meiner FXML die korrekte Controller-instanz zuweisen?
Wie trenne ich das jetzt. Ich muss gestehen, mir fehlt gerade ein Konzept zur Umsetzung.
Ich glaube nicht, dass ich 100 % verstanden habe was dieser Fehler für mich bedeutet.

So wie ich es verstanden habe, muss ich einen Controller für meine Oberfläche angeben. Das habe ich im SceneBuilder auch so umgesetzt. Kenne es tatsächlich auch nicht anders.
LG J
 
Zuletzt bearbeitet:

Jackcarver12

Mitglied
UPDATE:
Er schmiert nicht mehr ab.
Keine NullPointerException mehr.
Keine InvokedTargetException mehr.

Nun bleibt letztlich nur noch das Problem mit der ListView, die sich nicht befüllen lässt.
Wir waren stehen geblieben bei der doppelten BKPR-Instanz.
Ich habe nochmal nachgesehen und mein Package heisst "newP" daher muss es ja auch beim Zuweisen der Controllerklasse "newP.BKPR" heissen.

wenn ich das bkpr-Objekt selektiere, habe ich Zugriff auf die Control-Objekte und kann mir die auswählen die ich habe.
Aber der Inhalt der ListView wird leider nicht angezeigt.

fehler3.PNG
wie man hier sehen kann, ist das bkpr-Objekt also die Instanz der View auch befüllt. Sie wurde also dem Controller korrekt übergeben:
fehler4.PNG
Dennoch erhalte ich beim Run folgende Sicht:
fehler5.PNG
Auf der rechten Seite sieht man, dass alle Methoden korrekt arbeiten. Ich erhalte meine Daten vom Node.js-Server und auch mein Mailkonto wird korrekt ausgelesen. Es muss also zwangsläufig an der FXML-Datei oder dem FXML-Controller liegen(BKPR).
Zum Befüllen wurde folgender Command verwendet:
[CODE lang="java" title="Füllmethode(allgemein)"]
bkpr.getlistview().setItems(observableListe);[/CODE]

Das Projekt steht kurz vor dem Abschluss und scheitert gerade einfach an einer unbedeutenden Kleinigkeit.
Ich freue mich über jeden Tipp, jede Idee.
LG J
 

lam_tr

Top Contributor
UPDATE:
Er schmiert nicht mehr ab.
Keine NullPointerException mehr.
Keine InvokedTargetException mehr.

Nun bleibt letztlich nur noch das Problem mit der ListView, die sich nicht befüllen lässt.
Wir waren stehen geblieben bei der doppelten BKPR-Instanz.
Ich habe nochmal nachgesehen und mein Package heisst "newP" daher muss es ja auch beim Zuweisen der Controllerklasse "newP.BKPR" heissen.

wenn ich das bkpr-Objekt selektiere, habe ich Zugriff auf die Control-Objekte und kann mir die auswählen die ich habe.
Aber der Inhalt der ListView wird leider nicht angezeigt.

Anhang anzeigen 15523
wie man hier sehen kann, ist das bkpr-Objekt also die Instanz der View auch befüllt. Sie wurde also dem Controller korrekt übergeben:
Anhang anzeigen 15524
Dennoch erhalte ich beim Run folgende Sicht:
Anhang anzeigen 15527
Auf der rechten Seite sieht man, dass alle Methoden korrekt arbeiten. Ich erhalte meine Daten vom Node.js-Server und auch mein Mailkonto wird korrekt ausgelesen. Es muss also zwangsläufig an der FXML-Datei oder dem FXML-Controller liegen(BKPR).
Zum Befüllen wurde folgender Command verwendet:
[CODE lang="java" title="Füllmethode(allgemein)"]
bkpr.getlistview().setItems(observableListe);[/CODE]

Das Projekt steht kurz vor dem Abschluss und scheitert gerade einfach an einer unbedeutenden Kleinigkeit.
Ich freue mich über jeden Tipp, jede Idee.
LG J
Wenn du die observableListe nimmst und Inhalt addest zeigt der nichts an? Was ist mit der ListView wenn du sie anklickst?
 

Jackcarver12

Mitglied
Ok ich habe mein Problem jetzt erkannt.
Die FXML-Injection funktioniert nicht.
Warum das so ist weiss ich nicht.
Wenn ich im Debugging ein Element anwähle, welches zur Oberfläche gehört, so ist dieses auch nach der Initialize mit null gefüllt!
Das ist also mein Problem.
Nun stellt sich die Frage wie ich in einer Gradleumgebung diese Art von Problem umgehe bzw. löse.
Ich weiss nicht, ob es sich um ein Fehler in den dependencies handelt oder ich beim Verbinden der FXML-Datei und der Controllerklasse gepatzt habe. @mrBrown ich konnte deine Beschreibung des Fehlers bisher nicht bestätigen. Auch ein Kollege der sich durchaus hier und dort damit auseinandersetzt, meinte er kann leider nicht erkennen wie hier mehrere Instanzen existieren. Vielleicht übersehe ich aber auch einfach etwas.

Ich hoffe jemand kann mir zur Injection vielleicht einen Tipp geben.
[CODE lang="java" title="Deklaration"]public class BKPR extends Application {

@FXML
private Label lblOutput;
@FXML
private Button btntest;
@FXML
private ListView<Bestellposition> listBPos;
@FXML
private ListView<Mailobject> listMPos;[/CODE]

fehler7.PNG
fehler6.PNG
Vielen Dank für die bisherigen Ratschläge und Anregungen.
Das hilft mir wirklich sehr.
LG J
 
Zuletzt bearbeitet:

lam_tr

Top Contributor
Ok ich habe mein Problem jetzt erkannt.
Die FXML-Injection funktioniert nicht.
Warum das so ist weiss ich nicht.
Wenn ich im Debugging ein Element anwähle, welches zur Oberfläche gehört, so ist dieses auch nach der Initialize mit null gefüllt!
Das ist also mein Problem.
Nun stellt sich die Frage wie ich in einer Gradleumgebung diese Art von Problem umgehe bzw. löse.
Ich weiss nicht, ob es sich um ein Fehler in den dependencies handelt oder ich beim Verbinden der FXML-Datei und der Controllerklasse gepatzt habe. @mrBrown ich konnte deine Beschreibung des Fehlers bisher nicht bestätigen. Auch ein Kollege der sich durchaus hier und dort damit auseinandersetzt, meinte er kann leider nicht erkennen wie hier mehrere Instanzen existieren. Vielleicht übersehe ich aber auch einfach etwas.

Ich hoffe jemand kann mir zur Injection vielleicht einen Tipp geben.
[CODE lang="java" title="Deklaration"]public class BKPR extends Application {

@FXML
private Label lblOutput;
@FXML
private Button btntest;
@FXML
private ListView<Bestellposition> listBPos;
@FXML
private ListView<Mailobject> listMPos;[/CODE]

Anhang anzeigen 15559
Anhang anzeigen 15558
Vielen Dank für die bisherigen Ratschläge und Anregungen.
Das hilft mir wirklich sehr.
LG J
Du kannst die Steuerlemente in der Controller Klasse über @FXML laden, in der Application Klasse macht das wenig Sinn
 

mrBrown

Super-Moderator
Mitarbeiter
@mrBrown ich konnte deine Beschreibung des Fehlers bisher nicht bestätigen. Auch ein Kollege der sich durchaus hier und dort damit auseinandersetzt, meinte er kann leider nicht erkennen wie hier mehrere Instanzen existieren. Vielleicht übersehe ich aber auch einfach etwas.
Dein Post hier ist eine Bestätigung meiner Fehlerbeschreibung ;)
Setz einen Breakpoint in initialize und einen in start, und vergleich die beiden this, daran könnte man das u.U. erkennen.

Ansonsten wie gesagt: Trenn Controller und Application, dann wird der Fehler auf "magische Art und Weise" verschwinden.
 

Jackcarver12

Mitglied
Aber das ist doch meine Controller Klasse.
fehler8.PNG
Ich denke wir verstehen alle etwas anderes unter einem Controller.
Ich kenne das noch aus Swing-Anwendungen.
Da hat man den Controller manuell angelegt.
Ich habe eine JavaFx-Anwendung erzeugt.
Dementsprechend ist darin meine MAIN und meine @FXML Annotations
Und zugehörig coexistiert eine FXML-Datei die ich in meiner JavaFx-Anwendung referenziere.
Ich verstehe nicht wie ich es anders umsetzen soll.

Bitte einigen.
Entweder BKPR.java (die Klasse mit dem grünen Dreieck) ist mein Controller, oder Controller.java

Den Controller habe ich eigentlich nur geschrieben, damit ich die Logik aus der View trennen kann.
Das MVC wurde zumindest ansatzweise umgesetzt. Ich weiss, dass es nicht perfekt ist.
Könnt es daran liegen, dass ich mit Gradle arbeite?
 

mrBrown

Super-Moderator
Mitarbeiter
Mit Controller meine ich die Klasse, die als Controller in der FXML eingetragen ist.

Das ist bei dir aktuell BKPR, die gleichzeitig auch die Application-Klasse ist, was deine Probleme verursacht, da JavaFX damit zwei verschiedene Instanzen der Klasse erzeugt.
 

Jackcarver12

Mitglied
UPDATE
Ich kann nun sicher sagen, dass es etwas mit der FXML-Datei zu tun hat bzw. mit dem Laden der FXML-Datei.
Die Datei wird nicht gefunden. Das erkennt man daran, dass ich jeden möglichen Namen im load-Prozess eingeben kann.
Die Exception bleibt gleich, bis ich die Elemente Manuell "im Code der start-Methode".
Und dann funktioniert auch alles.

Also gibts ein Problem beim laden der Datei:
Hier mein aktueller Code. Ich hoffe wir können das Problem über diesen Hintergrund lösen.
[CODE lang="java" title="FX-Klasse"]import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;

public class Main extends Application {
private ObservableList<String> bposListe;
private Controller controller;

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws IOException {
/*
primaryStage.setTitle("Hello JavaFX!");
Button btn = new Button();
ListView<String> listBPos = new ListView<>();
listBPos.setMinHeight(100);
listBPos.setMinWidth(100);
listBPos.setMaxHeight(110);
listBPos.setMaxWidth(110);
btn.setText("Hello JavaFX!");
btn.setOnAction( (event) -> Platform.exit() );
Pane root = new StackPane();
root.getChildren().add(listBPos);
primaryStage.setScene(new Scene(root, 600, 500));
primaryStage.show();
bposListe= FXCollections.observableArrayList();
bposListe.add("Servus");
listBPos.setItems(bposListe);

*/
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("BKPR.fxml"));
VBox root = (VBox) loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Lab 3");;
primaryStage.show();
}





}
[/CODE]
Der auskommentierte Code kennzeichnet alles was funktional ist. Verwende ich den Code ab FXMLLoader, so stürzt alles ab.
Hier meine FXML-Datei:
[CODE lang="java" title="FXML-Datei"]<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="Controller"
prefHeight="400.0" prefWidth="600.0">

</AnchorPane>
[/CODE]
Hier mein aktueller Aufbau:
Fehler9.PNG

Es muss etwas mit der Load-Anweisung zu tun haben....
Egal wo ich die FXML-Datei ablege.
Wie immer freue mich über jede Anregung und jeden Tipp.
LG J
 

mrBrown

Super-Moderator
Mitarbeiter
Ich kann nun sicher sagen, dass es etwas mit der FXML-Datei zu tun hat bzw. mit dem Laden der FXML-Datei.
Die Datei wird nicht gefunden. Das erkennt man daran, dass ich jeden möglichen Namen im load-Prozess eingeben kann.
Wie auf den vorherigen Screenshots zu sehen funktionierte das Laden der FXML zu Anfang:
fehler7.PNG
Das hatte als bisher nichts mit dem Laden der FXML zu tun.

Wenn es jetzt ein Problem ist, solltest du zu einem vorherigen Stand zurück...
 

Jackcarver12

Mitglied
[CODE lang="java" title="Fehler"]Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3246)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
at newP.BKPR.start(BKPR.java:24)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Exception running application newP.BKPR
:run (Thread[Execution worker for ':' Thread 7,5,main]) completed. Took 1.079 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2.4\jbr\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s[/CODE]

Erhalte immer den selber Fehler.
Als problematische Zeile wird mir diese markiert:
Java:
 AnchorPane root = (AnchorPane) FXMLLoader.load(getClass().getClassLoader().getResource("../../resources/View.fxml"));

Ich weiss, dass es schon funktioniert hat. Aber jetzt eben nicht mehr. Ich weiss auch nicht warum.
Ich programmiere jetzt schon länger JAVA. Aber sowas wie in Gradle hab ich noch nie erlebt.
Absolute Ratlosigkeit.
 

Jackcarver12

Mitglied
UPDATE:
Ich bin jetzt aus Gradle rausgeswitcht.
Das hatte einfach keinen Sinn mehr.
Hab eine einfache JavaFX Anwendung erstellt.
Hier ist der Code und mein Fehler:

[CODE lang="java" title="HTTP-Request-Klasse"]package sample;

import okhttp3.*;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class RequestHandler {
private static HttpURLConnection con;
private OkHttpClient client;
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");


public String makeGetRequest(String url) throws IOException, InterruptedException {//gives us all our orderpositions
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response);
return response.body();
}

public String makePostRequest(String url, String json) throws IOException {

client = new OkHttpClient();
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
}
[/CODE]

FXML-Datei
Java:
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.2-internal" fx:controller="sample.Controller">
   <columnConstraints>
      <ColumnConstraints />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints />
   </rowConstraints>
   <children>
      <AnchorPane prefHeight="363.0" prefWidth="511.0">
         <children>
            <ListView fx:id="listBPos" layoutX="29.0" layoutY="14.0" prefHeight="200.0" prefWidth="200.0" />
            <ListView fx:id="listMPos" layoutX="288.0" layoutY="14.0" prefHeight="200.0" prefWidth="200.0" />
         </children>
      </AnchorPane>
   </children>
</GridPane>

[CODE lang="java" title="Main"]package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

Controller controller;

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();



}


public static void main(String[] args) {
launch(args);
}
}
[/CODE]

Mailabrufklasse.
Java:
package sample;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import javax.mail.*;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;

public class MailChecker {
    private Properties props;
    private MailChecker MailUtils;

    public ObservableList<Mailobject> getAllMails() throws IOException, MessagingException {
/*
        Session session = MailUtils.getGMailSession(
                JOptionPane.showInputDialog( "user" ),
                JOptionPane.showInputDialog( "pass" ) );

 */
        ObservableList<Mailobject> dlmMails= FXCollections.observableArrayList();
        Session session = getGMailSession("testbarkeeper@gmail.com","Jackcarver12");
        Folder inbox = openPop3InboxReadOnly( session );
        printAllTextPlainMessages( inbox );

        if(inbox.getMessages()!=null)
        {
            for (Message m : inbox.getMessages())
            {
                Mailobject mo = new Mailobject();
                mo.setSubject(m.getSubject());
                mo.setDate(m.getSentDate());
                mo.setSender(Arrays.toString(m.getFrom()));
                dlmMails.add(mo);
            }
        }
        else
        {
            System.out.println("Sie haben keine Mails");
        }
        printAllTextPlainMessages(inbox);
        closeInbox( inbox );
        return dlmMails;
    }

    public static Session getGMailSession(String user, String pass )
    {
        final Properties props = new Properties();

        // Zum Empfangen
        props.setProperty( "mail.pop3.host", "pop.gmail.com" );
        props.setProperty( "mail.pop3.user", user );
        props.setProperty( "mail.pop3.password", pass );
        props.setProperty( "mail.pop3.port", "995" );
        props.setProperty( "mail.pop3.auth", "true" );
        props.setProperty( "mail.pop3.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory" );

        // Zum Senden
        props.setProperty( "mail.smtp.host", "smtp.gmail.com" );
        props.setProperty( "mail.smtp.auth", "true" );
        props.setProperty( "mail.smtp.port", "465" );
        props.setProperty( "mail.smtp.socketFactory.port", "465" );
        props.setProperty( "mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory" );
        props.setProperty( "mail.smtp.socketFactory.fallback", "false" );

        return Session.getInstance( props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication( props.getProperty( "mail.pop3.user" ),
                        props.getProperty( "mail.pop3.password" ) );
            }
        } );
//    session.setDebug( true );
    }
    // ...


    public static Folder openPop3InboxReadOnly( Session session )
            throws MessagingException
    {
        Store store = session.getStore( "pop3" );
        store.connect();

        Folder folder = store.getFolder( "INBOX" );
        folder.open( Folder.READ_ONLY );

        return folder;
    }
    public static void closeInbox( Folder folder ) throws MessagingException
    {
        folder.close( false );
        folder.getStore().close();
    }
    public static   void printAllTextPlainMessages( Folder folder )
            throws MessagingException, IOException
    {
        for ( Message m : folder.getMessages() )
        {
            System.out.println( "\nNachricht:" );
            System.out.println( "Von: " + Arrays.toString(m.getFrom()) );
            System.out.println( "Betreff: " + m.getSubject() );
            System.out.println( "Gesendet am: " + m.getSentDate() );
            System.out.println( "Content-Type: " +
                    new ContentType( m.getContentType() ) );

            if ( m.isMimeType( "text/plain" ) )
                System.out.println( m.getContent() );
        }
    }


    public static void sendGMX() throws MessagingException
    {
        String sender = "bkpr@gmx.de";
        String password = "my.password";
        String receiver = "my-receiver@gmail.com";

        Properties properties = new Properties();

        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.host", "mail.gmx.net");
        properties.put("mail.smtp.port", "587");
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.user", sender);
        properties.put("mail.smtp.password", password);
        properties.put("mail.smtp.starttls.enable", "true");

        Session mailSession = Session.getInstance(properties, new Authenticator()
        {
            @Override
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication(properties.getProperty("mail.smtp.user"),
                        properties.getProperty("mail.smtp.password"));
            }
        });

        Message message = new MimeMessage(mailSession);
        InternetAddress addressTo = new InternetAddress(receiver);
        message.setRecipient(Message.RecipientType.TO, addressTo);
        message.setFrom(new InternetAddress(sender));
        message.setSubject("The subject");
        message.setContent("This is the message content", "text/plain");
        Transport.send(message);
    }
}

Sobald ich eine Methode der Klassen im Controller-Konstruktor aufrufen möchte erhalte ich dieses Ergebnis:
[CODE lang="java" title="Fehler"]Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: javax/activation/DataSource
at com.sun.mail.pop3.POP3Folder.createMessage(POP3Folder.java:326)
at com.sun.mail.pop3.POP3Folder.getMessage(POP3Folder.java:307)
at javax.mail.Folder.getMessages(Folder.java:943)
at sample.MailChecker.printAllTextPlainMessages(MailChecker.java:103)
at sample.MailChecker.getAllMails(MailChecker.java:28)
at sample.Controller.<init>(Controller.java:24)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.lang.Class.newInstance(Class.java:584)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
at sample.Main.start(Main.java:15)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 34 more
Exception running application sample.Main
[/CODE]

Das ist jetzt auch der letzte Versuch.
Ich sitze jetzt schon Tage dran und egal was ich mache es ändert sich garnichts.
LG J
 
K

kneitzel

Gast
Also aus Gradle raus zu gehen ist schon schlecht und wie man sieht rennst Du jetzt in irgendwelche Abhängigkeits-Probleme, weil eine Abhängigkeit nicht da ist / eine Klasse nicht gefunden wird.

Was mit direkt beim Bildschirmfoto in #24 auffällt: die fxml datei liegt im src/main/java Ordner und nicht in src/main/resources.
Resourcen gehören in den Resource Ordner.

Das getClassLoader().getResource("../../resources/View.fxml") passt auch nicht!
a) Auf dem Screenshot sehe ich keine View.fxml und
b) Ich sehe auch keine Packages. Daher ist die Frage aus welchen Resource Path du zurück gehen wolltest.... und
c) Beim getResource vom Classloader bist du immer direkt im root. Daher macht ein relativer Pfad, der mit .. startet auch absolut keinen Sinn!
 

Jackcarver12

Mitglied
@kneitzel danke für den Tipp!
Meine Gui startet mittlerweile und es läuft alles.
Ich habe den problematischen Code gefunden...:
[CODE lang="java" title="MailUtil-Klasse"]package sample;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.*;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;

public class MailUtils
{
public MailUtils() {
}

public void getMessages() throws IOException, MessagingException
{
//ObservableList<Mailobject>mails = FXCollections.observableArrayList();
Session session = //zensiert weil letztes mal vergessen pw + user
Folder inbox = MailUtils.openPop3InboxReadOnly( session );
MailUtils.printAllTextPlainMessages( inbox );
MailUtils.closeInbox( inbox );
Message [] allMails = inbox.getMessages();
/*
for(Message m : allMails)
{
Mailobject o = new Mailobject();
o.setDate(m.getSentDate());
o.setSenderA(m.getFrom());
o.setSubject(m.getSubject());
mails.add(o);
}

*/
//return mails;
}
public static Session getGMailSession( String user, String pass ) throws MessagingException, IOException {
final Properties props = new Properties();



// Zum Empfangen
props.setProperty( "mail.pop3.host", "pop.gmail.com" );
props.setProperty( "mail.pop3.user", user );
props.setProperty( "mail.pop3.password", pass );
props.setProperty( "mail.pop3.port", "995" );
props.setProperty( "mail.pop3.auth", "true" );
props.setProperty( "mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory" );

// Zum Senden
props.setProperty( "mail.smtp.host", "smtp.gmail.com" );
props.setProperty( "mail.smtp.auth", "true" );
props.setProperty( "mail.smtp.port", "465" );
props.setProperty( "mail.smtp.socketFactory.port", "465" );
props.setProperty( "mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory" );
props.setProperty( "mail.smtp.socketFactory.fallback", "false" );

return Session.getInstance( props, new javax.mail.Authenticator() {
@Override protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication( props.getProperty( "mail.pop3.user" ),
props.getProperty( "mail.pop3.password" ) );
}
} );
// session.setDebug( true );
}
// ...
public static Folder openPop3InboxReadOnly( Session session )
throws MessagingException
{
Store store = session.getStore( "pop3" );
store.connect();

Folder folder = store.getFolder( "INBOX" );
folder.open( Folder.READ_ONLY );

return folder;
}
public static void closeInbox( Folder folder ) throws MessagingException
{
folder.close( false );
folder.getStore().close();
}
public static void printAllTextPlainMessages( Folder folder )
throws MessagingException, IOException
{
for ( Message m : folder.getMessages() )
{
System.out.println( "\nNachricht:" );
System.out.println( "Von: " + Arrays.toString(m.getFrom()) );
System.out.println( "Betreff: " + m.getSubject() );
System.out.println( "Gesendet am: " + m.getSentDate() );
System.out.println( "Content-Type: " +
new ContentType( m.getContentType() ) );

if ( m.isMimeType( "text/plain" ) )
System.out.println( m.getContent() );
}
}

public static void postMail( Session session, String recipient,
String subject, String message )
throws MessagingException
{
Message msg = new MimeMessage( session );

InternetAddress addressTo = new InternetAddress( recipient );
msg.setRecipient( Message.RecipientType.TO, addressTo );

msg.setSubject( subject );
msg.setContent( message, "text/plain" );
Transport.send( msg );
}

}
[/CODE]

wenn ich die getMessages methode mit der FXanwendung zsm starte.... dann ist die Hölle los.
Ansonsten geht alles einwandfrei
 

Jackcarver12

Mitglied
Ja ... An der Stelle wirds genauso interessant wie vorhin:
[CODE lang="java" title="Ausgabe"]Nachricht:
Von: [Google-Community-Team <googlecommunityteam-noreply@google.com>]
Betreff: Barkeeper, Einrichtung Ihres neuen Google-Kontos beenden
Gesendet am: Thu Jun 10 12:52:03 CEST 2021
Content-Type: multipart/alternative; boundary=00000000000073c2d905c4672eec

Nachricht:
Von: [Google <no-reply@accounts.google.com>]
Betreff: Kritische Sicherheitswarnung
Gesendet am: Thu Jun 10 12:52:26 CEST 2021
Content-Type: multipart/alternative; boundary=000000000000d530c905c4672f4a

Nachricht:
Von: [Google <no-reply@accounts.google.com>]
Betreff: Helfen Sie uns, die Sicherheit Ihres Google-Kontos zu erhöhen
Gesendet am: Sun Jun 20 03:43:20 CEST 2021
Content-Type: multipart/alternative; boundary=00000000000081234305c52fe159

Nachricht:
Von: [Google <no-reply@accounts.google.com>]
Betreff: Sicherheitswarnung
Gesendet am: Mon Jun 21 13:58:15 CEST 2021
Content-Type: multipart/alternative; boundary=00000000000090516805c54563bf
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javafx.fxml.LoadException:
/C:/Users/prakt/IdeaProjects/LastTry/out/production/LastTry/sample/sample.fxml:10

at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
at sample.Main.start(Main.java:18)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
... 1 more
Caused by: java.lang.IllegalStateException: Folder not open
at javax.mail.Folder.getMessages(Folder.java:939)
at sample.MailUtils.getMessages(MailUtils.java:36)
at sample.Controller.<init>(Controller.java:33)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.lang.Class.newInstance(Class.java:584)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 17 more
Exception running application sample.Main
[/CODE]

Wobei ich dachte die InvocationException ist nur eine Strohexception.... an der sollte es also eigl nicht liegen.
Die andere Exceptions sagen mir nur bedingt was.

Aber es bezieht sich scheinbar immer wieder auf den Loader.
Könnte es was damit zu tun haben, dass wir eine Session erzeugen?
Hier nochmal der MailUtil Code der aufgerufen wird

Main:
[CODE lang="java" title="ControllerKonstruktor"] public Controller() throws IOException, MessagingException, InterruptedException {
bestellungenLaden();
MailUtils mu=new MailUtils();
mu.getMessages();



}[/CODE]

[CODE lang="java" title="Klasse zum Maillesen"]package sample;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.*;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;

public class MailUtils
{
public MailUtils() {
}

public void getMessages() throws IOException, MessagingException
{
//ObservableList<Mailobject>mails = FXCollections.observableArrayList();
Session session = //pw und user
Folder inbox = MailUtils.openPop3InboxReadOnly( session );
MailUtils.printAllTextPlainMessages( inbox );
MailUtils.closeInbox( inbox );
Message [] allMails = inbox.getMessages();
/*
for(Message m : allMails)
{
Mailobject o = new Mailobject();
o.setDate(m.getSentDate());
o.setSenderA(m.getFrom());
o.setSubject(m.getSubject());
mails.add(o);
}

*/
//return mails;
}
public static Session getGMailSession( String user, String pass ) throws MessagingException, IOException {
final Properties props = new Properties();



// Zum Empfangen
props.setProperty( "mail.pop3.host", "pop.gmail.com" );
props.setProperty( "mail.pop3.user", user );
props.setProperty( "mail.pop3.password", pass );
props.setProperty( "mail.pop3.port", "995" );
props.setProperty( "mail.pop3.auth", "true" );
props.setProperty( "mail.pop3.socketFactory.class",
"javax.net.ssl.SSLSocketFactory" );

// Zum Senden
props.setProperty( "mail.smtp.host", "smtp.gmail.com" );
props.setProperty( "mail.smtp.auth", "true" );
props.setProperty( "mail.smtp.port", "465" );
props.setProperty( "mail.smtp.socketFactory.port", "465" );
props.setProperty( "mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory" );
props.setProperty( "mail.smtp.socketFactory.fallback", "false" );

return Session.getInstance( props, new javax.mail.Authenticator() {
@Override protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication( props.getProperty( "mail.pop3.user" ),
props.getProperty( "mail.pop3.password" ) );
}
} );
// session.setDebug( true );
}
// ...
public static Folder openPop3InboxReadOnly( Session session )
throws MessagingException
{
Store store = session.getStore( "pop3" );
store.connect();

Folder folder = store.getFolder( "INBOX" );
folder.open( Folder.READ_ONLY );

return folder;
}
public static void closeInbox( Folder folder ) throws MessagingException
{
folder.close( false );
folder.getStore().close();
}
public static void printAllTextPlainMessages( Folder folder )
throws MessagingException, IOException
{
for ( Message m : folder.getMessages() )
{
System.out.println( "\nNachricht:" );
System.out.println( "Von: " + Arrays.toString(m.getFrom()) );
System.out.println( "Betreff: " + m.getSubject() );
System.out.println( "Gesendet am: " + m.getSentDate() );
System.out.println( "Content-Type: " +
new ContentType( m.getContentType() ) );

if ( m.isMimeType( "text/plain" ) )
System.out.println( m.getContent() );
}
}

public static void postMail( Session session, String recipient,
String subject, String message )
throws MessagingException
{
Message msg = new MimeMessage( session );

InternetAddress addressTo = new InternetAddress( recipient );
msg.setRecipient( Message.RecipientType.TO, addressTo );

msg.setSubject( subject );
msg.setContent( message, "text/plain" );
Transport.send( msg );
}

}
[/CODE]
vielleicht weil dort static Methoden aufgerufen werden?

LG J
 

mrBrown

Super-Moderator
Mitarbeiter
Der Grund steht in der Fehlermeldung:
Code:
Caused by: java.lang.IllegalStateException: Folder not open

Versuch es doch erstmal ohne das ganze drum herum zum Laufen zu bringen, aktuell hast du zig Fehlerquellen drin, die sich zT gegenseitig verdecken. Nimm einfach erstmal statischen Daten, anstatt echter Mails.
 

Jackcarver12

Mitglied
Den Ansatz habe ich bereits umgesetzt!
Ohne die FX-Anwendung funktioniert alles einwandfrei!
Selber code, selber Aufruf in der "ausführenden Klasse".
Es ist tatsächlich identisch!
Aber zusammen funktionieren die Funktionen nicht.
Und an der Stelle ergibt sich für mich einfach ein Verständnisproblem.

Was in einem Projekt ohne FX einwandfrei läuft, macht in einer FX-Anwendung mit identischen Imports Probleme...
[CODE lang="java" title="Main-Klasse"]import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.swing.*;
import java.io.IOException;

public class Main {

public static void main(String[]args) throws IOException, MessagingException, InterruptedException {

MailUtils mu = new MailUtils();
}
}
[/CODE]

Java:
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.*;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;

public class MailUtils
{
    public  MailUtils() throws MessagingException, IOException {
        Session session = //zensiert pw+user
        Folder inbox = MailUtils.openPop3InboxReadOnly( session );
        MailUtils.printAllTextPlainMessages( inbox );
        MailUtils.closeInbox( inbox );
    }

    public static Session getGMailSession( String user, String pass )
    {
        final Properties props = new Properties();

        // Zum Empfangen
        props.setProperty( "mail.pop3.host", "pop.gmail.com" );
        props.setProperty( "mail.pop3.user", user );
        props.setProperty( "mail.pop3.password", pass );
        props.setProperty( "mail.pop3.port", "995" );
        props.setProperty( "mail.pop3.auth", "true" );
        props.setProperty( "mail.pop3.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory" );

        // Zum Senden
        props.setProperty( "mail.smtp.host", "smtp.gmail.com" );
        props.setProperty( "mail.smtp.auth", "true" );
        props.setProperty( "mail.smtp.port", "465" );
        props.setProperty( "mail.smtp.socketFactory.port", "465" );
        props.setProperty( "mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory" );
        props.setProperty( "mail.smtp.socketFactory.fallback", "false" );

        return Session.getInstance( props, new javax.mail.Authenticator() {
            @Override protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication( props.getProperty( "mail.pop3.user" ),
                        props.getProperty( "mail.pop3.password" ) );
            }
        } );
//    session.setDebug( true );
    }
    // ...
    public static Folder openPop3InboxReadOnly( Session session )
            throws MessagingException
    {
        Store store = session.getStore( "pop3" );
        store.connect();

        Folder folder = store.getFolder( "INBOX" );
        folder.open( Folder.READ_ONLY );

        return folder;
    }
    public static void closeInbox( Folder folder ) throws MessagingException
    {
        folder.close( false );
        folder.getStore().close();
    }
    public static void printAllTextPlainMessages( Folder folder )
            throws MessagingException, IOException
    {
        for ( Message m : folder.getMessages() )
        {
            System.out.println( "\nNachricht:" );
            System.out.println( "Von: " + Arrays.toString(m.getFrom()) );
            System.out.println( "Betreff: " + m.getSubject() );
            System.out.println( "Gesendet am: " + m.getSentDate() );
            System.out.println( "Content-Type: " +
                    new ContentType( m.getContentType() ) );

            if ( m.isMimeType( "text/plain" ) )
                System.out.println( m.getContent() );
        }
    }

    public static void postMail( Session session, String recipient,
                                 String subject, String message )
            throws MessagingException
    {
        Message msg = new MimeMessage( session );

        InternetAddress addressTo = new InternetAddress( recipient );
        msg.setRecipient( Message.RecipientType.TO, addressTo );

        msg.setSubject( subject );
        msg.setContent( message, "text/plain" );
        Transport.send( msg );
    }

}
/*
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import javax.mail.*;
import javax.mail.internet.ContentType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;


public class MailChecker {
    private Properties props;
    private MailChecker MailUtils;

    public ObservableList<Mailobject> getAllMails() throws IOException, MessagingException, MessagingException {

        Session session = MailUtils.getGMailSession(
                JOptionPane.showInputDialog( "user" ),
                JOptionPane.showInputDialog( "pass" ) );


        ObservableList<Mailobject> dlmMails= FXCollections.observableArrayList();
        Session session = getGMailSession("testbarkeeper@gmail.com","Jackcarver12");
        Folder inbox = openPop3InboxReadOnly( session );
        printAllTextPlainMessages( inbox );

        if(inbox.getMessages()!=null)
        {
            for (Message m : inbox.getMessages())
            {
                Mailobject mo = new Mailobject();
                mo.setSubject(m.getSubject());
                mo.setDate(m.getSentDate());
                mo.setSender(Arrays.toString(m.getFrom()));
                dlmMails.add(mo);
            }
        }
        else
        {
            System.out.println("Sie haben keine Mails");
        }
        printAllTextPlainMessages(inbox);
        closeInbox( inbox );
        return dlmMails;
    }

    public static Session getGMailSession(String user, String pass )
    {
        final Properties props = new Properties();

        // Zum Empfangen
        props.setProperty( "mail.pop3.host", "pop.gmail.com" );
        props.setProperty( "mail.pop3.user", user );
        props.setProperty( "mail.pop3.password", pass );
        props.setProperty( "mail.pop3.port", "995" );
        props.setProperty( "mail.pop3.auth", "true" );
        props.setProperty( "mail.pop3.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory" );

        // Zum Senden
        props.setProperty( "mail.smtp.host", "smtp.gmail.com" );
        props.setProperty( "mail.smtp.auth", "true" );
        props.setProperty( "mail.smtp.port", "465" );
        props.setProperty( "mail.smtp.socketFactory.port", "465" );
        props.setProperty( "mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory" );
        props.setProperty( "mail.smtp.socketFactory.fallback", "false" );

        return Session.getInstance( props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication( props.getProperty( "mail.pop3.user" ),
                        props.getProperty( "mail.pop3.password" ) );
            }
        } );
//    session.setDebug( true );
    }
    // ...


    public static Folder openPop3InboxReadOnly( Session session )
            throws MessagingException
    {
        Store store = session.getStore( "pop3" );
        store.connect();

        Folder folder = store.getFolder( "INBOX" );
        folder.open( Folder.READ_ONLY );

        return folder;
    }
    public static void closeInbox( Folder folder ) throws MessagingException
    {
        folder.close( false );
        folder.getStore().close();
    }
    public static   void printAllTextPlainMessages( Folder folder )
            throws MessagingException, IOException
    {
        for ( Message m : folder.getMessages() )
        {
            System.out.println( "\nNachricht:" );
            System.out.println( "Von: " + Arrays.toString(m.getFrom()) );
            System.out.println( "Betreff: " + m.getSubject() );
            System.out.println( "Gesendet am: " + m.getSentDate() );
            System.out.println( "Content-Type: " +
                    new ContentType( m.getContentType() ) );

            if ( m.isMimeType( "text/plain" ) )
                System.out.println( m.getContent() );
        }
    }


    public static void sendGMX() throws MessagingException
    {
        String sender = "bkpr@gmx.de";
        String password = "my.password";
        String receiver = "my-receiver@gmail.com";

        Properties properties = new Properties();

        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.host", "mail.gmx.net");
        properties.put("mail.smtp.port", "587");
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.user", sender);
        properties.put("mail.smtp.password", password);
        properties.put("mail.smtp.starttls.enable", "true");

        Session mailSession = Session.getInstance(properties, new Authenticator()
        {
            @Override
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication(properties.getProperty("mail.smtp.user"),
                        properties.getProperty("mail.smtp.password"));
            }
        });

        Message message = new MimeMessage(mailSession);
        InternetAddress addressTo = new InternetAddress(receiver);
        message.setRecipient(Message.RecipientType.TO, addressTo);
        message.setFrom(new InternetAddress(sender));
        message.setSubject("The subject");
        message.setContent("This is the message content", "text/plain");
        Transport.send(message);
    }
}
*/
 

Jackcarver12

Mitglied
ok Leute!
Vielen Dank für die Geduld, die Hilfe und eure Zeit!
Ich habs jetzt endlich auf die Reihe bekommen.
Nachdem ich mir den Fehler jetzt mal wirklich Zeile für Zeile durchgelesen habe, ist mir aufgefallen, dass es an einer Stelle um einen Folder geht.
So einen spreche ich in der MailUtils Klasse an.
Wie sich herausgestellt hat, habe ich auf einen Folder zugegriffen, obwohl dieser bereits wieder geschlossen war.
Mir ist grad zwar ne kleine Ader geplatzt, aber für euch tuts mir natürlich auch Leid, eben weil es so ein simpler Leichtsinnsfehler war. Sowas sollte man schon ausschließen bevor man irgendwo nachfragt!
Tut mir außerordentlich Leid!
LG J
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
L java.lang.NullPointerException - Fehlermeldung AWT, Swing, JavaFX & SWT 2
L exception in thread awt-eventqueue-0 java.lang.nullpointerexception AWT, Swing, JavaFX & SWT 2
M Exception in thread "Thread-3" java.lang.NullPointerException AWT, Swing, JavaFX & SWT 18
1 JComponent -> java.lang.NullPointerException AWT, Swing, JavaFX & SWT 13
E java.lang.NullPointerException AWT, Swing, JavaFX & SWT 14
A AWT Methodenaufruf "AWT-EventQueue-0" java.lang.NullPointerException AWT, Swing, JavaFX & SWT 4
S Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException AWT, Swing, JavaFX & SWT 7
loadbrain JTextFields & java.lang.NullPointerException AWT, Swing, JavaFX & SWT 2
F Fehler: java.lang.NullPointerException AWT, Swing, JavaFX & SWT 2
Juelin Für Java-Spezialisten AWT, Swing, JavaFX & SWT 4
Juelin Java <-> Delphi AWT, Swing, JavaFX & SWT 3
H Exceptions seit java: 1.6.0_65 Umstellung AWT, Swing, JavaFX & SWT 3
H Exception: java.lang.ClassCastException AWT, Swing, JavaFX & SWT 2
M JavaFX java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found AWT, Swing, JavaFX & SWT 5
J Java GUI Dropdown-Menü anzeigen AWT, Swing, JavaFX & SWT 5
M Eigene Java Klasse für allgemeine Grafikelemente AWT, Swing, JavaFX & SWT 8
thor_norsk Java - Allgemeine - Frage AWT, Swing, JavaFX & SWT 14
W Kennt jemand Dear ImGui (und den Java-Wrapper dazu)? AWT, Swing, JavaFX & SWT 0
B Java Projekt mit JavaFX und jfoenix ausführbar machen AWT, Swing, JavaFX & SWT 46
D JAVA Schieberegler AWT, Swing, JavaFX & SWT 6
N JavaFX Einfacher Taschenrechner mit Scene Builder und Java FX AWT, Swing, JavaFX & SWT 0
Jose05 Aus einer normalen Java Klasse eine FXML-Klasse laden AWT, Swing, JavaFX & SWT 12
S Welches Java Layout sollte ich verwenden? AWT, Swing, JavaFX & SWT 3
B Actionlistener mit Java Swing AWT, Swing, JavaFX & SWT 2
P Fehlermeldung: Error: Could not find or load main class set Caused by: java.lang.ClassNotFoundException: set AWT, Swing, JavaFX & SWT 5
Encera Java FX im Eclipse-Marketplace nichtmehr auffindbar AWT, Swing, JavaFX & SWT 6
_user_q Versionscode aus build.gradle in Java-Klasse ausgeben lassen AWT, Swing, JavaFX & SWT 14
M Java Dateien kopieren mit Fortschrittsbalken AWT, Swing, JavaFX & SWT 13
M Frage zu Java Bundesligaverwaltung AWT, Swing, JavaFX & SWT 7
_user_q Gibt es eine Möglichkeit, in Java alle möglichen Zeichen automatisch tippen zu lassen? AWT, Swing, JavaFX & SWT 13
E 3D-Grafik Java Fatal error bei LWJGL AWT, Swing, JavaFX & SWT 2
Heldderschatten Java Events und Interfaces AWT, Swing, JavaFX & SWT 18
volcanos Scrollen: JScrollPane mit Graphics g und Java-Fonts extends Frame ? AWT, Swing, JavaFX & SWT 5
sserio Java Fx - Problem AWT, Swing, JavaFX & SWT 3
U Warum wird zweimal die Affinetransformation estellt (2Dgraphics, Java)? AWT, Swing, JavaFX & SWT 31
U was bewirkt die methode fill und unterschied zu anderen fill Methoden in 2dgraphics? (Java)? AWT, Swing, JavaFX & SWT 6
DonBronson Java Graphics bewegbar machen (Drag&Drop) AWT, Swing, JavaFX & SWT 3
Yonnig Lokale HTML-Datei in Java GUI rendern AWT, Swing, JavaFX & SWT 4
E Java-TexturePaint sehr langsam AWT, Swing, JavaFX & SWT 9
N Java MySQL Datenbank durchsuchen? AWT, Swing, JavaFX & SWT 7
maximstein JavaFX WebView - java.lang.NoSuchMethodError: 'boolean com.sun.prism.ResourceFactory.isDisposed()' AWT, Swing, JavaFX & SWT 4
Splayfer Custom Font in AttributedString Java AWT, Swing, JavaFX & SWT 4
imawake Java Paket-Tracking Programm 📦 AWT, Swing, JavaFX & SWT 7
izoards *.doc Seitenränder per Java setzen... AWT, Swing, JavaFX & SWT 14
T FXML Datei in Java Code einbinden: javafx.fxml.LoadException AWT, Swing, JavaFX & SWT 2
J Key-Listener in Java AWT, Swing, JavaFX & SWT 37
J Java Datei durch CMD mit Parameter ausführen AWT, Swing, JavaFX & SWT 1
N Java Mouse Listiner macht alles zusammen AWT, Swing, JavaFX & SWT 4
T Exception in thread "main" java.lang.NoClassDefFoundError AWT, Swing, JavaFX & SWT 4
M Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found AWT, Swing, JavaFX & SWT 14
AmsananKING Java Menü-Problem AWT, Swing, JavaFX & SWT 1
T Swing DPI-Skalierung und Java 2D unter Java 11 (und Windows 10) AWT, Swing, JavaFX & SWT 2
J Spiel mit Java AWT, Swing, JavaFX & SWT 9
I AWT java.awt.FileDialog - "coffee cup"-Icon lässt sich nicht ersetzen AWT, Swing, JavaFX & SWT 14
O Ein Java-Programm mit Swing steuern AWT, Swing, JavaFX & SWT 1
izoards Java FX Window Event SHOWING AWT, Swing, JavaFX & SWT 17
N FXMLLoader.load java.lang.RuntimeException: Gradle AWT, Swing, JavaFX & SWT 2
T Java GUI - Würfel Programm AWT, Swing, JavaFX & SWT 6
JojoSand Java Programm wird nicht gestartet - keinen Fehlerhinweis AWT, Swing, JavaFX & SWT 9
dtr84 JavaFX/OpenJFX mittels Apache Ivy einbinden (Java 11) AWT, Swing, JavaFX & SWT 18
M Jogl und Java 3d AWT, Swing, JavaFX & SWT 0
S0PEX JavaFX Java 8 auf 15 migrieren OpenJFX mit Gradle eingebunden, jedoch nicht gefunden !? AWT, Swing, JavaFX & SWT 4
I Gui in bestehendes Java-Programm AWT, Swing, JavaFX & SWT 11
V Java-Zeichenfeld mit AWT AWT, Swing, JavaFX & SWT 3
N java Gui friert scheinbar zufällig ein AWT, Swing, JavaFX & SWT 5
T Anderen Java Code durch Code kompilieren und Fehler in Label ausgeben AWT, Swing, JavaFX & SWT 5
P Java Fx einrichten AWT, Swing, JavaFX & SWT 2
pkm Frage wegen java.lang.IllegalStateException bei DocumentListener AWT, Swing, JavaFX & SWT 4
S JavaFX Java Custom Node Grafik zurückgeben AWT, Swing, JavaFX & SWT 2
MiMa Java und JavaFX 13 läuft endlich AWT, Swing, JavaFX & SWT 4
N eclipse Java, bilder benutzten Funktioniert nicht AWT, Swing, JavaFX & SWT 6
Trèfle Ausklappbare Diagramme in Java AWT, Swing, JavaFX & SWT 1
R Java, GUI, Hintergrundbild, Image, AWT, Swing, JavaFX & SWT 4
K JAVA FX Constraints AWT, Swing, JavaFX & SWT 2
F Java FX und webcam AWT, Swing, JavaFX & SWT 1
T Wie kann man in java aufwendige grafiken programmieren AWT, Swing, JavaFX & SWT 1
M Swing Java Swing/AWT Combobox Bug AWT, Swing, JavaFX & SWT 3
S Java GUI durch variable Größe einer Map anpassen AWT, Swing, JavaFX & SWT 3
J Java SWT Tabelleninhalt formattieren AWT, Swing, JavaFX & SWT 10
Blender3D Falsche Werte mit Java Toolkit Screensize AWT, Swing, JavaFX & SWT 4
K Swing AWT-EventQueue-1 java.lang.NoClassDefFoundError bei setVisible(true) AWT, Swing, JavaFX & SWT 3
A Java Programm gestalten AWT, Swing, JavaFX & SWT 4
B [Problem] Java öffnet Word-Datein nicht AWT, Swing, JavaFX & SWT 14
S Swing Java Swing AWT, Swing, JavaFX & SWT 6
I Java Bildfarbe ändern wie bei Photoshop AWT, Swing, JavaFX & SWT 9
R JavaFX Java FXML Vererbung in Klassen AWT, Swing, JavaFX & SWT 9
T Java: Zwei abhängige JSlider machen nicht das, was sie sollen AWT, Swing, JavaFX & SWT 4
J Parallele Aktionen in Java FX richtig durchführen. AWT, Swing, JavaFX & SWT 5
Neumi5694 java.awt.Window nach javafx.stage.Window AWT, Swing, JavaFX & SWT 1
M JavaFX java.lang.IllegalStateException: Location is not set. AWT, Swing, JavaFX & SWT 9
L Java- CardLayout AWT, Swing, JavaFX & SWT 10
M Java zeichnet nicht pixelgenau AWT, Swing, JavaFX & SWT 40
B Swing Eclipse is running under 0, but this Java project has a 1.6 Java compliance level, so WindowBuilder AWT, Swing, JavaFX & SWT 2
L Java- UI zweites Fenster aus einer anderen Klasse öffnen durch ButtonClick AWT, Swing, JavaFX & SWT 4
S Java Gui AWT, Swing, JavaFX & SWT 5
R Sierpinski Dreieck mit Java FX AWT, Swing, JavaFX & SWT 4
Flynn java.lang.UnsupportedOperationException: Not supported yet AWT, Swing, JavaFX & SWT 7
D Zwei getrennte Java Klassen verbinden. Wie ? AWT, Swing, JavaFX & SWT 2
D SQL Statements mit Java Swing benutzen AWT, Swing, JavaFX & SWT 4
D DatePicker für Java Swing AWT, Swing, JavaFX & SWT 2

Ähnliche Java Themen

Neue Themen


Oben