Problem while running j2me application in netbeans - java

i am very new to j2me. i have created a sample program, but i am not able run that program. Build failed message came. My code is :
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* #author aneesh
*/
public class httpconnection extends MIDlet {
private Command exit, start;
private Display display;
private Form form;
public httpconnection ()
{
}
public void startApp() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
start = new Command("Start", Command.EXIT, 1);
form = new Form("Http Connection");
form.addCommand(exit);
form.addCommand(start);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
and the error i am getting is
java.lang.UnsatisfiedLinkError: /usr/local/netbeans-7.0/mobility/WTK2.5.2/bin/sublime.so: /usr/local/netbeans-7.0/mobility/WTK2.5.2/bin/sublime.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1646)
at java.lang.Runtime.load0(Runtime.java:787)
at java.lang.System.load(System.java:1022)
at com.sun.kvem.Sublime.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at com.sun.kvem.Lime.createLime(Unknown Source)
at com.sun.kvem.KVMBridge.<init>(Unknown Source)
at com.sun.kvem.KVMBridge.getBridge(Unknown Source)
at com.sun.kvem.midp.MIDP.run(Unknown Source)
at com.sun.kvem.environment.EmulatorInvoker.runEmulatorImpl(Unknown Source)
at com.sun.kvem.environment.EmulatorInvoker.main(Unknown Source)
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:616)
at com.sun.kvem.environment.JVM.main(Unknown Source)
NetBeansProjects/VDCustomComponents1/nbproject/build-impl.xml:915: Execution failed with error code 1.
BUILD FAILED (total time: 3 seconds)

It seems like you have 32-bit WTK and 64-bit JDK. You should install the matching 32-bit JDK and set the WTK to use it.
Command-line WTK installer downloaded from Sun (Oracle) website should ask you for the JDK location during installation.

Related

Client/Server jars - Exception in thread "main" java.lang.reflect.InvocationTargetException

I have a javafx project in eclipse ready to run. I have a client and a server.
I have tried to run server and client in eclipse and everything works fine, but when I exported to runnable jars, one to server and one to client, the server jar works fine, but the client throws exception: Exception in thread "main" java.lang.reflect.InvocationTargetException
although it works fine before exporting in eclipse.
Server and Client are both javafx applications that start with GUI.
ClientLauncher.java:
package client;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
public class ClientLauncher extends Application {
public GCMClient gcmClient;
private String host = "localhost";
private int port = 5555;
private double xOffset = 0;
private double yOffset = 0;
public static void main(String[] args) {
launch();
}
#Override
public void start(Stage PrimaryStage) throws Exception {
System.out.println("Client Connection Established");
Parent root = FXMLLoader.load(getClass().getResource("/sources/ServerLogin.fxml"));
root.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
PrimaryStage.setX(event.getScreenX() - xOffset);
PrimaryStage.setY(event.getScreenY() - yOffset);
}
});
Scene scene = new Scene(root);
PrimaryStage.setScene(scene);
PrimaryStage.show();
}
}
The exception I get:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.load(Unknown Source)
at client.ClientLauncher.start(ClientLauncher.java:33)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
Solved:
I have misspelled ServerLogin.fxml in
Parent root = FXMLLoader.load(getClass().getResource("/sources/ServerLogin.fxml"));
Which is named "ServerLogIn.fxml" in my case.
It appears that the name of the fxml is case sensitive in runnable jar, but It's not in eclipse. That's why it worked fine in eclipse and didn't work in jar.

Libaries correctly extracted?

A few days ago I switched from the Eclipse IDE to IntelliJ IDE. This is my first time I am coding with IntelliJ. I don't know how I can describe my Problem. :D Where is the Problem? I use this Java Application as a Plugin in my Bungeecord-Proxy
Stacktrace:
20:46:16 [WARNING] Exception encountered when loading plugin:
CloudNet-RestAPI java.lang.ExceptionInInitializerError at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:264) at
com.sun.proxy.$Proxy9.(Unknown Source) at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:739) at
com.sun.jersey.server.impl.application.WebApplicationImpl$26.run(WebApplicationImpl.java:1626)
at java.security.AccessController.doPrivileged(Native Method) at
com.sun.jersey.server.impl.application.WebApplicationImpl.createProxy(WebApplicationImpl.java:1623)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.(WebApplicationImpl.java:335)
at
com.sun.jersey.server.impl.container.WebApplicationProviderImpl.createWebApplication(WebApplicationProviderImpl.java:55)
at
com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:66)
at
com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:160)
at
com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:264)
at
com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:246)
at
com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:117)
at
com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:92)
at me.singulativ.restapi.main.RestAPI.onEnable(RestAPI.java:17) at
net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:227)
at net.md_5.bungee.BungeeCord.start(BungeeCord.java:266) at
net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:56)
at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15) Caused by:
java.lang.RuntimeException: java.lang.ClassNotFoundException:
com.sun.ws.rs.ext.RuntimeDelegateImpl at
javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
at
javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
at javax.ws.rs.core.EntityTag.(EntityTag.java:35) ... 24
more Caused by: java.lang.ClassNotFoundException:
com.sun.ws.rs.ext.RuntimeDelegateImpl at
net.md_5.bungee.api.plugin.PluginClassloader.loadClass0(PluginClassloader.java:53)
at
net.md_5.bungee.api.plugin.PluginClassloader.loadClass(PluginClassloader.java:27)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:264) at
javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:62) at
javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:155) at
javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:105)
... 26 more
Code:
package me.singulativ.restapi.main;
import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.net.httpserver.HttpServer;
import net.md_5.bungee.api.plugin.Plugin;
import java.io.IOException;
public class RestAPI extends Plugin {
private HttpServer server;
#Override
public void onEnable() {
try {
String host = "http://localhost:12345/";
server = HttpServerFactory.create(host);
server.start();
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void onDisable() {
server.stop(0);
}
}
Dependencies
Artifacts

Localization code throwing unexpected exceptions in java

I'm working on a project for school. Part of the prompt for the application specifies that I'm supposed to add localization to the log in page to translate the text in to two other languages. I don't have any experience with localization and Internationalization so I looked up a tutorial on YouTube that you can find here.
The tutorial is slightly simpler than what I'm trying to do, but I thought that I extrapolated the information effectively. What I'm about to post is just a test to see if I could get the log-in prompt text to change language, based on a radio button selection by the user. Here is my log in controller class:
import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class LogInController implements Initializable {
#FXML
private Label logInPrompt;
#FXML
private TextField userNameField;
#FXML
private TextField passwordTextField;
#FXML
private RadioButton english;
#FXML
private RadioButton spanish;
#FXML
private RadioButton french;
#FXML
public void Login(ActionEvent event) throws Exception {
if (userNameField.getText().equals("user") && passwordTextField.getText().equals("password")) {
logInPrompt.setText("Log in successful!");
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
} else {
logInPrompt.setText("Log in Failed");
}
}
public String enLang = "en";
public String spLang = "sp";
public String frLang = "fr";
public String unitedStates = "US";
public String mexico = "MX";
public String france = "FR";
Locale us = new Locale(enLang, unitedStates);
ResourceBundle rbEn = ResourceBundle.getBundle("C195/MessageBundle_en_US", us);
Locale mx = new Locale(spLang, mexico);
ResourceBundle rbSp = ResourceBundle.getBundle("C195/MessageBundle_es_MX", mx);
Locale fr = new Locale(frLang, france);
ResourceBundle rbFr = ResourceBundle.getBundle("C195/MessageBundle_fr_FR", fr);
public String enLogIn = rbEn.getString("logInPromptEN");
public String spLogIn = rbSp.getString("logInPromptSP");
public String frLogIn = rbFr.getString("logInPromptFR");
public void langSelect(){
if (english.isSelected()){
logInPrompt.setText(enLogIn);
}else if (spanish.isSelected()){
logInPrompt.setText(spLogIn);
}else if (french.isSelected()){
logInPrompt.setText(frLogIn);
}
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Here is an example of one of my properties files, the other two are the same except they are for the other two languages:
logInPromptSP = Ingrese su nombre de usuario y contraseƱa:
The application runs if I comment out the localization code, but if I run it without the comment I get a list of exceptions and errors a mile long, very few of which I'm familiar with.
To try to figure this problem out, I went back and read through the Localization and Internationalization portion in my OCP study guide, and I searched through StackOverflow using search terms similar to the title of my question.
Any help anyone could offer me on this issue would be greatly appreciated. Also just a quick note: This is the first question I've ever posted on StackOverflow and I read the guidelines but I'm a complete noob at both programming and at using StackOverflow. So please kindly let me know if the way that I formatted my question or the problem I asked about is in any way inappropriate.
Here is the full stack trace:
ant -f C:\\Users\\Forbes\\Documents\\NetBeansProjects\\C195 jfxsa-run
init:
Deleting: C:\Users\Forbes\Documents\NetBeansProjects\C195\build\built- jar.properties
deps-jar:
Updating property file: C:\Users\Forbes\Documents\NetBeansProjects\C195\build\built-jar.properties
compile:
Deleting directory C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\lib
Copying 1 file to C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\lib
Detected JavaFX Ant API version 1.3
jfx-deployment:
jar:
Copying 13 files to C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\run302791547
jfx-project-run:
Executing C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\run302791547\C195.jar using platform C:\Program Files\Java\jdk1.8.0_51\jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav a:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.j ava:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav a:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917 )
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImp l.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1343441044.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/Forbes/Documents/NetBeansProjects/C195/dist/run302791547/C195.jar!/c195/LoginXML.fxml:10
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2583)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at c195.C195.start(C195.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherIm pl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$54/1038706898.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java: 326)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/355629945.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/722855603.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:29 4)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1915503092.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1963387170.run(Unknown Source)
... 1 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name C195/MessageBundle_en_US, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:845)
at c195.LogInController.<init>(LogInController.java:69)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI mpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorA ccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.ja va:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
... 22 more
Exception running application c195.C195
Java Result: -1073741819
Deleting directory C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\run302791547
jfxsa-run:
BUILD SUCCESSFUL (total time: 5 seconds)
Here is the updated stack trace after following your advice.
ant -f C:\\Users\\Forbes\\Documents\\NetBeansProjects\\C195 jfxsa-run
init:
Deleting: C:\Users\Forbes\Documents\NetBeansProjects\C195\build\built- jar.properties
deps-jar:
Updating property file: C:\Users\Forbes\Documents\NetBeansProjects\C195\build\built-jar.properties
compile:
Deleting directory C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\lib
Copying 1 file to C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\lib
Detected JavaFX Ant API version 1.3
jfx-deployment:
jar:
Copying 13 files to C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\run1318536498
jfx-project-run:
Executing C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\run1318536498\C195.jar using platform C:\Program Files\Java\jdk1.8.0_51\jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.j ava:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav a:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917 )
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImp l.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/1343441044.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/Forbes/Documents/NetBeansProjects/C195/dist/run1318536498/C195.ja r!/c195/LoginXML.fxml:10
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2583)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at c195.C195.start(C195.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherIm pl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$54/1361720784.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java: 326)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/355629945.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/722855603.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:29 4)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1915503092.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1963387170.run(Unknown Source)
... 1 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name MessageBundle_en_US, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:845)
at c195.LogInController.<init>(LogInController.java:70)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI mpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorA ccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.ja va:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
... 22 more
Exception running application c195.C195
Java Result: -1073741819
Deleting directory C:\Users\Forbes\Documents\NetBeansProjects\C195\dist\run1318536498
jfxsa-run:
BUILD SUCCESSFUL (total time: 5 seconds)

RMI server ClassNotFoundException when client makes call

I am trying to make a simple RMI execution engine to run on my local machine so that other java programs can easily run code on a second processor. (In the future this will be expanded to allow more processors).
The server starts up just fine, and the client appears to locate the registry ok, but when it tries to call the execution engine (and passes it a parameter) it causes a ClassNotFoundException.
I recognize that this is similar to many other questions on stack overflow, but as far as I can tell, all the other ones have to do with the client not being able to download the server's classes rather than the server not being able to download the client's classes.
Here is my code (copied almost exactly from this sample code):
RMIServer eclipse project
ComputeEngine Interface:
package interfaces;
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ComputeEngine_IF extends Remote {
/**
* #param task The task object specifying the computation to be performed
* #return
* #throws RemoteException
*/
<T extends Serializable> T compute(TaskWithoutInput<T> task) throws RemoteException;
}
TaskWithoutInput interface:
package interfaces;
import java.io.Serializable;
public interface TaskWithoutInput<T> extends Serializable {
public T compute();
}
ComputeEngine Class:
package server;
import interfaces.ComputeEngine_IF;
import interfaces.TaskWithoutInput;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class ComputeEngine implements ComputeEngine_IF{
public ComputeEngine() {
super();
}
#Override
public <T extends Serializable> T compute(TaskWithoutInput<T> task) throws RemoteException {
return task.compute();
}
public static void main(String[] args) {
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
ComputeEngine_IF engine = new ComputeEngine();
ComputeEngine_IF stub = (ComputeEngine_IF) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.createRegistry(1099);
registry.rebind(name, stub);
System.out.println("Registry bound!");
}
catch (Exception e) {
System.err.println("ComputeEngine exception:");
e.printStackTrace();
}
}
}
RMIClient eclipse project
GetAnswerTask class
package client;
import interfaces.TaskWithoutInput;
public class GetAnswerTask implements TaskWithoutInput<Integer> {
private static final long serialVersionUID = 1L;
#Override
public Integer compute() {
return Integer.valueOf(42);
}
}
Client class
package client;
import interfaces.ComputeEngine_IF;
import interfaces.TaskWithoutInput;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class RmiClientExample {
public static void main(String args[]) {
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
Registry registry = LocateRegistry.getRegistry("localhost");
ComputeEngine_IF comp = (ComputeEngine_IF) registry.lookup(name);
TaskWithoutInput<Integer> getAnswer = new GetAnswerTask();
Integer answer = comp.compute(getAnswer);
System.out.println("Answer: " + answer);
}
catch (Exception e) {
System.err.println("RmiClientExample exception:");
e.printStackTrace();
}
}
}
Both projects contain an identical security policy file (in RMIServer it is called server.policy and in RMIClient it is called client.policy)
grant {
permission java.security.AllPermission;
};
I will, of course, restrict the permissions more once I get this working.
Building/Running
Since the code is pretty close to something I copied out of an example, my guess is that the code is right, or at least close, but that my mistake is in compiling/running the code. The example wasn't written for eclipse, so I don't have exact instructions.
The first thing I did was use eclipse's jar export wizard to jar the interface package into Interfaces.jar which I just placed in my RMIServer folder.
Then I run ComputeEngine with the following defines:
-Djava.rmi.server.codebase=file:/c:/Users/nate/workspace/RMIServer/Interfaces.jar
-Djava.rmi.server.hostname=localhost
-Djava.security.policy=c:/Users/nate/workspace/RMIServer/src/server.policy
The compute engine seems to run just find and outputs the print statement in the code.
I then run the client with the defines:
-Djava.rmi.server.codebase=file:/c:/Users/nate/workspace/RMIClient/bin/
-Djava.security.policy=c:/Users/nate/workspace/RMIClient/src/client.policy
And I get the following error message:
RmiClientExample exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: client.GetAnswerTask
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy0.compute(Unknown Source)
at client.RmiClientExample.main(RmiClientExample.java:24)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: client.GetAnswerTask
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: client.GetAnswerTask
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler$Loader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClassForName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
at sun.rmi.server.UnicastServerRef.unmarshalParametersUnchecked(Unknown Source)
at sun.rmi.server.UnicastServerRef.unmarshalParameters(Unknown Source)
... 13 more
Any thoughts on what I might be doing wrong?
GetAnswerTask implements Serializable, so it will be serialized to the server when you call ComputeEngine_IF.compute(). So GetAnswerTask needs to be available at the server, on its classpath, and it isn't.
For those still struggling with oracle RMI tutorial, whose server doesn't download serializable class from given client's codebase (and stubbornly seeks class in its own codebase) - try to add
-Djava.rmi.server.useCodebaseOnly=false
to server's arguments

Getting ClassNotFoundException while using Class.forName("com.actitime5.Testcases."+vriable);

I've been messing around with ClassLoaders in java recently, trying to run my automation script code which uses dynamic loading of classes and geting ClassNotFoundException.
##MyCode
package com.actitime5.frameworkengine;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import com.gmail5.Testcases.LoginLogout;
import org.junit.runner.JUnitCore;
public class Init {
public static void main(String args[]) throws Exception
{
Init in=new Init();
String url=in.getConfigValue("url");
ExcelLibrary lib=new ExcelLibrary();
JUnitCore core = new JUnitCore();
int numberofTestcases=lib.getRowCont("Scenario");
System.out.println(numberofTestcases);
for(int i=1;i<=numberofTestcases;i++)
{String status=lib.getExcelData("Scenario", i, 1);
if(status.equals("yes"))
{String scriptnam=lib.getExcelData("Scenario", i, 0);
System.out.println("Sheet Name"+" "+scriptnam);
Class scriptToRun= Class.forName("com.gmail5.Testcases."+scriptnam);
core.run(scriptToRun);
}
}}
##Errors that i am getting :
1
Sheet Name LoginLogout
Exception in thread "main" java.lang.ClassNotFoundException:com.gmail5.Testcases.LoginLogout
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.gmail5.frameworkengine.Init.main(Init.java:24)
The class which I am trying to load is available in package: com.gmail5.Testcases.*;,but still it throws exception
I think your class name has trailing whitespace. Try trim()ming it off before attempting to load the class.
You can confirm this by replacing
System.out.println("Sheet Name"+" "+scriptnam);
with
System.out.println("Sheet Name"+" '"+scriptnam+"'");
I expect this will print out something like the following:
Sheet Name 'LoginLogout '
When I clicked 'edit' to edit your question, I could see there was trailing whitespace after the class name in the stack trace and in your Sheet Name message. (I didn't change anything in your question: I just used the Edit function to see the raw text of your question, and then clicked Cancel.)

Categories