# Error calling android static method from Unity

**URL:** https://discussions.unity.com/t/error-calling-android-static-method-from-unity/636795
**Category:** Mobile
**Tags:** Android
**Created:** [August 17, 2016, 3:53pm UTC](https://discussions.unity.com/t/error-calling-android-static-method-from-unity/636795 "2016-08-17T15:53:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kalathos16](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@kalathos16](https://discussions.unity.com/u/kalathos16)
#### Post date: [August 17, 2016, 3:53pm UTC](https://discussions.unity.com/t/error-calling-android-static-method-from-unity/636795/1 "2016-08-17T15:53:09Z")

</div>

**Hi, I have this simplified android code:**

package com.ak.shimmer;  
import com.unity3d.player.UnityPlayerActivity;  
public class MainActivity extends UnityPlayerActivity{  
protected void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
setContentView(R.layout.activity\_main);  
.(etc)  
.}  
// call this method from unity  
public static void calledFromUnity(){  
System.out.println(“calledFromUnity method is called”);  
}  
}

**This C+ code in Unity:**

using UnityEngine;  
using System.Collections;  
using UnityEngine.UI;

public class on\_onClick:MonoBehaviour{

public void shareText(){  
//executethebelowlinesifbeingrunonaAndroid device  
#ifUNITY\_ANDROID  
var androidJC=new AndroidJavaClass(“com.unity3d.player.UnityPlayer”);  
var jo=androidJC.GetStatic(“currentActivity”);  
jo.CallStatic(“calledFromUnity”);  
#endif  
}  
}

**And I am getting this error in the logcat:**

08-17 17:51:58.245: I/Unity(14253): AndroidJavaException: java.lang.NoSuchMethodError: no static method “Lcom/unity3d/player/UnityPlayerActivity;.calledFromUnity()V”

---

<div class="post-metadata">

### Author: ![liortal](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/liortal/32/238558_2.png) [@liortal](https://discussions.unity.com/u/liortal)
#### Post date: [August 19, 2016, 10:48pm UTC](https://discussions.unity.com/t/error-calling-android-static-method-from-unity/636795/2 "2016-08-19T22:48:16Z")

</div>

It looks like currentActivity returns UnityPlayerActivity, and not MainActivity (the one that you have defined).

Are you sure you have set it up properly so that it will override Unity’s default activity ?

---

<div class="post-metadata">

### Author: ![kalathos16](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@kalathos16](https://discussions.unity.com/u/kalathos16)
#### Post date: [September 1, 2016, 1:18pm UTC](https://discussions.unity.com/t/error-calling-android-static-method-from-unity/636795/3 "2016-09-01T13:18:37Z")

</div>

> [@liortal](#):
>
> It looks like currentActivity returns UnityPlayerActivity, and not MainActivity (the one that you have defined).
> 
> Are you sure you have set it up properly so that it will override Unity’s default activity ?

What do you mean with set it up?

I let the android app running in background while I push the method´s button of my Unity app.

I have followed these steps: [http://forum.unity3d.com/threads/integrating-unity-and-eclipse.71607/](http://forum.unity3d.com/threads/integrating-unity-and-eclipse.71607/)

---

<div class="post-metadata">

### Author: ![liortal](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/liortal/32/238558_2.png) [@liortal](https://discussions.unity.com/u/liortal)
#### Post date: [September 8, 2016, 8:16pm UTC](https://discussions.unity.com/t/error-calling-android-static-method-from-unity/636795/4 "2016-09-08T20:16:39Z")

</div>

I meant - if you declare your own activity (a Java class derived from Activity), you have to declare that this is the main activity you use for your game in the AndroidManifest.xml. Also - your class should derive from Unity’s activity.

Check out this link for more information: [Unity - Manual: Create and use plug-ins in Android](https://docs.unity3d.com/Manual/PluginsForAndroid.html)
