Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by leekinon · Oct 20, 2015 at 11:59 AM · pluginjava

Problem with call static methods in plugin

How to call C# to java?

I find some method in website but it not work.

Here is my c# script

 var activityJavaClass=new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  if(activityJavaClass!=null){
  Debug.Log("UnityPlayer class not null");
                             // To get the activity
 var currentActivityJavaObject=activityJavaClass.GetStatic<AndroidJavaObject>("currentActivity");
 AndroidJavaObject app = currentActivityJavaObject.Call<AndroidJavaObject>("getApplicationContext");
  
  if(currentActivityJavaObject!=null){
 Debug.Log("currentActivity object of UnityPlayer not null");
 var manager=GetComponent<CapturedScreenManager>()as CapturedScreenManager;
  
 if(manager!=null){
                                     //string path="/storage/emulated/0/DCIM/Camera/VID_20151017_072913.mp4";
 string path=manager.androidSavePath;
 if(path==null|| string.Equals(path,"")){
  Debug.LogError("Android save path is null or empty");
 return;
 }
                                     Debug.Log("About to share to Youku from path: " + path);
                                     // To get the share video class
                                     AndroidJavaClass javaClass=new AndroidJavaClass("com.youku.uploader.ShareToYouku");
  
 if(javaClass!=null){
 Debug.Log ("ShareToYouku java class not null");
 currentActivityJavaObject.Call("runOnUiThread", new AndroidJavaRunnable(() =>{
 javaClass.CallStatic("GetDataFromUnity", new object[]{ "32e7028d0a42009c","50cc4b8cfe70fd56ccdfecd7460e88b5",accessToken,title,tag, path, app});
                                         }));
                                     }else{
                                         Debug.LogError("ShareToYouku java class is null");
                                     }
                                 }else{
                                     Debug.LogError("Captured screen manager is null");
                                 }
                             }else {
                                 Debug.LogError("currentActivity object of UnityPlayer is null");
                             }
                         }else{
                             Debug.LogError("UnityPlayer class is null");
                         }

Here is my java script

  public static void GetDataFromUnity(String clientID,String client_secret,String access_token, String title, String tags, String file_name, Context context)

I already add jar into Plugin>Android. But it show error after the Debug Log (ShareToYouku java class not null)

 11-10 13:02:10.466: I/Unity(3354): AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.youku.uploader.YoukuUploader.upload(java.util.HashMap, java.util.HashMap, com.youku.uploader.IUploadResponseHandler)' on a null object reference
 11-10 12:05:45.585: I/Unity(20610):   at UnityEngine._AndroidJNIHelper.GetSignature (System.Object obj) [0x00000] in <filename unknown>:0
 11-10 12:06:48.950: I/Unity(20610):   at UnityEngine._AndroidJNIHelper.GetSignature (System.Object[] args) [0x00000] in <filename unknown>:0
 11-10 12:06:48.950: I/Unity(20610):   at UnityEngine._AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.Object[] args, Boolean isStatic) [0x00000] in <filename unknown>:0
 11-10 12:06:48.950: I/Unity(20610):   at UnityEngine.AndroidJNIHelper.GetMethodID (IntPtr jclass, System.String methodName, System.Object[] args, Boolean isStatic) [0x00000] in <filename unknown>:0
 11-10 12:07:56.735: I/Unity(20610):   at UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
 11-10 12:07:56.735: I/Unity(20610):   at UnityEngine.AndroidJavaObject.CallStatic (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
 11-10 12:07:56.735: I/Unity(20610):   at UIButtonShare+<GetAccessToken>c__AnonStorey39+<GetAccessToken>c__AnonStorey36.<>m__60 () [0x00000] in <f



Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image leekinon · Oct 20, 2015 at 10:23 AM 0
Share

After change some scripts, the first line of error is turn to 11-10 17:31:44.506: I/Unity(13572): AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/loopj/android/http/AsyncHttpClient;

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

JNI error when calling Java plugin from System.AppDomain.CurrentDomain.UnhandledException callback handler 0 Answers

Android/Unity/Eclipse Help 0 Answers

Admob plugin error: Java.Lang.ClassNotFoundException: com.google.android.gms.ads.mobileads 2 Answers

How Set Java Plugin on Unity? 0 Answers

How to write a java lib for unity as a plugin to make run another android app? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges