Arrays einspeichern geht nicht

MrTroble

Bekanntes Mitglied
Hallo erst mal
vielleicht kann mir jemand helfen
ich will n P(p)aar sachen in arrays rein quetschen (unbestimmte anzahl)
Java:
static int auf = 0;
			
	static void add(Node n){
		int sz;
		if(auf == 0){
		sz = 0;
		auf++;
		}else{
		sz = x.length;
		}
		Logger.Debug("Size " + sz, false);
		x[sz] = n.getTranslateX();
		z[sz] = n.getTranslateZ();
		y[sz] = n.getTranslateY();
		hy[sz] = n.getScaleY();
		lz[sz] = n.getScaleZ();
		bx[sz] = n.getScaleX();
		rot[sz] = n.getRotate();
		ax[sz] = n.getRotationAxis();
	}
ich bekomme diesen Error

[16:00:10 05/21/15]-[Client/Debug]:Size 0
[16:00:10 05/21/15]-[Client/Debug]:In Thread 14 JavaFX Application Thread
[16:00:10 05/21/15]-[Client/Debug]:Exepted by sun.misc.Launcher$AppClassLoader@73d16e93
Exception in Application start method
Exception in thread "Thread-223" java.lang.NullPointerException
at com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer.playerGetPresentationTime(Unknown Source)
at com.sun.media.jfxmediaimpl.NativeMediaPlayer.getPresentationTime(Unknown Source)
at javafx.scene.media.MediaPlayer.getCurrentTime(Unknown Source)
at com.weebly.Blackoutupdate.Blackout.INGAME$5.run(INGAME.java:639)
at java.lang.Thread.run(Unknown Source)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$57/1463801669.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.weebly.Blackoutupdate.Blackout.Berechnung.add(Berechnung.java:18)
at com.weebly.Blackoutupdate.Blackout.Game.register(Game.java:41)
at com.weebly.Blackoutupdate.Blackout.INGAME.newWorld(INGAME.java:695)
at com.weebly.Blackoutupdate.Blackout.INGAME.map(INGAME.java:599)
at com.weebly.Blackoutupdate.Blackout.INGAME.start(INGAME.java:689)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$60/575176754.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/237061348.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/494259528.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1030870354.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1232367853.run(Unknown Source)
... 1 more
 
Steht doch alles da! Irgendwas in deinem Code an diesen Zeilennummer ist null!
Code:
Caused by: java.lang.NullPointerException
at com.weebly.Blackoutupdate.Blackout.Berechnung.add(Berechnung.java:18)
at com.weebly.Blackoutupdate.Blackout.Game.register(Game.java:41)
at com.weebly.Blackoutupdate.Blackout.INGAME.newWorld(INGAME.java:695)
at com.weebly.Blackoutupdate.Blackout.INGAME.map(INGAME.java:599)
at com.weebly.Blackoutupdate.Blackout.INGAME.start(INGAME.java:689)
 
halt das kann nicht sein ein double ist niemahls null

Stimmt, aber es geht hier auch nicht um ein "double" sondern etwas anderes!
Leider weiß ich nicht welche Zeile Code der genannten in der Exception enstpricht sonst könnte ich mehr dazu sagen.
Aber ich nehme an entweder ist "Node n" null oder das Array in welches du die Daten speichern willst.
 
das Node ist nicht null weil da ja was übergeben wird also warum ist das array null bitte schön ,was kann ich dagegen tun

NACHTRAG : Es entspricht Zeile 13 in dem Code
 
Zuletzt bearbeitet:
wenn du eine unbestimmte anzahl an paarwerten hast kannst du das nicht so lösen
ArrayList<double[]> paare =new ArrayList<>();
for /while( ...){
double[] paar =new double[ 2];
paar[ 0] = irgendwas;
paar[ 1] = irgendwasAnderes;
paare.add( paar);
}
 
das war nicht gemeint aber danke für den vorschlag gemeint war wie oft die methode ausgefürt wird
 
Zuletzt bearbeitet:
In Zeile 13 steht: x[sz] = n.getTranslateX();
Hier dürfen x und n nicht null sein. auf ist 0, weshalb n nicht null sein kann (sonst hätte es schon in zeile 10 (bzw. 14 bei dir) geknallt. Also ist x null. Warum das so ist musst du selber rausfinden.
 
kann mir einer sagen warum x null ist
Java:
static double[] h = {};
 static double[] w = {};
 static double[] d = {};
 static double[] x = {};
 static double[] y = {};
 static double[] z = {};
 static double[] rot = {};
 static Point3D[] ax = {};
static ArrayList<double[]> reg = new ArrayList<double[]>();
 
Dein x ist nicht null. Folgender Sechszeiler produziert die erwartete Ausgabe, nämlich 0.
Java:
public class Test{
    static double[] x = {};
    public static void main(String[] args){
        System.out.println(x.length);
    }
}
 
ja aber warum war das null egal ich hab ne lösung
Java:
	static ArrayList<Point3D[]> regP= new ArrayList<Point3D[]>();
	static ArrayList<double[]> reg = new ArrayList<double[]>();
			
	static void add(Node n){
		double[] x = {n.getTranslateX()};
		reg.add(x);
		double[] y = {n.getTranslateY()};
	    reg.add(y);
	    double[] z = {n.getTranslateZ()};
	    reg.add(z);
	    double[] h = {n.layoutBoundsProperty().get().getHeight()};
	    reg.add(h);
	    double[] w = {n.layoutBoundsProperty().get().getWidth()};
	    reg.add(w);
	    double[] d = {n.layoutBoundsProperty().get().getDepth()};
	    reg.add(d);
	    Point3D[] poi = {n.getRotationAxis()};
	    regP.add(poi);
		
	    Logger.Debug("Info " + n.layoutBoundsProperty().getValue(), false);
	    Logger.Debug("Register SIZE " + reg.size(), false);
	  	}
 
Warum erstellst du für die ganzen Werte eigene Arrays? Ich würde einfach eine Array-List mit Nodes machen oder falls da zu viel Info drin steckt ein kleines "Sub-Nodes"-Objekt, das die entsprechenden Werte beinhaltet.
 
@Tom299 hab ich auch dann gemacht

Java:
static ArrayList<Point3D[]> regP= new ArrayList<Point3D[]>();
    static ArrayList<double[]> reg = new ArrayList<double[]>();
    static ArrayList<Node[]> regN = new ArrayList<Node[]>();
    static ArrayList<boolean[]> isSupported = new ArrayList<boolean[]>();
            
    static void add(Node n){
        double[] ifo = {n.getTranslateX(),n.getTranslateY(),n.getTranslateZ(),
                              n.layoutBoundsProperty().get().getHeight(),
                                n.layoutBoundsProperty().get().getWidth(),
                              n.layoutBoundsProperty().get().getDepth()};
        reg.add(ifo);
        Point3D[] poi = {n.getRotationAxis()};
        regP.add(poi);
        Node[] node = {n};
        regN.add(node);
        boolean[] isSu = {true};
        isSupported.add(isSu);
        
        Logger.Debug("Register SIZE " + reg.size(), false);
          }
 
Zuletzt bearbeitet:
das Node ist nicht null weil da ja was übergeben wird

Warum bist du dir sicher das der Node "n" nicht null ist?
"n" wird vor Zeile 13 (im Code des Anfangspost) nicht verwendet. Daher könnte es schon sein das "n" null ist.


In Zeile 13 steht: x[sz] = n.getTranslateX();
Hier dürfen x und n nicht null sein.

Korrekt, dass sind die beiden möglichen Fehlerquellen.

auf ist 0, weshalb n nicht null sein kann

Sehe ich einen anderen Code als du? Nur weil "auf=0" heißt das ja nicht das "n" nicht null sein kann oder?

@Tom299 hab ich auch dann gemacht

Java:
    static ArrayList<Node[]> regN = new ArrayList<Node[]>();
    static ArrayList<boolean[]> isSupported = new ArrayList<boolean[]>();
            
    static void add(Node n){
        Node[] node = {n};
        regN.add(node);
        boolean[] isSu = {true};
        isSupported.add(isSu);

Nein hast du nicht!
Beispiel: Deine ArrayList "isSupported" ist für "boolean[]" geeignet. In der Methode "add" fügst du immer nur ein Array mit 1 Wert hinzu. Warum verwendest du nicht einfach "ArrayList<Boolean>" und fügst einen einfachen Wert hinzu?
Ähnlich bei "regN" und den "Node[]".

So wird das Prorgamm unnötig kompliziert.
 
Zuletzt bearbeitet:
Joose hat gesagt.:
Sehe ich einen anderen Code als du? Nur weil "auf=0" heißt das ja nicht das "n" nicht null sein kann oder?
Nein, du siehst keinen anderen Code als ich 😀 Meine Aussage zu n war Bockmist (habe x und n verwechselt); entschuldigt bitte @all.

Daher korrigiere ich mich:
In Zeile 10 wird x.length benutzt, wenn auf 0 ist. auf ist 0, deshalb kann x nicht null sein; ergo ist n null.
 

Zurück
Oben