I'm trying to run my first JavaFX example, and I'm stumped because I cannot get the following example to run. I have read related items about java.lang.NoClassDefFoundError and I'm guessing it's a CLASSPATH issue, but I'm still new enough to java that I could not figure out what the problem might be from the other similar question here and elsewhere on the Internet. The same error occurs whether CLASSPATH is NOT set, or set to the value listed at the end. Any pointers would be much appreciated.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
It compiles, but when I run it I get the following stack trace:
> javac HelloWorld.java
> java HelloWorld
Exception in Application start method
java.lang.NoClassDefFoundError: Could not initialize class com.sun.javafx.css.StyleHelper
at com.sun.javafx.css.StyleManager$StylesheetContainer.getStyleHelper(StyleManager.java:1390)
at com.sun.javafx.css.StyleManager$StylesheetContainer.access$1300(StyleManager.java:1039)
at com.sun.javafx.css.StyleManager.getStyleHelper(StyleManager.java:976)
at javafx.scene.Node.impl_createStyleHelper(Node.java:7433)
at javafx.scene.Node.impl_processCSS(Node.java:7403)
at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
at javafx.scene.Node.processCSS(Node.java:7383)
at javafx.scene.Scene.doCSSPass(Scene.java:446)
at javafx.scene.Scene.access$3800(Scene.java:170)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2202)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:460)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:329)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82)
at java.lang.Thread.run(Thread.java:722)
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ExceptionInInitializerError
at com.sun.javafx.css.StyleManager$StylesheetContainer.getStyleHelper(StyleManager.java:1390)
at com.sun.javafx.css.StyleManager$StylesheetContainer.access$1300(StyleManager.java:1039)
at com.sun.javafx.css.StyleManager.getStyleHelper(StyleManager.java:976)
at javafx.scene.Node.impl_createStyleHelper(Node.java:7433)
at javafx.scene.Node.impl_processCSS(Node.java:7403)
at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
at javafx.scene.Node.processCSS(Node.java:7383)
at javafx.scene.Scene.doCSSPass(Scene.java:446)
at javafx.scene.Scene.preferredSize(Scene.java:1449)
at javafx.scene.Scene.impl_preferredSize(Scene.java:1516)
at javafx.stage.Window$9.invalidated(Window.java:716)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
at javafx.stage.Window.setShowing(Window.java:779)
at javafx.stage.Window.show(Window.java:794)
at javafx.stage.Stage.show(Stage.java:229)
at HelloWorld.start(HelloWorld.java:30)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82)
... 1 more
Caused by: java.lang.NullPointerException
at com.sun.t2k.LogicalFont.<init>(LogicalFont.java:172)
at com.sun.t2k.LogicalFont.getLogicalFont(LogicalFont.java:104)
at com.sun.t2k.LogicalFont.getLogicalFont(LogicalFont.java:144)
at com.sun.t2k.T2KFontFactory.createFont(T2KFontFactory.java:356)
at com.sun.prism.j2d.J2DFontFactory.createFont(J2DFontFactory.java:38)
at com.sun.javafx.font.PrismFontLoader.loadFont(PrismFontLoader.java:399)
at javafx.scene.text.Font.<init>(Font.java:282)
at javafx.scene.text.Font.getDefault(Font.java:85)
at com.sun.javafx.css.StyleHelper.<clinit>(StyleHelper.java:1600)
... 27 more
Some other details:
Red Hat Enterprise Linux 6.2 on x64
jdk1.7.0_21
> printenv CLASSPATH
.:/usr/java/jdk1.7.0_21/jre/lib/*:/usr/java/jdk1.7.0_21/jre/lib/ext/*
There are multiple jdks installed, but I checked to be sure that both javac and java point to the jdk1.7.0_21 version.
I've search Oracle's web site, this site, and a few other Internet sites, but not found mention of this error related to JavaFX.
If issue is the same as : https://javafx-jira.kenai.com/browse/RT-28405
Then the solution by Phil Race :
Since adding a TTF font to /usr/share/fonts works, then it seems like we are successfully
using /usr/libfontconfig to locate the installed fonts, but apparently there were none to our liking.
i.e. FX does not support Type 1 fonts (a policy decision), only TrueType and OpenType/CFF fonts.
Are you running with OpenJDK or Oracle JDK? I'd bet an OpenJDK that wsa bundled with slackware
OpenJDK has no fonts of its own, whereas OracleJDK has some of its own TrueType fonts so would
not hit this problem.
The bottom line here seems to be that you should install a decent set of TrueType fonts.
I think the only thing we can do on our end is improve the diagonostic when this happens.
For those without root access, you can also add a true type font to ~/.fonts/TTF to resolve this issue.
Related
I want to write an application that runs with two different windows, one with JavaFX (v18) and one with Processing (v4). I'm on Linux 64-bit using IntelliJ-Idea as IDE and Maven to manage dependencies. The project is created as a JavaFX project and the processing.core library is added as a separate project library.
I spent A LOT of TIME understanding how to set up the project correctly and I succeeded in launching a simple JFX app that creates a new window where a 2D sketch runs fine (a circle that follows the mouse's coordinates).
The problem comes out when I try to launch a 3D sketch (because that's what i need for my application) with the P3D render and I receive an exception with:
java.lang.UnsatisfiedLinkError: Can't load library: /home/.../natives/linux-amd64/libgluegen_rt.so
As suggested here I already tried to solve adding the jogl-fat.jar library as a project's library or dependencies for the jogl libraries from maven, without effects.
I don't think that something is wrong with my code but it's Processing or JFX's fault.
PS: I have to use processing to make a 3D environment for simulation, but I don't have restrictions for JavaFX. If someone knows another framework that can let me launch a P3D sketch and interact with it with some controls (i.e. buttons), you are welcome!
This is an example of the java classes that I have:
public class HelloApplication extends Application {
#Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
public class ProcessingTest extends PApplet{
private PeasyCam cam;
#Override
public void setup() {
background(255);
cam = new PeasyCam(this, 400);
}
public void settings(){
size(200, 200, P3D);
}
public void draw(){
background(255);
rotateX(-.5f);
rotateY(-.5f);
lights();
scale(5);
strokeWeight(1 / 10f);
fill(96, 255, 0);
box(30);
pushMatrix();
translate(0, 0, 20);
fill(0, 96, 255);
box(5);
popMatrix();
}
public void run(){
String[] args = {"com.effibot.provafx.ProcessingTest"};
PApplet.runSketch(args,this);
}
}
public class HelloController {
#FXML
private Label welcomeText;
private ProcessingTest pt;
#FXML
protected void onHelloButtonClick() {
welcomeText.setText("Welcome to JavaFX Application!");
pt = new ProcessingTest();
pt.run();
}
}
Unfortunately I don't have experience with your exact setup (64-bit Linux, IntelliJ, JavaFX application), but hopefully I can point you in the right direction.
The OpenGL native libraries should ship with Processing:
processing-4.0b8-linux-x64.tar/processing-4.0b8/core/library/linux-amd64
should contain:
libgluegen_rt.so
libnativewindow_awt.so
libnativewindow_drm.so
libnewt_head.so
libnativewindow_x11.so
libjogl_desktop.so
libnewt_drm.so
libjogl_mobile.so
Hopefully the IntelliJ docs can help with the native library setup.
The idea is that you'd tell IntelliJ not only to use core.jar, jogl-all.jar and gluegen-rt.jar but also set the native library paths to point to the .so files.
(as jewelsea mentions, in the run options you could set the native path as a command line argument (e.g. if Processing in unzipped in the home folder -Djava.library.path=/home/processing-4.0b8-linux-x64.tar/processing-4.0b8/core/library/linux-amd64) but I hope IntelliJ's interface is straight forward enough to easily allow you to set the native library path for the gluegen and jogl libraries)
(Also, bare in mind Processing ships with it's own JDK packaged (in processing-4.0b8/java): in case you run into some java version related issues you could switch the JDK in IntelliJ))
I am trying to learn how to code with JavaFx but every time I try to create an object (ex.: WebView webview = new Webview();) I get this error:
ERROR-START{
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:567) at
javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at
javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
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:567) 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:900)
at
javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830) Caused by:
java.lang.IllegalAccessError: superclass access check failed: class
com.sun.javafx.sg.prism.web.NGWebView (in unnamed module #0x7dab7530)
cannot access class com.sun.javafx.sg.prism.NGGroup (in module
javafx.graphics) because module javafx.graphics does not export
com.sun.javafx.sg.prism to unnamed module #0x7dab7530 at
java.base/java.lang.ClassLoader.defineClass1(Native Method) at
java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016) at
java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at
java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
at
java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at AppL.start(AppL.java:8) at
javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at
javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at
javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at
java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at
javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
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:174)
... 1 more Exception running application AppL
}ERROR-ENDING
I've tried to add: (I also added the PATH_TO_FX Path-variable)
--module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml
to the run configurations VM-options but it only changed the error I had before this error. I tried to do this on Windows AND on Linux, neither works.
Intellj shows me that every thing works, but it doesn't.
I wanted to use netbeans or eclipse but I don't know how to add libraries to them.
That would helb me to.
Example code:
import javafx.application.Application;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class AppL extends Application {
#Override
public void start(Stage stage) throws Exception {
WebView v = new WebView();
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Thanks to anyone who wants to help me, and who doesn't lauph on my english-scills😊
I'm just starting to learn coding for Android App by following the book Android App Development for Dummies to create the Silent Mode Toggle App.
Everything seems fine in the code (no error except for warning that:
"Casting 'findViewById(R.id.phone_icon)' to 'ImageView' is redundant.
This inspection reports unnecessary cast expressions."
I have read through a similar problem here (Application Crashes - Silent Mode Toggle - Android for Dummies) and it says to try:
1) Change "extends ActionBarActivity" to just "extends Activity" and import - mine is already as such.
2) delete or comment the 'if' in the onCreate method out - mine don't have this section.
3) change the parameter of the setContentView to: R.layout.fragment_main - not very sure what this means but don't seem to be relevant to my code? (his codes and mine are slightly different)
MainActivity.java Code
package com.dummies.silentmodetoggle;
import android.app.Activity;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.dummies.silentmodetoggle.util.RingerHelper;
public class MainActivity extends Activity {
AudioManager audioManager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
setContentView(R.layout.activity_main);
FrameLayout contentView =
(FrameLayout) findViewById(R.id.content);
contentView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
RingerHelper.performToggle(audioManager);
updateUi();
}
});
}
private void updateUi() {
ImageView imageView = (ImageView) findViewById(R.id.phone_icon);
int phoneImage = RingerHelper.isPhoneSilent(audioManager)
? R.mipmap.ringer_off
: R.mipmap.ringer_on;
imageView.setImageResource(phoneImage);
}
#Override
protected void onResume(){
super.onResume();
// Update our UI in case anything has changed.
updateUi();
}
}
RingerHelper.java
The book says to create a java file at: "src/main/java/com/dummies/silentmodetoggle/util/RingerHelper.java" but did not state how. Since I do not have a util folder so I'd created a package (New>Package) at "src/main/java/com.dummies.silentmodetoggle" and added the RingerHelper java file in the util folder. Note sure if this is the problem? The code is as below:
package com.dummies.silentmodetoggle.util;
import android.media.AudioManager;
public class RingerHelper {
// private to prevent users from creating a RingerHelper object
private RingerHelper(){}
/* Toggles the phone's silent mode */
public static void performToggle(AudioManager audioManager) {
// If the phone is currently silent, then unsilence it. If
// it's currently normal, then silence it.
audioManager.setRingerMode(
isPhoneSilent(audioManager)
? AudioManager.RINGER_MODE_NORMAL
: AudioManager.RINGER_MODE_SILENT);
}
/* Returns whether the phone is currently in silent mode. */
public static boolean isPhoneSilent(AudioManager audioManager){
return audioManager.getRingerMode()
== AudioManager.RINGER_MODE_SILENT;
}
}
Error from LogCat when I clicked the button on app
2018-12-01 22:11:44.029 30122-30122/com.dummies.silentmodetoggle E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dummies.silentmodetoggle, PID: 30122
java.lang.SecurityException: Not allowed to change Do Not Disturb state
at android.os.Parcel.readException(Parcel.java:1683)
at android.os.Parcel.readException(Parcel.java:1636)
at android.media.IAudioService$Stub$Proxy.setRingerModeExternal(IAudioService.java:962)
at android.media.AudioManager.setRingerMode(AudioManager.java:1022)
at com.dummies.silentmodetoggle.util.RingerHelper.performToggle(RingerHelper.java:13)
at com.dummies.silentmodetoggle.MainActivity$1.onClick(MainActivity.java:60)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
2018-12-01 22:11:44.672 1315-1315/? E/EGL_emulation: tid 1315: eglCreateSyncKHR(1901): error 0x3004 (EGL_BAD_ATTRIBUTE)
Otherwise the app seems to work fine, ie, when I click on the volume button of the device itself to silent, the app image will change to silent and vice versa. It just crashes when I try to click on the image of the app itself.
I really have no idea what's going on. Please help. Thanks very much!
You need to add permissions for Do Not Disturb State. I was facing the same issue and I added the following lines to my Main_Activity.java code in onCreate method and it works fine Now:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if(notificationManager.isNotificationPolicyAccessGranted())
{
Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivity(intent);
}
I am using jdk1.8.0_25.
I am trying to run a JavaFX app file below which, when named 'HelloWorldMain.java', compiles and runs OK with javac/java. I renamed it as 'HelloWorldMain.groovy' and can't run it using Groovy.
Is there a simple way to run this file using Groovy with no or minimal modification, preferably without additional software like GroovyFX? And if I have to use GroovyFX, can I run this pure Java code without modification?
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
/**
*
* #author cdea
*/
public class HelloWorldMain extends Application {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World");
Group root = new Group();
Scene scene = new Scene(root, 300, 250);
Button btn = new Button();
btn.setLayoutX(100);
btn.setLayoutY(80);
btn.setText("Hello World");
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
System.out.println("Hello World");
}
});
root.getChildren().add(btn);
primaryStage.setScene(scene);
primaryStage.show();
}
}
I am trying to run it as
groovy HelloWorldMain.groovy
and getting the following output in command line:
Caught: java.lang.RuntimeException: java.lang.ClassNotFoundException: javafx.application.Application$launch
java.lang.RuntimeException: java.lang.ClassNotFoundException: javafx.application.Application$launch
at javafx.application.Application.launch(Application.java:260)
at javafx.application.Application$launch.call(Unknown Source)
at HelloWorldMain.main(HelloWorldMain.groovy:20)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application$launch
at javafx.application.Application.launch(Application.java:248)
... 2 more
replace the main method with:
public static void main(String[] args) {
launch(HelloWorldMain, args);
}
The error basically gives you the answer: no you can not just copy the files in all cases. There are differences between groovy and java (e.g. http://groovy-lang.org/differences.html). Groovy comes with a tool called java2groovy that might help migrate.
But as groovy runs fine with java code, why bother? Migrate the parts, that are better off using groovy and keep the java parts around for now.
Hi i am using Google Maps in a code
This is the code written in the activity file
package com.hellomaps;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class HelloGoogleMaps extends MapActivity{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
Now in the line setContentView(R.layout.main) it does not recognse "R" and hence mapview cannot be used in the activity as it doesnot recognse the view
I know android.R and com.google.R should not be imported.
i am stuck here .. kindly help..!!
Thanks in Advance
R file is generated when you compile your project. So if you are using eclipse just press ctrl+b and R file should appear in gen folder in your project.
If you checked out project from SVN or some other version control you could have problem with R file. If you do, create new android project in eclipse then copy/paste source and resources from checked out project to new created one and build. Hope this helps.