Just tried to run my old tests in java-9 and see them not running at all due to an exception thrown by the code that guarantees running on the FX-threaad (the ol' trick to instantiate a JFXPanel)
The stand-alone example below (it's the plain tutorial code) throws it as well:
Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\java\jdk\190_ea\bin\awt.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1935)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1841)
at java.lang.Runtime.loadLibrary0(Runtime.java:874)
at java.lang.System.loadLibrary(System.java:1770)
at java.awt.Toolkit$3.run(Toolkit.java:1355)
at java.awt.Toolkit$3.run(Toolkit.java:1353)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Toolkit.java:1352)
at java.awt.Toolkit.<clinit>(Toolkit.java:1387)
at java.awt.EventQueue.invokeLater(EventQueue.java:1268)
at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1381)
at de.swingempire.fx.swing.JFXPanelExample.main(JFXPanelExample.java:59)
Environment is win7, jdk9-ea-107 (without jigsaw), eclipse-neon-ea - questions are simple: a) what's wrong exactly, b) how to fix?
The exact output of java -version is:
java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+107-2016-02-24-175644.javare.4520.nc)
Java HotSpot(TM) Client VM (build 9-ea+107-2016-02-24-175644.javare.4520.nc, mixed mode)
The code:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
public class JFXPanelExample {
private static void initAndShowGUI() {
// This method is invoked on the EDT thread
JFrame frame = new JFrame("Swing and JavaFX");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Platform.runLater(new Runnable() {
#Override
public void run() {
initFX(fxPanel);
}
});
}
private static void initFX(JFXPanel fxPanel) {
// This method is invoked on the JavaFX thread
Scene scene = createScene();
fxPanel.setScene(scene);
}
private static Scene createScene() {
Group root = new Group();
Scene scene = new Scene(root, Color.ALICEBLUE);
Text text = new Text();
text.setX(40);
text.setY(100);
text.setFont(new Font(25));
text.setText("Welcome JavaFX!");
root.getChildren().add(text);
return (scene);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
initAndShowGUI();
}
});
}
}
Update
tried both suggestions in the comments (updating to most recent 9-ea-107, running from the command line) - no success, same exception.
Another observation: the example above fails with the same stacktrace even when all fx related code is commented - plain swing won't run. Looks like something severely wrong in my environment.
Related
I want to create a Movie Player in javafx using eclipse.My code is compile successfully but it gives run time error.I tried using different file path also.
But it not resolved the error.
My code is
package Player3;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MediaPlayer3 extends Application{
public static void main(String args[])
{
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
Media media =new Media("file:////C://Kaise.MP4");
MediaPlayer player4=new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene =new Scene(root,400,400,Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
The error is
Exception in Application start method
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
As #Sergei Sirik mentioned this is JavaFX and not 'pure' java. Anyway reading the documentation of Media class for the constructor(String source) you will see :
The source must represent a valid URI and is immutable. Only HTTP, FILE, and JAR URLs are supported. If the provided URL is invalid then an exception will be thrown
So I will suggest first to create a File object ( to be able to check file permissions for read write etc ) and after that just pass the mediaFile.toURI().toString() to the Media class constructor and it will open.
Edit :
I guess you will use a FileChooser in future in order to load your video so it will make the file creation and handling much easier.
I had test the code below and it loads successfully my videos on my computer.
import java.io.File;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String args[]) {
launch(args);
}
public void start(Stage stage) throws Exception {
Group root = new Group();
FileChooser fc = new FileChooser();
File x = fc.showOpenDialog(null);
Media media = new Media(x.toURI().toString());
MediaPlayer player4 = new MediaPlayer(media);
MediaView view = new MediaView(player4);
root.getChildren().add(view);
Scene scene = new Scene(root, 400, 400, Color.BLACK);
stage.setScene(scene);
stage.show();
player4.play();
}
}
If you have any error like :
MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!
It's probably cause you alter the file signature by hand or try to play an unsupported file format like mkv.
I have Selenium IDE installed on Firefox, I ran a simple test on it and I exported the test cases to Netbeans under Java/JUNIT4/WebDriver. When I put the code in Netbeans and try to run it, It doesn't launch firefox. I've another simple program that will launch Firefox and go to google and search for cheese but when I try to export a test that I've ran using Selenium IDE, I can't get it to run. I'm not getting any errors and I get "successful build" when I run it, just nothing happens. Here's my code. Thanks
> Blockquotepackage firstpackage;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
//import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;
public class FirstPackage {
private WebDriver driver;
private String baseUrl;
//private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private boolean acceptNextAlert;
public static void main(String args[]){}
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.get("http://google.com");
baseUrl = "https://www.google.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// WebDriver driver = new FirefoxDriver();
System.out.println(driver.getTitle());
}
#Test
public void testGoogleSearch() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("Google");
driver.findElement(By.id("gbqfb")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}
// TODO code application logic h
> Blockquote
This problem is likely due to incompatible versions of Firefox and Selenium Firefox WebDriver.
My guess is that your program that works (the one that goes to Google and searches for cheese) has a different version of Selenium in its path than the one that NetBeans ends up using for your imported tests from the IDE.
For more information on how to deal with the version compatibility issue, see my answer to this question.
I just ran your code on my machine and it worked as expected. Make sure you're using correct jar files and are correctly mapped in your project.
I'm making a JFrame that will load pictures from the Internet. I have that working, but the problem with this JFrame is that there are many pictures, and so they take quite a while to load. This is fine, but I would like to show the user that the pictures are loading. For some reason, I can't get the JPanel to display in the loading JFrame. I know this is a common error, and I've tried many fixes, but none of them work. Here is the code:
final JFrame weatherLoadPop=new JFrame("Loading weather...");
weatherLoadPop.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
weatherLoadPop.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
weatherPop.dispose();
};
});
weatherLoadPop.setResizable(false);
weatherLoadPop.setBounds(100,50,225,100);
JPanel weatherLoadPanel=new JPanel();
weatherLoadPanel.setBackground(Color.RED);
weatherLoadPanel.setPreferredSize(new Dimension(225,100));
JLabel weatherLoadLabel=new JLabel("Loading...0%");
weatherLoadPanel.add(weatherLoadLabel);
weatherLoadPop.add(weatherLoadPanel);
weatherLoadPop.pack();
weatherLoadPop.validate();
weatherLoadPop.setVisible(true);
I'm not sure I'm using pack() and validate() correctly. I don't use them often. In any case, removing them does not help. The strangest part of this problem, to me, is that the JFrame that loads the pictures works beautifully, while the much simpler loading JFrame doesn't.
Thanks for any help.
It's working fine here. Maybe you should provide an sscce that we can test?
I had to change your event listener to dispose weatherLoadPop instead of weatherPop and added your code into a test class:
package test;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test {
public static void main(String[] args) {
final JFrame weatherLoadPop = new JFrame("Loading weather...");
weatherLoadPop.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
weatherLoadPop.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
weatherLoadPop.dispose();
}
;
});
weatherLoadPop.setResizable(false);
weatherLoadPop.setBounds(100, 50, 225, 100);
JPanel weatherLoadPanel = new JPanel();
weatherLoadPanel.setBackground(Color.RED);
weatherLoadPanel.setPreferredSize(new Dimension(225, 100));
JLabel weatherLoadLabel = new JLabel("Loading...0%");
weatherLoadPanel.add(weatherLoadLabel);
weatherLoadPop.add(weatherLoadPanel);
weatherLoadPop.pack();
weatherLoadPop.validate();
weatherLoadPop.setVisible(true);
}
}
and I'm getting:
using:
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
I am looking to read xls file using the gwt RPC and when I am using the code which excecuted fine in normal file it is unable to load the file and giving me null pointer exception.
Following is the code
{
{
import com.arosys.readExcel.ReadXLSX;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.Preview.client.GWTReadXL;
import java.io.InputStream;
import com.arosys.customexception.FileNotFoundException;
import com.arosys.logger.LoggerFactory;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* #author Amandeep
*/
public class GWTReadXLImpl extends RemoteServiceServlet implements GWTReadXL
{
private String fileName;
private String[] Header=null;
private String[] RowData=null;
private int sheetindex;
private String sheetname;
private XSSFWorkbook workbook;
private XSSFSheet sheet;
private static Logger logger=null;
public void loadXlsxFile() throws Exception
{
logger.info("inside loadxlsxfile:::"+fileName);
InputStream resourceAsStream =ClassLoader.getSystemClassLoader().getSystemResourceAsStream("c:\\test2.xlsx");
logger.info("resourceAsStream-"+resourceAsStream);
if(resourceAsStream==null)
throw new FileNotFoundException("unable to locate give file");
else
{
try
{
workbook = new XSSFWorkbook(resourceAsStream);
sheet = workbook.getSheetAt(sheetindex);
}
catch (Exception ex)
{
logger.error(ex.getMessage());
}
}
}// end loadxlsxFile
public String getNumberOfColumns() throws Exception
{
int NO_OF_Column=0; XSSFCell cell = null;
loadXlsxFile();
Iterator rowIter = sheet.rowIterator();
XSSFRow firstRow = (XSSFRow) rowIter.next();
Iterator cellIter = firstRow.cellIterator();
while(cellIter.hasNext())
{
cell = (XSSFCell) cellIter.next();
NO_OF_Column++;
}
return NO_OF_Column+"";
}
}
}
I am calling it in client program by this code:
final AsyncCallback<String> callback1 = new AsyncCallback<String>() {
public void onSuccess(String result) {
RootPanel.get().add(new Label("In success"));
if(result==null)
{
RootPanel.get().add(new Label("result is null"));
}
RootPanel.get().add(new Label("result is"+result));
}
public void onFailure(Throwable caught) {
RootPanel.get().add(new Label("In Failure"+caught));
}
};
try{
getService().getNumberOfColumns(callback1);
}catch(Exception e){}
}
Pls tell me how can I resolve this issue as the code runs fine when run through the normal java file.
Why are using using the system classloader, rather than the normal one?
But, If you still want to use then look at this..
As you are using like a web application. In that case, you need to use the ClassLoader which is obtained as follows:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
This one has access to the all classpath paths tied to the webapplication in question and you're not anymore dependent on which parent classloader (a webapp has more than one!) has loaded your class.
Then, on this classloader, you need to just call getResourceAsStream() to get a classpath resource as stream, not the getSystemResourceAsStream() which is dependent on how the webapplication is started. You don't want to be dependent on that as well since you have no control over it at external hosting:
InputStream input = classLoader.getResourceAsStream("filename.extension");
The location of file should in your CLASSPATH.
While am trying to execute the Helloword process example from the section 2.3 in
https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/docs/drools-flow/html_single/index.html#d4e24 site am unable to find the below mentioned class.
org.drools.builder.KnowledgeType
Could anyone please tell from which package can i get this class?
Thanks!
That part of the documentation seems a little outdated. You should use ResourceType. I've updated the docs with the following code fragment instead (should also appear on the link you're using once the build succeeds):
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
/**
* This is a sample file to launch a process.
*/
public class ProcessTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// start a new process instance
ksession.startProcess("com.sample.ruleflow");
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
return kbuilder.newKnowledgeBase();
}
}