Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Snapshot of any node throws IllegalArgumentException when screen is locked - how can we avoid this?

AndipaSep 6 2013 — edited Sep 19 2013

Here's some example code that won't work if the snapshot is taken while the screen is locked (and it was locked after application start) in both Java 7 and 8.


Is there a way to test whether the screen is locked or even better get notified when it is unlocked, so we don't accidentally run into this?

I also suspect there are more causes than just the screen being locked, so it would be great to know when this can happen in general.


import javafx.application.Application;

import javafx.application.Platform;

import javafx.scene.Scene;

import javafx.scene.layout.BorderPane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Rectangle;

import javafx.stage.Stage;

public class SnapshotTester extends Application {

    @Override

    public void start(Stage primaryStage) throws Exception {

        final BorderPane borderPane = new BorderPane();

        final Rectangle rectangle = new Rectangle(20, 20, Color.BLUE);

        borderPane.setCenter(rectangle);

        Scene scene = new Scene(borderPane);

        primaryStage.setScene(scene);

        primaryStage.show();

        new Thread(new Runnable() {

            @Override

            public void run() {

                try {

                    Thread.sleep(2000);

                    Platform.runLater(new Runnable() {

                        @Override

                        public void run() {

                            Image snapshot = rectangle.snapshot(null, null);

                            System.out.println("Snapshot taken: " + snapshot);

                        }

                    });

                } catch (InterruptedException ignored) {

                }

            }

        }).start();

    }

    public static void main(String[] args) {

        launch(args);

    }

}

To reproduce do the following:

1) Start application

2) Lock screen as soon as window is shown

3) Unlock after two seconds


You'll get the following exception which is unfortunately not very expressive:


java.lang.IllegalArgumentException: Unrecognized image loader: null
at javafx.scene.image.WritableImage.loadTkImage(WritableImage.java:230)
at javafx.scene.image.WritableImage.access$000(WritableImage.java:44)
at javafx.scene.image.WritableImage$1.loadTkImage(WritableImage.java:49)
at javafx.scene.Scene.doSnapshot(Scene.java:1144)
at javafx.scene.Node.doSnapshot(Node.java:1632)
at javafx.scene.Node.snapshot(Node.java:1710)



Comments

Zachariah Falgout

So it is separate by chr(13). This seems like a bug in Apex to me.

TexasApexDeveloper
Answer

HTML does NOT use the same carriage return + line feed as database.  You have the CR+LF characters in the field, and the search can't deal with them properly. To html a <br> is a line break. To be honest your database design leaves something to be desired..

I would save this as MTWTHF and get rid of the break between..

Thank you,

Tony Miller

Los Alamos, NM

Marked as Answer by Zachariah Falgout · Sep 27 2020
Zachariah Falgout

It is broken up to be on separate lines so the different schedules for a class line up the same.

So MWF 9-950 Building A

     TR    11-150 Building B

where days, times, and buildings are in their own column. Makes it easy for students to read.

Lol, probably but I am stuck with how the university stored the data, so I only have control over the table that combines the data from various per-existing tables.

So it is a bit difficult getting things to work and look nice in the app when the data that was originally stored isn't very neat.

But your answer makes sense, and honestly wouldn't have thought it as a html not being able to handle those characters. Still new to apex.

Thanks for your help.

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 17 2013
Added on Sep 6 2013
5 comments
1,066 views