Error saving image in an ImageView object with JavaFX and sceneBuilder [duplicate]
This question already has an answer here:
What is a NullPointerException, and how do I fix it?
12 answers
I'm making a simple graphical desktop application for image management and, I'm using JavaFX, in addition to its sceneBuilder. The idea is, at pushing a button a FileChooser appears, to choose the image and to show a new window with all the background image on it. The problem is that in doing it. I get an error that I can not identify.
Edit: I discovered that if I open the image in the same window there is no error.
My code:
public void OpenWindow(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Window2.fxml"));
Scene secondScene = new Scene(root,800,800);
Stage newWindow = new Stage();
newWindow.setTitle("Imagen");
newWindow.setScene(secondScene);
newWindow.setX(100);
newWindow.setY(100);
newWindow.show();
/////// Open Window //////
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter(" JPG", "*.JPG");
fileChooser.getExtensionFilters().addAll(extFilterJPG);
File file = fileChooser.showOpenDialog(null);
try {
BufferedImage bufferedImage = ImageIO.read(file);
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
myImageView.setImage(image);
}catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
Edit: (SOLUTION WAS CREATE A NEW FMXL LOADER)
`
FXMLLoader loader = new FXMLLoader(getClass().getResource("SecondController.fxml"));
Parent root = (Parent) loader.load();
SecondController secController = loader.getController();
secController.nuevaImagen(imagen);
secController.mostrarInfo(imagen); // Hacer que el controlador de la imagen muestre la info
secController.addMainController(this);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.setTitle(datosImagenActiva.titulo);
stage.show();`
java eclipse image javafx imageview
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 23:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 6 more comments
This question already has an answer here:
What is a NullPointerException, and how do I fix it?
12 answers
I'm making a simple graphical desktop application for image management and, I'm using JavaFX, in addition to its sceneBuilder. The idea is, at pushing a button a FileChooser appears, to choose the image and to show a new window with all the background image on it. The problem is that in doing it. I get an error that I can not identify.
Edit: I discovered that if I open the image in the same window there is no error.
My code:
public void OpenWindow(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Window2.fxml"));
Scene secondScene = new Scene(root,800,800);
Stage newWindow = new Stage();
newWindow.setTitle("Imagen");
newWindow.setScene(secondScene);
newWindow.setX(100);
newWindow.setY(100);
newWindow.show();
/////// Open Window //////
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter(" JPG", "*.JPG");
fileChooser.getExtensionFilters().addAll(extFilterJPG);
File file = fileChooser.showOpenDialog(null);
try {
BufferedImage bufferedImage = ImageIO.read(file);
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
myImageView.setImage(image);
}catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
Edit: (SOLUTION WAS CREATE A NEW FMXL LOADER)
`
FXMLLoader loader = new FXMLLoader(getClass().getResource("SecondController.fxml"));
Parent root = (Parent) loader.load();
SecondController secController = loader.getController();
secController.nuevaImagen(imagen);
secController.mostrarInfo(imagen); // Hacer que el controlador de la imagen muestre la info
secController.addMainController(this);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.setTitle(datosImagenActiva.titulo);
stage.show();`
java eclipse image javafx imageview
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 23:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Is that the full stack trace? Are there anyCaused by:s you left out?
– Slaw
Nov 17 '18 at 18:44
Yes, there are 2:Caused by: java.lang.reflect.InvocationTargetException&Caused by: java.lang.NullPointerException
– Danielmagox
Nov 17 '18 at 18:45
That means the fundamental cause is aNullPointerException. Read What is a stack trace, and how can I use it to debug my application errors? and What is a NullPointerException, and how do I fix it?, then go to where the stack trace is telling you the error is so you can see the problem.
– Slaw
Nov 17 '18 at 19:01
I guess it'smyImageView. OP might have forgotten to putfx:idin the FMXL
– Gnas
Nov 17 '18 at 19:04
Nope it is too.
– Danielmagox
Nov 17 '18 at 19:12
|
show 6 more comments
This question already has an answer here:
What is a NullPointerException, and how do I fix it?
12 answers
I'm making a simple graphical desktop application for image management and, I'm using JavaFX, in addition to its sceneBuilder. The idea is, at pushing a button a FileChooser appears, to choose the image and to show a new window with all the background image on it. The problem is that in doing it. I get an error that I can not identify.
Edit: I discovered that if I open the image in the same window there is no error.
My code:
public void OpenWindow(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Window2.fxml"));
Scene secondScene = new Scene(root,800,800);
Stage newWindow = new Stage();
newWindow.setTitle("Imagen");
newWindow.setScene(secondScene);
newWindow.setX(100);
newWindow.setY(100);
newWindow.show();
/////// Open Window //////
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter(" JPG", "*.JPG");
fileChooser.getExtensionFilters().addAll(extFilterJPG);
File file = fileChooser.showOpenDialog(null);
try {
BufferedImage bufferedImage = ImageIO.read(file);
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
myImageView.setImage(image);
}catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
Edit: (SOLUTION WAS CREATE A NEW FMXL LOADER)
`
FXMLLoader loader = new FXMLLoader(getClass().getResource("SecondController.fxml"));
Parent root = (Parent) loader.load();
SecondController secController = loader.getController();
secController.nuevaImagen(imagen);
secController.mostrarInfo(imagen); // Hacer que el controlador de la imagen muestre la info
secController.addMainController(this);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.setTitle(datosImagenActiva.titulo);
stage.show();`
java eclipse image javafx imageview
This question already has an answer here:
What is a NullPointerException, and how do I fix it?
12 answers
I'm making a simple graphical desktop application for image management and, I'm using JavaFX, in addition to its sceneBuilder. The idea is, at pushing a button a FileChooser appears, to choose the image and to show a new window with all the background image on it. The problem is that in doing it. I get an error that I can not identify.
Edit: I discovered that if I open the image in the same window there is no error.
My code:
public void OpenWindow(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Window2.fxml"));
Scene secondScene = new Scene(root,800,800);
Stage newWindow = new Stage();
newWindow.setTitle("Imagen");
newWindow.setScene(secondScene);
newWindow.setX(100);
newWindow.setY(100);
newWindow.show();
/////// Open Window //////
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter(" JPG", "*.JPG");
fileChooser.getExtensionFilters().addAll(extFilterJPG);
File file = fileChooser.showOpenDialog(null);
try {
BufferedImage bufferedImage = ImageIO.read(file);
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
myImageView.setImage(image);
}catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
Edit: (SOLUTION WAS CREATE A NEW FMXL LOADER)
`
FXMLLoader loader = new FXMLLoader(getClass().getResource("SecondController.fxml"));
Parent root = (Parent) loader.load();
SecondController secController = loader.getController();
secController.nuevaImagen(imagen);
secController.mostrarInfo(imagen); // Hacer que el controlador de la imagen muestre la info
secController.addMainController(this);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.setTitle(datosImagenActiva.titulo);
stage.show();`
This question already has an answer here:
What is a NullPointerException, and how do I fix it?
12 answers
java eclipse image javafx imageview
java eclipse image javafx imageview
edited Dec 20 '18 at 22:03
Danielmagox
asked Nov 17 '18 at 18:39
DanielmagoxDanielmagox
184
184
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 23:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by fabian
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 17 '18 at 23:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Is that the full stack trace? Are there anyCaused by:s you left out?
– Slaw
Nov 17 '18 at 18:44
Yes, there are 2:Caused by: java.lang.reflect.InvocationTargetException&Caused by: java.lang.NullPointerException
– Danielmagox
Nov 17 '18 at 18:45
That means the fundamental cause is aNullPointerException. Read What is a stack trace, and how can I use it to debug my application errors? and What is a NullPointerException, and how do I fix it?, then go to where the stack trace is telling you the error is so you can see the problem.
– Slaw
Nov 17 '18 at 19:01
I guess it'smyImageView. OP might have forgotten to putfx:idin the FMXL
– Gnas
Nov 17 '18 at 19:04
Nope it is too.
– Danielmagox
Nov 17 '18 at 19:12
|
show 6 more comments
Is that the full stack trace? Are there anyCaused by:s you left out?
– Slaw
Nov 17 '18 at 18:44
Yes, there are 2:Caused by: java.lang.reflect.InvocationTargetException&Caused by: java.lang.NullPointerException
– Danielmagox
Nov 17 '18 at 18:45
That means the fundamental cause is aNullPointerException. Read What is a stack trace, and how can I use it to debug my application errors? and What is a NullPointerException, and how do I fix it?, then go to where the stack trace is telling you the error is so you can see the problem.
– Slaw
Nov 17 '18 at 19:01
I guess it'smyImageView. OP might have forgotten to putfx:idin the FMXL
– Gnas
Nov 17 '18 at 19:04
Nope it is too.
– Danielmagox
Nov 17 '18 at 19:12
Is that the full stack trace? Are there any
Caused by:s you left out?– Slaw
Nov 17 '18 at 18:44
Is that the full stack trace? Are there any
Caused by:s you left out?– Slaw
Nov 17 '18 at 18:44
Yes, there are 2:
Caused by: java.lang.reflect.InvocationTargetException & Caused by: java.lang.NullPointerException– Danielmagox
Nov 17 '18 at 18:45
Yes, there are 2:
Caused by: java.lang.reflect.InvocationTargetException & Caused by: java.lang.NullPointerException– Danielmagox
Nov 17 '18 at 18:45
That means the fundamental cause is a
NullPointerException. Read What is a stack trace, and how can I use it to debug my application errors? and What is a NullPointerException, and how do I fix it?, then go to where the stack trace is telling you the error is so you can see the problem.– Slaw
Nov 17 '18 at 19:01
That means the fundamental cause is a
NullPointerException. Read What is a stack trace, and how can I use it to debug my application errors? and What is a NullPointerException, and how do I fix it?, then go to where the stack trace is telling you the error is so you can see the problem.– Slaw
Nov 17 '18 at 19:01
I guess it's
myImageView. OP might have forgotten to put fx:id in the FMXL– Gnas
Nov 17 '18 at 19:04
I guess it's
myImageView. OP might have forgotten to put fx:id in the FMXL– Gnas
Nov 17 '18 at 19:04
Nope it is too.
– Danielmagox
Nov 17 '18 at 19:12
Nope it is too.
– Danielmagox
Nov 17 '18 at 19:12
|
show 6 more comments
1 Answer
1
active
oldest
votes
You need to pass a Stage object to fileChooser.showOpenDialog. Try this:
File file = fileChooser.showOpenDialog(newWindow);
Edit: This is false as pointed out by @Slaw
The documentation indicates the argument may benull.
– Slaw
Nov 17 '18 at 18:57
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to pass a Stage object to fileChooser.showOpenDialog. Try this:
File file = fileChooser.showOpenDialog(newWindow);
Edit: This is false as pointed out by @Slaw
The documentation indicates the argument may benull.
– Slaw
Nov 17 '18 at 18:57
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
add a comment |
You need to pass a Stage object to fileChooser.showOpenDialog. Try this:
File file = fileChooser.showOpenDialog(newWindow);
Edit: This is false as pointed out by @Slaw
The documentation indicates the argument may benull.
– Slaw
Nov 17 '18 at 18:57
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
add a comment |
You need to pass a Stage object to fileChooser.showOpenDialog. Try this:
File file = fileChooser.showOpenDialog(newWindow);
Edit: This is false as pointed out by @Slaw
You need to pass a Stage object to fileChooser.showOpenDialog. Try this:
File file = fileChooser.showOpenDialog(newWindow);
Edit: This is false as pointed out by @Slaw
edited Nov 17 '18 at 19:03
answered Nov 17 '18 at 18:55
GnasGnas
50829
50829
The documentation indicates the argument may benull.
– Slaw
Nov 17 '18 at 18:57
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
add a comment |
The documentation indicates the argument may benull.
– Slaw
Nov 17 '18 at 18:57
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
The documentation indicates the argument may be
null.– Slaw
Nov 17 '18 at 18:57
The documentation indicates the argument may be
null.– Slaw
Nov 17 '18 at 18:57
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
I think you misundertstood. It doesn't say the argument can be null, only the result if no file is chosen
– Gnas
Nov 17 '18 at 18:59
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
"If the owner window for the file dialog is set..."
– Slaw
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
I just tried it and it gives the same error.
– Danielmagox
Nov 17 '18 at 19:00
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
@Slaw you're right, I just tried setting it to null in my existing code and it works.
– Gnas
Nov 17 '18 at 19:03
add a comment |
Is that the full stack trace? Are there any
Caused by:s you left out?– Slaw
Nov 17 '18 at 18:44
Yes, there are 2:
Caused by: java.lang.reflect.InvocationTargetException&Caused by: java.lang.NullPointerException– Danielmagox
Nov 17 '18 at 18:45
That means the fundamental cause is a
NullPointerException. Read What is a stack trace, and how can I use it to debug my application errors? and What is a NullPointerException, and how do I fix it?, then go to where the stack trace is telling you the error is so you can see the problem.– Slaw
Nov 17 '18 at 19:01
I guess it's
myImageView. OP might have forgotten to putfx:idin the FMXL– Gnas
Nov 17 '18 at 19:04
Nope it is too.
– Danielmagox
Nov 17 '18 at 19:12