• 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
1
Question by lexvandersluijs · Jun 30, 2011 at 05:54 PM · androidjavaandroidjavaobjectjni

AndroidJavaObject.Call fails with 'method not found'

I created a Java Activity that I want to start from a C# script running in Unity.

To do so, I made this routine:

 AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");  
 Debug.Log("intentObject created");
 intentObject.Call("setClassName", "com.twnkls.SendImageWithIntent", "SendImageWithIntentActivity");

However, the 'Call' method fails with a "GetMethodID: method not found: Landroid/content/;.setClassName error. This causes the application to crash (no exception handling in place yet).

This is relevant section of the log from LogCat:

 06-30 18:34:57.053: INFO/Unity(16440): intentObject created
 06-30 18:34:57.053: INFO/Unity(16440): UnityEngine.Debug:Internal_Log(Int32, String, Object)
 06-30 18:34:57.053: INFO/Unity(16440): UnityEngine.Debug:Log(Object)
 06-30 18:34:57.053: INFO/Unity(16440): SaveScreenshotScript:OnGUI() (at XXXmy-local-file-locationXXX\SaveScreenshotInUnityAndroid\Assets\SaveScreenshotScript.cs:37)
 06-30 18:34:57.053: INFO/Unity(16440):  
 06-30 18:34:57.053: INFO/Unity(16440): (Filename: C Line: 0)
 06-30 18:34:57.073: DEBUG/dalvikvm(16440): GetMethodID: method not found: Landroid/content/Intent;.setClassName:(Ljava/lang/String;Ljava/lang/String;)V
 06-30 18:34:57.083: INFO/Unity(16440): JNI: Unable to find method id for 'setClassName'
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine.Debug:Internal_Log(Int32, String, Object)
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine.Debug:Log(Object)
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine._AndroidJNIHelper:GetMethodID(IntPtr, String, Object[], Boolean)
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine.AndroidJNIHelper:GetMethodID(IntPtr, String, Object[], Boolean)
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine.AndroidJavaObject:GetCachedMethodID(String, Object[], Boolean)
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine.AndroidJavaObject:_Call(String, Object[])
 06-30 18:34:57.083: INFO/Unity(16440): UnityEngine.AndroidJavaObject:Call(String, Object[])
 06-30 18:34:57.083: INFO/Unity(16440): SaveScreenshotScript:OnGUI() (at XXXmy-local-file-locationXXX\SaveScreenshotInUnityAndroid\Assets\SaveScreenshotScript.cs:38)

It's strange because according to the Android docs, the setClassName method in android.content.Intent has been around since API level 1.

To verify that calling methods on Java objects works at all in my environment: when I use the sample code on Unity's AndroidJavaObject documentation page, the script runs without problem, so that's not it.

Perhaps I'm making an error in the parameters to the method? Although one would think that passing two String objects would match the signature..

I'm pretty new to Android development, so I hope someone can help me out here..

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

· Add your reply
  • Sort: 
avatar image
2

Answer by Tseng · Sep 08, 2011 at 02:08 PM

Even though this is pretty old and you probably already found it out by yourself...

But the setClassName method has a return value and you're calling Call method for methods without a return value (void).

The correct way of calling the method is

 intentObject.Call<AndroidJavaObject>("setClassName", "com.twnkls.SendImageWithIntent", "SendImageWithIntentActivity");

because, setClassName returns an Intent, as you can see in the Android Documentation for the Intent class.

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

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.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What is the difference between AndroidJavaClass.Call and AndroidJavaObject.Call 2 Answers

Getting native Android String constants via JNI broken in Unity 2019.2.0? 3 Answers

Problem in android java plugin 0 Answers

How to remove an add? 0 Answers

How to access methods from nested static java classes 0 Answers


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