Passing Java Objects to C#

Hey Everyone,

I am attempting to implement some Java native code into my Unity project, and I want to be able to use a function in my Java code that passes back an object based on a class defined within my java code to my C# Unity code. So far I have been unable to do this.

Here is an example of the Java Side Code:

Inventory:

    public List<Weapon> weapon;

    public List<Weapon> getWeaponFromInventory(Context context)
	{
		activity = (Activity)context;
		activity.runOnUiThread(new Runnable(){
			public void run()
			{
				if(myInstance == null){
					 Log.e("Instance cannot be null");
			          throw new IllegalArgumentException("Instance was null when attempting to getWeaponFromInventory(context)");
				}
				weapon = instance.myInstance.getWeaponFromInventory(activity);
			}	
		});
		return weapon;
	}

I am then calling on this code from my C# in this way:

PlayerWeaponHandler:

	private static AndroidJavaObject instance;
        // Create link to java based Inventory
	private static AndroidJavaClass inventoryPlug= new AndroidJavaClass("com.myth.player.Inventory");
	//Create link to Unity Player
	public static AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
	//Get the current activity to use as context
	public static AndroidJavaObject currentAct = jc.GetStatic<AndroidJavaObject>("currentActivity");
	
	public static List<AndroidJavaObject> Weapon;

	static PlayerWeaponHandler(){
		if(Application.platform == RuntimePlatform.Android){
			Debug.Log ("PlayerWeaponHandler- Created");
			instance = inventoryPlug.CallStatic<AndroidJavaObject>("getInstance");
		}
	}

	public static void getWeapon(bool show){
		if(Application.platform == RuntimePlatform.Android){
             //Here I am attempting to call on a Java method that returns a Java Object holding the information about the 
            //players Weapon
			Weapon = instance.Call<List<AndroidJavaObject>>("getWeaponFromInventory", currentAct);
			return;
		}
		return;
	}

The error I get back is:

Has anyone ever dealt with trying to do this and found a way to make it work?

Would love to know if the Unity community has an answer to this question.

JavaScript is compiled before C#
http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html