• 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 /
This question was closed Jan 02, 2015 at 10:39 PM by iwaldrop for the following reason:

The question is answered.

avatar image
0
Question by Pleng · Jan 02, 2015 at 08:42 AM · coroutineandroidjavaobject

java.lang.NullPointerException in AndroidJavaObject.Call when calling from a coroutine

I extend all my classes from a base class SakadiiMono, which contains the following method:

 public bool AndroidSendMessage(ANDROID_DATA.AndroidMessageType _messageType, string _messageData, bool _debug)
 {
     try
     {
         if (_debug)
         {
             this.LogError("MessageType: " + _messageType);
             this.LogError("Sending message: " + _messageData);
         }
 
         if (inAndroid())
         {
             if (this.jc == null)
             {
                 this.jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                 this.jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
             }
 
             if (jc == null)
             {
                 this.LogError("jc is null!!");
             }
             else
             {
                 
                 if (jo == null)
                 {
                     this.LogError("jo - currentActivity is null");
                 }
                 else
                 {
                     jo.Call("OnUnityMessage", _messageType.ToString(), _messageData.ToString());
                 }
 
             }
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (System.Exception ex)
     {
         this.LogError(ex.ToString());
         return false;
     }
    } 


This method is called hundereds of time throughout my code, yet in one particular instance it will throw an exception. The only thing that is different is that it's being called from within a co-routine.

 01-02 15:27:11.450: I/Unity(17522): (Filename: D Line: 0)
  UnityEngine.AndroidJavaException: java.lang.NullPointerException
    at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 
    at UnityEngine.AndroidJNISafe.CallVoidMethod (IntPtr obj, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0 
    at UnityEngine.AndroidJavaObject._Call (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
    at UnityEngine.AndroidJavaObject.Call (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 
    at SakadiiMono.AndroidSendMessage (.AndroidMessageType _messageType, System.String _messageData, Boolean _debug) [0x0009a] in D:\Unity\Projects\[xxxxx]\Assets\Scripts\SakadiiMono.cs:88 


Is there some special way I need to be calling this function from a coroutine? I've tried to Invoke it, but that doesn't seem to help either.

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Pleng · Jan 02, 2015 at 11:20 AM

Never mind. The exception was being thrown in the Java code.

Comment
Add comment · Share
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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

StartCoroutine_Auto can only be called from the main thread. 1 Answer

How to start a coroutine from another script? 1 Answer

How do I do something after multiple coroutines finish? 1 Answer

How to make loop with call to IEnumerator actually pause? 2 Answers

Coroutines Bug? Unity 4.5 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