New_JMap = Put(New_JMap:w_key:w_value) ; (3rd free rpg
statement)
I'm attaching source code .
Any help is really appreciated.
Cheers
Giovanni
hdftactgrp(*no) ACTGRP(*CALLER)
THREAD(*SERIALIZE)
d Jmap pr
o
d
EXTPROC(*JAVA:
d
'java.util.HashMap':
d
*CONSTRUCTOR)
d
CLASS(*JAVA:'java.util.HashMap')
d Put pr
o
d
EXTPROC(*JAVA:
d
'java.util.HashMap'
d :'put')
d
CLASS(*JAVA:'java.util.HashMap')
d key
like(JObject)
d value
like(JObject)
d*
d NewString pr o
EXTPROC(*JAVA:
d
'java.lang.String':
d
*CONSTRUCTOR)
d
CLASS(*JAVA:'java.lang.String')
d Jva_Bytes 65000 CONST VARYING
d JObject s o CLASS(*JAVA:'java.lang.Object')
d w_Key s like(JObject)
d w_value s like(JObject)
d New_Jmap s like(Jmap)
d*
c*****************************************************************
c* M A I N *
c*****************************************************************
c*
/free
w_key = NewString('p01') ;
w_value= NewString('AAAA') ;
New_JMap = Put(New_JMap:w_key:w_value) ;
w_key = NewString('p02') ;
w_value= NewString('BBBB') ;
New_JMap = Put(New_JMap:w_key:w_value) ;
/end-free
c eval *inlr = *on
d New_Jmap s like(Jmap)
tells us that New_Jmap is of type procedure, while to pass it as the 1st
argument of put procedure should be:
d New_Jmap s o CLASS(*JAVA:'java.util.HashMap')
or something like:
d HashMap s o CLASS(*JAVA:'java.util.HashMap')
d New_Jmap s like(HashMap)
so you should code:
d old_Key s like(JObject)
/free
New_JMap = Jmap;
old_key = Put(New_JMap:w_key:w_value) ;
Accordingly to HashTable javadoc put() method returns the previous value
of the specified key in the hashtable, if New_JMap was empty, old_key
should be *NULL
--
Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñejoAlcoolInside
Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'
Ugo,
thanks for your help.
I changed the code as per your suggestions but I still get the same
error message
I'm trying to populate the hashtable first with "put" method. I've got
the error message while adding new values to the hashtable itself.
Error message RNQ0301 :
Messaggio . . . : Ricevuta eccezione Java nel richiamo del metodo
Java (C G
D
F).
Causa . . . . . : La procedura RPG JVACALLGIS nel
programma
TEST/JVACALLGIS ha ricevuto un'eccezione
Java
"java.lang.NoSuchMethodError: put" nel richiamo al metodo "put" con
firma
"(Ljava.lang.Object;Ljava.lang.Object;)Ljava.util.HashMap;" nella
classe
"java.util.HashMap".
Here's my source code changed as suggested:
hdftactgrp(*no) ACTGRP(*CALLER)
THREAD(*SERIALIZE)
d Jmap pr
o
d
EXTPROC(*JAVA:
d
'java.util.HashMap':
d
*CONSTRUCTOR)
d
CLASS(*JAVA:'java.util.HashMap')
d Putm pr
d New_Jmap s o CLASS(*JAVA:'java.util.HashMap')
c*
/free
w_key = NewString('001') ;
w_value= NewString('AAAA') ;
New_JMap = JMap ;
New_JMap = Putm(New_JMap:w_key:w_value) ;
Putm(New_JMap:w_key:w_value) ;
/end-free
c eval *inlr = *on
Both "New_JMap = Putm(New_JMap:w_key:w_value) ; " and
"Putm(New_JMap:w_key:w_value) ; " receive exception error RNQ0301.
Cheers
Giovanni
Your declaration has indeed the wrong return type of java.util.HashMap,
as the java exception stated, it should be:
d Putm pr o CLASS(*JAVA:'java.lang.Object')
--- or ---
d Putm pr o like(JObject)
d EXTPROC(*JAVA:'java.util.HashMap':'put')
d key like(JObject)
d value like(JObject)
Sorry, I didn't recognize it due to the fact that RPG code was scrambled
in yesterday post.
Just for reference about how to understand java signature for JNI:
http://www.rgagnon.com/javadetails/java-0286.html
or look at JNI from Sun source.
If you want to know the signature of some java class you can use javap
utility provided by JDK, available in QSH too. For example:
javap -s -public java.util.HashMap
will output signature of all members with public modifier of HashMap
class, you'll see that the signature:
public java.lang.Object put(java.lang.Object, java.lang.Object);
Signature: (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
is different from what reported by RNQ0301,
Ugo,
I changed the code and now "put" method works fine .
Thanks for your help.
Giovanni
0001.00 hdftactgrp(*no) ACTGRP(*CALLER)
THREAD(*SERIALIZE)
0002.00 d Jmap pr
o
0003.00 d
EXTPROC(*JAVA:
0004.00 d
'java.util.HashMap':
0005.00 d
*CONSTRUCTOR)
0006.00 d
CLASS(*JAVA:'java.util.HashMap')
0007.00 d Putm pr
like(Jobject)
0008.00 d
EXTPROC(*JAVA:
0009.00 d
'java.util.HashMap'
0010.00
d :'put')
0011.00 d keym
like(JObject)
0012.00 d valuem
like(JObject)
0013.00
d*
0014.00 d Getm pr
like(Jobject)
0015.00 d
EXTPROC(*JAVA:
0016.00 d
'java.util.HashMap'
0017.00
d :'get')
0018.00 d keyp
like(JObject)
0019.00
d*
0020.00 d NewString pr o
EXTPROC(*JAVA:
0021.00 d
'java.lang.String':
0022.00 d
*CONSTRUCTOR)
0023.00 d
CLASS(*JAVA:'java.lang.String')
0024.00 d Jva_Bytes 65000 CONST
VARYING
0025.00
d*
0026.00 d getBytes pr 10a
EXTPROC(*JAVA:
0027.00 d
'java.lang.String':
0028.00 d 'getBytes')
VARYING
0029.00 d Jva_String s o
CLASS(*JAVA:'java.lang.String')
0030.00
d*
0031.00 d JObject s o
CLASS(*JAVA:'java.lang.Object')
0032.00 d Old_key s
like(JObject)
0033.00 d w_key s
like(JObject)
0034.00 d w_value s
like(JObject)
0035.00 d J_key s
like(JObject)
0036.00 d New_JMap s o
CLASS(*JAVA:'java.util.HashMap')
0037.00 d w_String s 256 inz
varying
0038.00 c*
0039.00 /free
0040.00 New_JMap = JMap ;
0041.00 w_key = NewString('001') ;
0042.00 w_value= NewString('AAAA') ;
0043.00 Putm(New_JMap:w_key:w_value) ;
0044.00 w_key = NewString('002') ;
0045.00 w_value= NewString('BBBB') ;
0045.01 Putm(New_JMap:w_key:w_value) ;
0046.00 w_key = NewString('003') ;
0047.00 w_value= NewString('CCCC') ;
0048.00 Putm(New_JMap:w_key:w_value) ;
0049.00 J_key = NewString('002') ;
0050.00 Old_Key = Getm(New_JMap:J_key) ;
0051.00 Jva_String = Old_Key ;
0052.00 w_string = getbytes(Jva_string) ;
0053.00 /end-free
0054.00 c eval *inlr = *on
LIKE(prototypeName) defines the new variable like the _return_type_ of
the procedure, so Henry's definition using LIKE is the same as your
explicit definition.
Giovanni's code was:
New_JMap = Put(New_JMap:w_key:w_value) ;
while put(Object key, Object value) method returns a java.lang.Object,
not a java.util.HashMap, in other words returns the Object reference of
the value that was associated to the key before the put of a new
different value. Infact the signature reported by the message was
(Ljava.lang.Object;Ljava.lang.Object;)Ljava.util.HashMap;