Java NullPointerException when using Evaluation.areaUnderROC from Weka - java

So I'm trying to evaluate the performance of a classifier on a test instance and when I try to get the area under the ROC, the following error is thrown:
Java.lang.NullPointerException
at weka.classifiers.evaluation.ThresholdCurve.getROCArea(ThresholdCurve.java:268)
at weka.classifiers.Evaluation.areaUnderROC(Evaluation.java:382)
at Classifier_Search.runAda(Classifier_Search.java:74)
at Classifier_Search.acrossTest(Classifier_Search.java:142)
at Classifier_Search.main(Classifier_Search.java:511)
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:271)
The code that is throwing the error is this:
Evaluation eval = new Evaluation(train);
String[] options = {"-P 100", "-S 1", "-I " + it, "-W weka.classifiers.trees.DecisionStump"};
AdaBoostM1 cls = new AdaBoostM1();
cls.setOptions(options);
cls.buildClassifier(train);
eval.evaluateModel(cls, test);
int index = test.classIndex();
return eval.areaUnderROC(index);
When I look up the javadoc for Evaluation (javadoc for Evaluation), It says that areaUnderROC needs to be set by an evaluateClassifier method. No such method exists. Other similar methods (such as falsePositive) work just fine. Has anyone encountered this problem? I can't find anything on OldNabble (Weka's help site).
Thanks!
EDIT: to clarify, test and train are both Instances objects that were created with the following code:
private static Instances readFile(File filename) throws IOException
{
CSVLoader loader = new CSVLoader();
loader.setSource(filename);
Instances data = loader.getDataSet();
data.setClassIndex(data.numAttributes() - 1);
return data;
}
They are read from .csv files. Typically if there is something wrong with test or train, the error is thrown here.

Once again, I have the answer to my own question. If someone disagrees with this answer, please let me know. The weka documentation for areaUnderROC, which already has one typo (it references a method, evaluateClassifier, which does not exist), has led me in the wrong direction. I think there is another error in the form of a misleading explanation. areaUnderROC works (without throwing the exception) for two values: 0 and 1. So, rather than taking the class index (the index of the attribute I am using as the class in the Instances object), what it actually wants is which class (of the two classes) to consider as positive. Given the variable names in the documentation, I think it's reasonable to not understand this at first glance. I also think that since its explanation is in parallel with that of methods that do take the class index (rather than 0 or 1), it is also misleading.

Related

Uncatchable exception thrown by calling Stage.show()

Edit: I was lucky enough that James_D quickly identified and explained this phenomenon in his comments below. Having now found the alternative to the use of PropertyValueFactory (for Groovy users) I thought I'd add my own answer to help anyone unlucky enough to be flummoxed by this in future.
Specs Java: 11. OS: Linux Mint 18.3.
All this app and testing code is written in Groovy (2.5.10), but this shouldn't be particularly relevant (i.e. the same phenomenon should occur with an equivalent project written in Java).
I have a method called from App.start() where App extends javafx.application.Application (so it is running in the JAT/JavaFX Application Thread):
class GraphBuilder {
...
def attachAndShow(Stage stage, Node rootNode) {
try {
App.instance.fxmlController.treeTableView.root = rootTreeItem
App.instance.fxmlController.treeTableView.showRoot = false
stage.scene = new Scene(rootNode, 1200, 800)
stage.show()
}catch( Throwable t ){
log.error( "got throwable in attachAndShow... $t.message", t )
}
}
I am TDD'ing my way forward on the model of a "spike" (untested code where I just raced ahead) where the TreeTableView gets populated. I emphasise that there is no sign any anything being amiss with the spike.
Intrinsic to doing this is to set the TreeTableView's columns "cell value factories", which stipulate the name of a field of the class instances of which will be set as the value of the TreeItems.
The value class is called Task... and its first field is String title. I've added a first factory for this. But (because I'm proceeding by TDD) I have added the factory for the second column, property dueDate, but I haven't yet included this field in Task. Naturally the test to make sure that a factory has been set, with the right property name, is failing. But I'm more interested in what happens when I do a Gradle installDist (i.e. distribute a self-contained executable) at this point.
This runs: the window is displayed. I can see that the TreeItems have been given the right titles. In the Terminal I see a stack trace caused by my failure to include a required field (dueDate) in the Task instances:
Mar 23, 2020 6:16:25 PM javafx.scene.control.cell.TreeItemPropertyValueFactory getCellDataReflectively
WARNING: Can not retrieve property 'dueDate' in TreeItemPropertyValueFactory: javafx.scene.control.cell.TreeItemPropertyValueFactory#2d1e69d0 with provided class type: class core.Task
java.lang.IllegalStateException: Cannot get property dueDate
at com.sun.javafx.property.PropertyReference.getProperty(PropertyReference.java:194)
at javafx.scene.control.cell.TreeItemPropertyValueFactory.getCellDataReflectively(TreeItemPropertyValueFactory.java:185)
at javafx.scene.control.cell.TreeItemPropertyValueFactory.call(TreeItemPropertyValueFactory.java:158)
at javafx.scene.control.cell.TreeItemPropertyValueFactory.call(TreeItemPropertyValueFactory.java:136)
at javafx.scene.control.TreeTableColumn.getCellObservableValue(TreeTableColumn.java:576)
at javafx.scene.control.TreeTableColumn.getCellObservableValue(TreeTableColumn.java:561)
at javafx.scene.control.TreeTableCell.updateItem(TreeTableCell.java:632)
at javafx.scene.control.TreeTableCell.indexChanged(TreeTableCell.java:457)
at javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)
at javafx.scene.control.skin.TableRowSkinBase.updateCells(TableRowSkinBase.java:539)
at javafx.scene.control.skin.TreeTableRowSkin.updateCells(TreeTableRowSkin.java:276)
at javafx.scene.control.skin.TableRowSkinBase.<init>(TableRowSkinBase.java:159)
at javafx.scene.control.skin.TreeTableRowSkin.<init>(TreeTableRowSkin.java:102)
at javafx.scene.control.TreeTableRow.createDefaultSkin(TreeTableRow.java:529)
at javafx.scene.control.Control.doProcessCSS(Control.java:897)
at javafx.scene.control.Control.access$000(Control.java:83)
at javafx.scene.control.Control$1.doProcessCSS(Control.java:89)
at com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)
at com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:145)
at javafx.scene.Node.processCSS(Node.java:9529)
at javafx.scene.Node.applyCss(Node.java:9616)
at javafx.scene.control.skin.VirtualFlow.setCellIndex(VirtualFlow.java:1715)
at javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1692)
at javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1801)
at javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2639)
at javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1245)
at javafx.scene.Parent.layout(Parent.java:1204)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Scene.doLayoutPass(Scene.java:576)
at javafx.scene.Scene.preferredSize(Scene.java:1748)
at javafx.scene.Scene$2.preferredSize(Scene.java:393)
at com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
at javafx.stage.Window$12.invalidated(Window.java:1086)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
at javafx.stage.Window.setShowing(Window.java:1174)
at javafx.stage.Window.show(Window.java:1189)
at javafx.stage.Stage.show(Stage.java:273)
at javafx.stage.Stage$show.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
at core.GraphBuilder.attachAndShow(main.groovy:111)
at core.GraphBuilder$attachAndShow$4.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)
at core.App.start(main.groovy:56)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:834)
This Throwable (IllegalState is a RuntimeException) doesn't get caught in the above try ... catch. Why not? Is there any way to catch such exceptions?
This certainly appears to be the JAT: you can see App.start() in that stack trace (and also GraphBuilder.attachAndShow())
I just performed a couple of experiments: throwing first a RuntimeException and then a standard Exception in this attachAndShow() method, before any of the 4 lines in the method.
In both cases the (distributed) application failed to run, and displayed nothing... but the log message was indeed logged, i.e. these were both caught. Totally expected behaviour, so it appears that the JAT itself is not the "culprit".
I also note that the trace shown above is not a "normal" stack trace: the first two lines indicate that something is handling it and, it appears, rather unfortunately swallowing it. At the very least I'd like to be able to log such problems!
The basic answer is here.
Groovy users can smugly slice through the vast forest of pointy brackets though: my solution became:
fxmlController.treeTableView.columns.get( 0 ).cellValueFactory =
new Callback() {
#Override
Binding call(Object cellDataFeatures ) {
// NB it turns out that the first "value" is a TreeItem
Task task = cellDataFeatures.value.value
Bindings.createStringBinding({ task.title })
}
}
or stick some minimal ones in maybe:
fxmlController.treeTableView.columns.get( 0 ).cellValueFactory =
new Callback<TreeTableColumn.CellDataFeatures, ObservableValue>() {
#Override
Binding call(TreeTableColumn.CellDataFeatures cellDataFeatures ) {
Task task = cellDataFeatures.value.value
Bindings.createStringBinding({ task.title })
}
}
For the Groovy "Java lambda" substitute, no surprise that we use a closure:
fxmlController.treeTableView.columns.get( 0 ).cellValueFactory
= { cellDataFeatures -> cellDataFeatures.value.titleProperty() }
NB this involves a little understanding of JavaFX Property (see here) and a little tailoring of the class whose instances are displayed.

Why doesn't printStackTrace work in Clojure?

In both the Joy of Clojure and on Alex Miller's Pure Danger Tech blog-post it is recommended that you can print the last stack using something like the following:
(use 'clojure.stacktrace)
(java.util.Date. "foo")
(.printStackTrace *e 5)
But I can't get any of their examples to work, and instead just get
java.lang.NullPointerException: null
Reflector.java:26 clojure.lang.Reflector.invokeInstanceMethod
(Unknown Source) jtown$eval9755.invoke
What's up with this? .printStackTrace seems to be a Java function from the looks of it, so I am not sure why I am bringing clojure.stacktrace into my namespace, in the first place. I read through the clojure.stacktrace API, though, and see an e function, which seems similar too but is not the *e function, which is in core and is supposed to be binding to the last exception, but isn't. Could somebody straighten me out on the best way to check stack-traces?
There are some special vars available when using the REPL and
*e - holds the result of the last exception.
For instance:
core=> (java.util.Date. "foo")
IllegalArgumentException java.util.Date.parse (Date.java:615)
core=> (class *e)
java.lang.IllegalArgumentException
core=> (.printStackTrace *e)
java.lang.IllegalArgumentException
at java.util.Date.parse(Date.java:615)
<not included.....>
You are right, .printStackTrace is the java method that is invoked on the exception class. This is not very straightforward (since its java interop) so clojure.stacktrace namespace has some utilities about working with stack traces
So after
(use 'clojure.stacktrace)
you can use the stacktrace library instead of java interop:
core=> (print-stack-trace *e)
java.lang.IllegalArgumentException: null
at java.util.Date.parse (Date.java:615)
<not included.....>
Obviously in an app, instead of *e, you can do a try - catch and use the related functions as necessary
I use
(.printStackTrace *e *out*)
That seems to work.

Velocity - NullPointerException

During my searching, I would like to have some help about my problem :
So this is my error, the trace :
VelocityView : Error processing a template for path '/comptes/affilies.html.vtl'
Invocation of method 'getRemunerationVendeur' in class model.User threw exception java.lang.NullPointerException at /comptes/affilies.html.vtl[line 28, column 20]
java.lang.NullPointerException
at model.User.getListRemunerationVendeur(User.java:238)
at model.User.getRemunerationVendeur(User.java:268)
at sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.velocity.runtime.parser.node.PropertyExecutor.execute(PropertyExecutor.java:127)
at org.apache.velocity.util.introspection.UberspectImpl$VelGetterImpl.invoke(UberspectImpl.java:523)
at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:198)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:271)
at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:561)
at org.apache.velocity.runtime.directive.VelocimacroProxy.handleArgValues(VelocimacroProxy.java:325)
at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:189)
at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:300)
at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:230)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at org.apache.velocity.runtime.directive.Foreach.renderBlock(Foreach.java:281)
at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:258)
at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
at org.apache.velocity.Template.merge(Template.java:356)
at org.apache.velocity.Template.merge(Template.java:260)
at org.apache.velocity.tools.view.VelocityView.performMerge(VelocityView.java:942)
at org.apache.velocity.tools.view.VelocityView.merge(VelocityView.java:902)
at org.apache.velocity.tools.view.VelocityViewServlet.mergeTemplate(VelocityViewServlet.java:318)
at org.apache.velocity.tools.view.VelocityViewServlet.doRequest(VelocityViewServlet.java:220)
at org.apache.velocity.tools.view.VelocityViewServlet.doGet(VelocityViewServlet.java:182)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
at filter.AuthFilter.doRedirect(AuthFilter.java:54)
at velosurf.web.auth.AuthenticationFilter.doFilter(AuthenticationFilter.java:392)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
at filter.DateFilter.doFilter(DateFilter.java:309)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1345)
at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1301)
at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1285)
at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1193)
at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:992)
at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
Normally the class User.java works.
This is a piece of my class java (User.java) that corresponds to my error :
Instance service = (Instance)db.get("service_by_code");
vendeur.put("ope_code", operateur.get("ope_code"));
vendeur.put("srv_code", service.get("srv_code"));
My variable service corresponds at a line of a result at my database.
I think my row is NULL in the database (because a nullPointerException is mainly that ... an object set at NULL !) but I don't know to solve the problem in my database : to change value in the row of my database.
I try it but It changes nothing.
Please if you've got a piece of advice.
Ale.
It looks, like your object of class Instance is NULL, because of your work with DB.
Anyway, should be nice, if you give a stacktrace of your exception, so nobody will try to guess.

java.lang.ClassCastException socket readObject

Hi guys I am getting this problem on my console, but only appear sometimes.. not always..
I would like your help if possible, thanks
Error:
Exception in thread "Thread-2" java.lang.ClassCastException: cannot assign instance of java.lang.String to field Element.posElement of type java.awt.Point in instance of Personagem
at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(Unknown Source)
at java.io.ObjectStreamClass.setObjFieldValues(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at LaunchCliente$receberDoServidor.run(LaunchCliente.java:332)
and here is my code, when I am trying to read the object :
Object a = inputStream.readObject();
if(a instanceof Mapa){
Mapa novo = (Mapa) a;
if(launchJogo.getListaObstaculos().size() == 0)
launchJogo.setLista(novo.getListaObstaculos());
launchJogo.setListaPers(novo.getListaPersonagens());
launchJogo.setElements(novo.getElements());
launchJogo.getFrame().pack();
}
else if(a instanceof logout){
if(launchJogo != null)
launchJogo.getFrame().dispose();
novo.close();
}
else if(a instanceof updateList){
Vector<String> novo = ((updateList) a).getUpdateList();
if(novo.size() != 0){
if(!nomeUtilizador.isEnabled()){
modeloDaLista.clear();
arrayDeJogos = new Vector<String>(novo);
for (String x : arrayDeJogos) {
modeloDaLista.addElement(x);
}
janela.validate();
}
}
if(novo.size() == 0){
modeloDaLista.clear();
}
}
else if(a instanceof String){
String b = a.toString();
if(b.equals("COLOR:FALSE")){
JOptionPane.showMessageDialog(c, "Essa cor já está em uso no jogo selecionado!" , "Cor já escolhida!",
JOptionPane.WARNING_MESSAGE);
launchJogo = null;
cores.dispose();
janela.setVisible(true);
}
else if(b.equals("CREATE:BUTTONSTART")){
launchJogo.getOptions().showButton(true);
}
else if(b.equals("ACTIVE:BUTTONSTART")){
if(!launchJogo.getOptions().isButtonEnabled()){
launchJogo.getOptions().setBotaoState(true);
}
}
else if(b.equals("COLOR:TRUE")){
cores.dispose();
out.writeObject(new addToAGame(corDoJogador, nomeJogador, jogoSelecionado));
launchJogo = new LaunchJogo(launchCliente, jogoSelecionado, nomeJogador);
}
else if(b.equals("LAUNCH:GAME")){
if(launchJogo != null)
launchJogo.addPersonagemListener();
}
}
} catch (ClassNotFoundException e) {
System.out.println("Class not found!");
} catch (IOException e) {
this.interrupt();
}
Thanks alot in advance guys, I would appreciate some help
The error message is telling you that the object stream is encountering a runtime error while rebuilding a serialized object. The object state being deserialized has a String for a value of the field Element.posElement ... which ought to be a Point according to the version of the Element class that your application is using.
The problem is with the actual serialized objects that you are attempting to read. I suspect that some time in the past you have changed the type of the Element.posElement field from String to Point (or vice versa), and you are trying to deserialize an object created by the other version of the class to the one you are currently using.
Normally, the object reader would complain about incompatible versions, but I suspect that you have:
- added serialVersionId constants to your classes, and
- failed to update the serialVersionId for Element after making a change that makes the new version incompatible with the old one.
Another possibility (see #TInusTate's comment) is that there are multiple threads writing to a shared ObjectOutputStream instance without synchronizing properly. This can result in the bytes from different objects getting "mixed up".
You could get a similar effect if you did other things like:
Multiple ObjectOutputStream instances wrapping a shared OutputStream.
Multiple threads reading from the same ObjectInputStream.
In some cases, the solution is proper synchronization. In others, the problem is intractable. None of the stream classes are inherently thread-safe, and multiple threads multiplexing data over a single stream is a difficult problem, requiring considerable care.
You are going to need to find where these incompatible serialized objects are coming from and either get rid of them or (somehow) replace them. In the future, you need to be more careful whan making changes to classes that may have been serialized and persisted, etcetera.
(This kind of problem is one of the reasons why ObjectStream serialization can be problematic for persisting state.)
The error is quite obvious.
cannot assign instance of java.lang.String
to field Element.posElement of type java.awt.Point
At the point where the error occurs, you are trying to assign a String where a "awt.Point" is exspected.
The bad thing is that I'm not sure of the problem is in the code you pasted.
Check line 332 of LaunchCliente.java.
You should be able to debug the issue and figure out which line it is.
First few points
You don't have "a instance of Persongem"
You are not capturing ClassCastException. May be capture it with as much information as you can.
The problem is with the Serialized version of your class only. It has definitely been changed at least once for at least one data (data/row in lose terms).
Thread does complicate the stuff. Have a test around it.
Resolution: The thing you can do is identify the data. alienate/correct/log and fail safely in such case.

Trouble using java class within jruby

I'm trying to use Java Opencl from within jruby, but am encountering a problem which I can't solve, even with much google searching.
require 'java'
require 'JOCL-0.1.7.jar'
platforms = org.jocl.cl_platform_id.new
puts platforms.class
org.jocl.CL.clGetPlatformIDs(1, platforms, nil)
when I run this code using: jruby test.rb
I get the following error, when the last line is uncommented:
#<Class:0x10191777e>
TypeError: cannot convert instance of class org.jruby.java.proxies.ConcreteJavaP
roxy to class [Lorg.jocl.cl_platform_id;
LukeTest at test.rb:29
(root) at test.rb:4
Just wondering whether anyone has an idea on how to solve this problem?
EDIT:
ok so I think I've solved the first part of this problem by making platforms an array:
platforms = org.jocl.cl_platform_id[1].new
but that led to this error when adding the next couple of lines:
context_properties = org.jocl.cl_context_properties.new()
context_properties.addProperty(org.jocl.CL::CL_CONTEXT_PLATFORM, platforms[0])
CodegenUtils.java:98:in `human': java.lang.NullPointerException
from CodegenUtils.java:152:in `prettyParams'
from CallableSelector.java:462:in `argumentError'
from CallableSelector.java:436:in `argTypesDoNotMatch'
from RubyToJavaInvoker.java:248:in `findCallableArityTwo'
from InstanceMethodInvoker.java:66:in `call'
from CachingCallSite.java:332:in `cacheAndCall'
from CachingCallSite.java:203:in `call'
from test.rb:36:in `module__0$RUBY$LukeTest'
from test.rb:-1:in `module__0$RUBY$LukeTest'
from test.rb:4:in `__file__'
from test.rb:-1:in `load'
from Ruby.java:679:in `runScript'
from Ruby.java:672:in `runScript'
from Ruby.java:579:in `runNormally'
from Ruby.java:428:in `runFromMain'
from Main.java:278:in `doRunFromMain'
from Main.java:198:in `internalRun'
from Main.java:164:in `run'
from Main.java:148:in `run'
from Main.java:128:in `main'
for some reason when I print the class of platforms[0] it's listed as NilClass!?
You are overlooking a very simple mistake. You write
platforms = org.jocl.cl_platform_id.new
but that line creates a single instance of the class org.jocl.cl_platform_id. You then pass that as the second parameter to org.jocl.CL.clGetPlatformIDs in
org.jocl.CL.clGetPlatformIDs(1, platforms, nil)
and that doesn't work, because the second argument of the method requires an (empty) array of org.jocl.cl_platform_id objects.
What the error says is: "I have something that is a proxy for a Java object and I can't turn it into an an array of org.jocl.cl_platform_id objects, as you are asking me to do.
If you just say
platforms = []
and pass that in, it might just work :).

Categories

Resources