Exception in Aplication start method -- JavaFx with Intellj - object

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😊

Related

App Crashes on Button Click that was supposed to send a call instantly

I have set up the button such a way that upon the click of a button it will send a call. when the button is clicked the app crashes. Please Help me debug this. Please suggest if there are alternative ways i can code a button to send a call directly upon clicking on it. I have granted permission in the settings as well.
package com.example.allegiant;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button dial;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dial = findViewById(R.id.dial);
}
public void onDialButton(View view) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tell:12345678"));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(intent);
}
}
Here is the logcat
2021-03-22 21:56:33.365 7530-7530/com.example.allegiant E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.allegiant, PID: 7530
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:6294) 
at android.view.View$PerformClick.run(View.java:24770) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tell:12345678 }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1937)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4487)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at android.app.Activity.startActivityForResult(Activity.java:4445)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
at android.app.Activity.startActivity(Activity.java:4806)
at android.app.Activity.startActivity(Activity.java:4774)
at com.example.allegiant.MainActivity.onDialButton(MainActivity.java:34)
at java.lang.reflect.Method.invoke(Native Method) 
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397) 
at android.view.View.performClick(View.java:6294) 
at android.view.View$PerformClick.run(View.java:24770) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Try adding READ_PHONE_STATE permission in manifest as well as ask it before click.
android.permission.READ_PHONE_STATE
Also surround your code inside click with try - catch having ActivityNotFoundException handling

DrJava scriptengine doesn't work

I try to evaluate math expression in string form using scriptengine, but it throws me NullPointerException
java.lang.NullPointerException
at Math.main(Math.java:12)
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 edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
Here is the code:
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Math{
public static void main(String[] args){
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
try {
System.out.println("scriptEngine result: "+jsEngine.eval("{2+4*3*[1+(1+2+4)]}"));
} catch (ScriptException ex) {
Logger.getLogger(Math.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
i tried the same code in netbeans and it works, but i also need it to work in DrJava development environment.
Is it possible to resolve this or is there any other library that can evaluate string like this with combination of all parenthesis "{[()]}"?

Gridgain serialization exception

I am trying out gridgain for the first time and facing some issues with serialization. While trying to use GridClosure to project jobs on different nodes I get marshaling exception . On debugging, It seems the failure is always for Apache log4j Logger object. Its difficult for me to avoid loggers and wanted to understand if this is a known issue or someway I can remedy this. I have requireSerializable set to false for my grid config.
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeSerializable(GridOptimizedObjectOutputStream.java:292)
... 45 more
Caused by: java.io.IOException: java.lang.reflect.InvocationTargetException
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeSerializable(GridOptimizedObjectOutputStream.java:295)
at org.gridgain.grid.marshaller.optimized.GridOptimizedClassDescriptor.write(GridOptimizedClassDescriptor.java:849)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeObject0(GridOptimizedObjectOutputStream.java:198)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeObjectOverride(GridOptimizedObjectOutputStream.java:129)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:342)
at java.util.Hashtable.writeObject(Hashtable.java:988)
... 50 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeSerializable(GridOptimizedObjectOutputStream.java:292)
... 55 more
Caused by: java.lang.NullPointerException
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream$PutFieldImpl.value(GridOptimizedObjectOutputStream.java:1003)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream$PutFieldImpl.put(GridOptimizedObjectOutputStream.java:965)
at java.util.Vector.writeObject(Vector.java:1068)
... 60 more
Can you make Log4J object static so it does not affect serialization? If not, GridGain allows you to inject logger resource into pretty much anything, including closures. You can configure GridLogger as GridLog4jLogger in GridConfiguration.
Here is an example:
GridRunnable run = new GridRunnable() {
// Can be any logger, including GridLog4jLogger.
#GridLoggerResource
GridLogger log;
#Override public void run() {
log.info("Hello");
// Do some logic.
}
}
or
// Can be any logger, including GridLog4jLogger
final GridLogger log = grid.log();
GridRunnable run = new GridRunnable() {
#Override public void run() {
log.info("Hello");
// Do some logic.
}
}
For more information, refer to Resource Injection page in GridGain documentation.

Null pointer exception on Initialize second controller class from first controller class

I am trying to access initialize method of another calss from a different class.But I am getting nullpointer Exception while returning ctroller
THis is the code I am trying to call from my second calss.
Line1- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/src/myjavfxapp/controller/EditClientDetails.fxml"));
Line 2- EditClientDetailsController fooController = (EditClientDetailsController) fxmlLoader.getController();
Line3- fooController.initialize(null, null);
I am getting null pointer exception at line number 3.
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
... 44 more
Caused by: java.lang.NullPointerException
at myjavfxapp.controller.NewUserController.saveNewuser(NewUserController.java:167)
... 54 more
My Intention is to initialize the "EditClientDetails.fxml" fields from different controller class.
Please point out if i missed anything.
Try the below example it working fine, you have to use load() function of FxmlLoader class.
public class Xxx extends Application {
#Override
public void start(Stage stage) throws Exception {
//Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("Sample.fxml"));
Parent root = (Parent)loader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
SampleController controller = (SampleController)loader.getController();
}
public static void main(String[] args) {
launch(args);
}
}

Could not initialize class com.sun.javafx.css.StyleHelper

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.

Resources