Error in generating Java Wrapper in Web3j - java
I am trying to generate java Wrapper for a smart contract, but it failed because of this error:
Exception in thread "main" java.lang.IllegalArgumentException: not a valid name: Main.sol:main
at com.squareup.javapoet.Util.checkArgument(Util.java:64)
at com.squareup.javapoet.TypeSpec$Builder.<init>(TypeSpec.java:383)
at com.squareup.javapoet.TypeSpec$Builder.<init>(TypeSpec.java:362)
at com.squareup.javapoet.TypeSpec.classBuilder(TypeSpec.java:90)
at org.web3j.codegen.SolidityFunctionWrapper.createClassBuilder(SolidityFunctionWrapper.java:172)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:103)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:91)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityFunctionWrapperGenerator.java:123)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunctionWrapperGenerator.java:87)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.run(SolidityFunctionWrapperGenerator.java:48)
at org.web3j.console.Runner.main(Runner.java:38)
I followed what this guy said to remove this error
https://github.com/web3j/web3j/issues/16]
and give a default name (letters alphabetically) for each empty property as the following:
[{"constant":true,"inputs":
[{"name”:”a”,”type":"bytes32"}],"name":"ApprovedTAs","outputs":
[{"name":"Trade_id","type":"bytes32"},{"name":"Trade_producer","type":"address"},{"name":"Trade_consumer","type":"address"},{"name":"Trade_rate","type":"uint256"},{"name":"Trade_from","type":"uint256"},{"name":"Trade_to","type":"uint256"},{"name":"Trade_broker","type":"address"},{"name":"Trade_topic","type":"uint256"},{"name":"approvedByA","type":"bool"},{"name":"approvedByB","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”b”,”type":"address"},{"name”:”c”,”type":"uint256"}],"name":"offersByProducer","outputs":[{"name":"offer_id","type":"uint256"},{"name":"offer_producer","type":"address"},{"name":"offer_topic","type":"uint256"},{"name":"offer_rate","type":"uint256"},{"name":"offer_from","type":"uint256"},{"name":"offer_to","type":"uint256"},{"name":"offer_broker","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getAll","outputs":[{"name”:”d”,”type":"address[]"},{"name”:”e”,”type":"address[]"},{"name”:”f”,”type":"address[]"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"mk_producer","type":"address"},{"name":"mk_topic","type":"uint256"},{"name":"mk_rate","type":"uint256"},{"name":"mk_from","type":"uint256"},{"name":"mk_to","type":"uint256"},{"name":"mk_broker","type":"address"}],"name":"mkOrder","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”g”,”type":"uint256"}],"name":"offers","outputs":[{"name":"offer_id","type":"uint256"},{"name":"offer_producer","type":"address"},{"name":"offer_topic","type":"uint256"},{"name":"offer_rate","type":"uint256"},{"name":"offer_from","type":"uint256"},{"name":"offer_to","type":"uint256"},{"name":"offer_broker","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"ofr_topic","type":"uint256"},{"name":"ofr_rate","type":"uint256"},{"name":"ofr_from","type":"uint256"},{"name":"ofr_to","type":"uint256"},{"name":"ofr_broker","type":"address"}],"name":"offer","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”h”,”type":"uint256"},{"name”:”ii”,”type":"uint256"}],"name":"allAdd","outputs":[{"name”:”j”,”type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"sndC_id","type":"bytes32"},{"name":"sndC_producer","type":"address"},{"name":"sndC_broker","type":"address"},{"name":"sndC_topic","type":"uint256"},{"name":"sndC_from","type":"uint256"},{"name":"sndC_to","type":"uint256"},{"name":"sndC_count","type":"uint256"}],"name":"sendCCube","outputs":[{"name”:”l”,”type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"id","type":"bytes32"}],"name":"agreeTA","outputs":[{"name”:”m”,”type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"sndP_id","type":"bytes32"},{"name":"sndP_broker","type":"address"},{"name":"sndP_topic","type":"uint256"},{"name":"sndP_from","type":"uint256"},{"name":"sndP_to","type":"uint256"},{"name":"sndP_count","type":"uint256"}],"name":"sendPCube","outputs":[{"name”:”n”,”type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name”:”o”,”type":"bytes32"}],"name":"CreatedTAs","outputs":[{"name":"Trade_id","type":"bytes32"},{"name":"Trade_producer","type":"address"},{"name":"Trade_consumer","type":"address"},{"name":"Trade_rate","type":"uint256"},{"name":"Trade_from","type":"uint256"},{"name":"Trade_to","type":"uint256"},{"name":"Trade_broker","type":"address"},{"name":"Trade_topic","type":"uint256"},{"name":"approvedByA","type":"bool"},{"name":"approvedByB","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"nkname","type":"string"},{"name":"code","type":"uint256"}],"name":"register","outputs": [{"name”:”p”,”type":"bool"}],"payable":false,"type":"function"}]
But the error still the same. I also changed the name of the contract rather than "main" but nothing change.
I also changed every variable name has numbers, special characters or even starting with _ but still doesn't work.
Any idea what I should change to solve this error
Thanks
This error is triggered if you are declaring a function o event with only the argument type without a name.for example :
event myevent(string)
should be
event myevent(string message);
Related
Getting version mismatch error while updating into DCTM using java
I am trying to update into DCTM through java code, below is the code snippet IDfDocument communication = (IDfDocument) getDfSession().getObject(DfId.valueOf(communicationId)); communication.setString(ATTR_STATUS, status); communication.save(); but I am getting the below error Caused by: DfException:: THREAD: be.ing.ca.xpression.DCTM001P-1; MSG: [DM_OBJ_MGR_E_VERSION_MISMATCH]error: "save of object 090283e589bf689d of type xx_document failed because of version mismatch: old version was 4"; ERRORCODE: 100; NEXT: null I thinki am getting this error because there is another process which is trying to modify the object ,and when more than one process try to modify anyobject DCTM throws this exception, But after lot of searching i dident found any solution which can solve this error If anyone knows the solution please reply.. Link that i refer http://www.javablog.fr/?s=version+mismatch
Try calling a fetch() on the object before doing updates. communication.fetch() There are some optional parameters AFAIK, but it's been a while since I've been fiddling with DCTM. Best of luck!
Alternative for AnyLogic deprecated method getJComponent()?
I recently updated to AnyLogic PLE 8.4.0 and Java SE 12 on my Windows 10 laptop. And now an AnyLogic model that used to work earlier stops with the error "The method getJComponent() is undefined for the type ShapeTextField." I looked it up in AnyLogic/Help and I notice that getJComponent is identified as "Deprecated" and no alternative is identified. It appears to me that some mismatch happened between AnyLogic and Java updates that resulted in this error. I would appreciate any workarounds to get the model working. Tried replacing getJComponent() with the following: by getX() - gave error "cannot cast from double to Jtextfield" by getPresentable() - gave error "cannot cast from Presentable to Jtextfield" by getClass() - gave error "Description: Cannot cast from Class to JTextField." by getComponentGraphics() - gave error "Description: The method getComponentGraphics() is undefined for the type ShapeTextField." by equals - gave error "Description: The method equals(Object) in the type Object is not applicable for the arguments ()." The code is: ((JTextField)(editbox.getJComponent())).setHorizontalAlignment(JTextField.LEFT); This is defined in Simulation - Simulation Experiment / Java Actions/ Initial Experiment Setup field Expected result: No error message. And the model should proceed to run window.
Thanks to the inputs from #Benjamin and #Felipe the following worked: I replaced the editbox and buttons with corresponding artifacts from AL8.4 palette. I copied the code from the earlier artifacts to corresponding fields in the new artifacts. I deleted the artifacts that were from AL7. I commented out the line that was meant to align the editbox since that capability is not available anymore. With the above two changes I didn't get the error message about undefined method. The editbox and buttons worked and allowed me to enter XML filename and reading it with an XML parser routine. I have now run into issue with JAXB integration with AL8.4 and haven't been able to get past that yet. I will be posting that as a separate question.
Why does Java 8's Nashorn engine in strict mode throw a java.lang.ClassCastException when calling apply() and passing the arguments object directly?
When I call eval (in strict mode) on a nashorn engine with the following script I get an exception: var yfunc = function () { (null).apply(null, arguments); }; yfunc(); I've truncated my personal situation heavily. The "(null)" on line 2 can be replaced with anything between parenthesis or a local variable, either way just something that shouldn't throw a compile error, and it will yield the same result. The issue seems to be explicitly that "arguments" is passed directly as the second argument of calling a method called "apply". Any of the following changes will undo the thrown exception: Putting "arguments" in a variable first (but simply wrapping it in parenthesis doesn't work!) Calling something other than apply Passing "arguments" in a different argument slot when calling apply Calling print() (with or without passing any arguments) as a preceding line of code inside yfunc() (weird huh?) Defining more than 0 parameters for yfunc() Binding yfunc first and then calling the bound method Calling yfunc via Function.apply (not so much with Function.call!) The Exception thrown is this: Exception in thread "main" java.lang.ClassCastException: Cannot cast jdk.nashorn.internal.runtime.Undefined to jdk.nashorn.internal.runtime.ScriptFunction at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361) at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356) at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(<eval>:4) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) When I call this method with an owner, the exception thrown changes. Example code: var yfunc = { method: function () { (null).apply(null, arguments); } }; var x = yfunc.method(); Then the thrown exception looks like this: Exception in thread "main" java.lang.ClassCastException: Cannot cast jdk.nashorn.internal.scripts.JO4 to jdk.nashorn.internal.runtime.ScriptFunction at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361) at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356) at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(<eval>:5) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) I've reproduced the issue so far on specifically these environments: windows 7 64bit -> jdk 1.8.0_60 64bit windows 8 64bit -> jdk 1.8.0_131 64bit I can't seem to find anything on the internet about similar issues. Do I need to report this to Oracle/OpenJDK? Minor update Added items 6 and 7 to list of "following changes will undo the thrown exception". Final update Bug filed: JDK-8184720
Yes, it appears to be a bug. Please file a bug.
jGroups jar giving Exception
We have a legacy project and we are using jgroups-all 2.2.9.1 jar. We are facing a issue from the past few days where our server crashes giving following exception : java.lang.IllegalArgumentException: timeout value is negative at java.lang.Object.wait(Native Method) at org.jgroups.protocols.ring.UdpRingNode.receiveToken(UdpRingNode.java:59) at org.jgroups.protocols.TOTAL_TOKEN$TokenTransmitter.run(TOTAL_TOKEN.java:1116) we think this is occuring due to the old jgroups jar we are using.but then if we upgrade the jar file there is another problem.The new jar has removed the sub package ring(org.jgroups.protocol.ring) from package protocol. So my question is how should we proceed ?. if i will have to change the implementation of udpring then what should i use instead?.
The exception tells the entire story : java.lang.IllegalArgumentException: timeout value is negative There must be a call to method that expects a positive value for its argument and you may be giving a negative value to it, so it throws an exception. Imagine I am having a java.util.Date object, and then I call a method to set the year as java.util.Date d = new java.util.Date(); d.setYear(-123); Then it may throw this kind of exception as I cannot specify negative value for year. So just have check where your code is accessing the jar's code that throws this exception and make a check whether the parameter value passed are of correct value.
Java Exception appends ": null" to "Caused by" clause
There are some exceptions shown as follows in my log: (the text has been modified to conceal project information) java.util.concurrent.ExecutionException:org.xxx.BBBException<br> at ....<br> ...<br> Caused by: org.xxx.BBBException: null<br> at ....<br> ...<br> Why is there "null" in the Caused by clause? BBBException, which was made by us, extends Exception and does not override toString(). In some situations, FutureTask.setException(new BBBException("RPC timed out")) is called and BBBException is being expected in the log. However, the exception's details message is not what we set in the program and the text in the first line and Caused by clause even do not match (there is no ": null" in the first line). Anyone has a clue why this has happened? Thanks! Environment: java 6, update 21, centos 64-bit, java 64-bit, mixed mode.
I suspect you've either actually created a new BBBException without a message, or your BBBException(String) constructor doesn't pass the message up to the super-constructor (which it should, via super(message)). Basically it's saying: this is an exception with no message. It's hard to tell exactly what's wrong without seeing any of your code though.
org.xxx.BBBException: null was thrown with null message (using default constructor). Throw it with some message (if it supports it): throw new BBBException("Danger! High Voltage") If this doesn't work, it means the BBBException(String msg) constructor is poorly written. It should be something like: BBBException(String msg) { super(msg); }