How to retrieve a ArrayList from C# to java Call

418 views
Skip to first unread message

AkIberdrola

unread,
Apr 7, 2010, 4:02:54 PM4/7/10
to jni4net
Hi Pavel

Thanks a ton for building this tool. Its totally awesome. I need your
help .I have a C# program that sends a ArrayList containing a c sharp
class objects ( say a list of Test objects).

The Java program on the receiving end calls this method and receives
the Object. But i can not typecast the Object return type to a List or
ArrayList type in java..

See below my code. and the error message.

Bridge.init();
File file = new File("C:\\PI-WTJavaWorkSpace1.0\\JavaPIWTInterface\\lib
\\PiToWTJNI.j4n.dll");
Bridge.LoadAndRegisterAssemblyFrom(file);

List arrayList = new ArrayList();
IPiToWTJNI db = new PiToWTJNI();

arrayList = db.getPIData("MV90.PLV.MWHDEL");
System.out.printf("This is the object retured"+arrayList.size());


When i execute i get the following error....

java.lang.ClassCastException: system.collections.__IList cannot be
cast to java.util.List
at
com.iberdrola.piwtreconn.jininterface.PIJNIInterface.main(PIJNIInterface.java:
33)

Can you help ?

Thanks
Akila.

Pavel Šavara

unread,
Apr 7, 2010, 4:57:28 PM4/7/10
to jni...@googlegroups.com
Without too much thinking:
you confuse java.util.List with System.Collection.IList.
Try this

system.collections.IList list = db.getPIData("MV90.PLV.MWHDEL");
System.out.printf("This is the object retured"+list.getCount());

I didn't compiled/tested that ;-)

> --
> You received this message because you are subscribed to jni...@googlegroups.com
> http://groups.google.com/group/jni4net?hl=en-GB?hl=en-GB
> http://jni4net.sf.net/
>
> To unsubscribe, reply using "remove me" as the subject.
>

Amine Chaari

unread,
Aug 9, 2017, 8:10:16 AM8/9/17
to jni4net
Another suggestions please! Any help?

Amine Chaari

unread,
Aug 9, 2017, 9:06:39 AM8/9/17
to jni4net

I have used System.Collections.IList like this: system.collections.IList list = ara.DisplayAllDocuments();
 and that's fine. But in Java how can I access to an element  of  my list?
Thank you.

Pavel Šavara

unread,
Aug 9, 2017, 9:34:38 AM8/9/17
to jni4net

--
---
You received this message because you are subscribed to the Google Groups "jni4net" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jni4net+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Amine Chaari

unread,
Aug 9, 2017, 5:11:53 PM8/9/17
to jni4net
thank you for your response but no one of methods in IList.java let me access to an element in my list.
I want to access to my list's elements because i want to display data in Jtable Swing.
To unsubscribe from this group and stop receiving emails from it, send an email to jni4net+u...@googlegroups.com.

Pavel Šavara

unread,
Aug 9, 2017, 5:28:23 PM8/9/17
to jni4net
GetItem is the one you need.

To unsubscribe from this group and stop receiving emails from it, send an email to jni4net+unsubscribe@googlegroups.com.

Amine Chaari

unread,
Aug 10, 2017, 2:50:33 PM8/10/17
to jni4net
when i apply getItem, i can't access to proporties and methods of my Class.

There is the code in C#:

IList<ArasDocument> docs = ara.DisplayAllDocuments();

            for(int i=0;i<docs.Count;i++)
                   {
                docs[i].ShowDocs();
                    }

and there is the code in Java:


Thank you!

Pavel Šavara

unread,
Aug 10, 2017, 2:54:57 PM8/10/17
to jni4net
you need proxygen to generate the (java) proxy of the data type inside of the list. 
Then you cast each item to the java proxy type via Bridge.cast().


To unsubscribe from this group and stop receiving emails from it, send an email to jni4net+unsubscribe@googlegroups.com.

Amine Chaari

unread,
Aug 10, 2017, 3:07:57 PM8/10/17
to jni4net
Sorry,i don't understand very much. Can you develop more?
Thanks!

Amine Chaari

unread,
Aug 11, 2017, 6:04:03 AM8/11/17
to jni4net
Should the Name of the Class be the 2nd parameter of the Bridge.Cast ?
Object test= docs.getItem(i);
ArasDocument a = Bridge.cast(test,ArasDocument);

Because I have an error on it: cannot find symbol
  symbol:   variable ArasDocument
Reply all
Reply to author
Forward
0 new messages