ArrayList of String[] array

66 views
Skip to first unread message

Nitish Gupta

unread,
Jul 21, 2018, 5:00:29 PM7/21/18
to Kivy users support

One of Java function's argument is List<String[]>

jArrayList = autoclass('java.util.ArrayList')   
jString = autoclass('java.lang.String')
words = ['a', 'b', 'c']
javaWords = [jString(w)  for w in words]
arraylist = jArrayList()
arraylist.add(javaWords)

But I get the following JavaException: No methods matching your arguments when I call arraylist.add(javaWords).

What is the solution for this?

Daniel Khashabi

unread,
Jul 21, 2018, 7:18:54 PM7/21/18
to Kivy users support
Your `javaWords` variable is a Python-List. And of course, a Java ArrayList.add(.) won't be able to use it. 

I think the correct syntax is this: 

jArrayList = autoclass('java.util.ArrayList')   
jString = autoclass('java.lang.String')
words = ['a', 'b', 'c']
arraylist = jArrayList()
for w in words:  
    arraylist.add(jString(w))

Nitish Gupta

unread,
Jul 21, 2018, 8:10:24 PM7/21/18
to kivy-...@googlegroups.com
Sorry, I think you misunderstood my question. I want to make a ArrayList<String[]> and not ArrayList<String>.

In pyjnius, String[] are expressed as python lists, but when I add one to ArrayList, it doesn't work.

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/YkO9G4efcjI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+unsubscribe@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5e27147b-db93-4923-8fe3-cea1a3e4b363%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nitish Gupta

unread,
Jul 22, 2018, 1:51:16 AM7/22/18
to kivy-...@googlegroups.com
jString = autoclass('java.lang.String')
jArrayList = autoclass('java.util.ArrayList')

jal = jArrayList()
jsl = jArrayList()
jsl.add(jString('a'))
jsll = jArrayList()
jsll.add(jString('b'))

jal.add(jsl)
jal.add(jsll)

BasicTextAnnotationBuilder = autoclass('edu.illinois.cs.cogcomp.annotation.BasicTextAnnotationBuilder')
BasicTextAnnotationBuilder.createTextAnnotationFromListofListofTokens(jal)

---------
This gives : 
JavaException: JVM exception occurred: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;

Reply all
Reply to author
Forward
0 new messages