Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 smallbit · Apr 21, 2015 at 08:29 AM · androidjavaplugins

Android Java Plugin For Unity Object with null ptr!

So I wanted to test out writing custom plugins for unity. I am using Android Studio 1.1.0. I found tutorial to write a plugin, and it works when defined in manifest as MainActivity.But if I add it as secondary plugin I am having the following error:

 04-21 15:13:58.446: I/Unity(23041): Exception: JNI: Init'd AndroidJavaObject with null ptr!
 04-21 15:13:58.446: I/Unity(23041):   at UnityEngine.AndroidJavaObject..ctor (IntPtr jobject) [0x00000] in :0 
 04-21 15:13:58.446: I/Unity(23041):   at UnityEngine.AndroidJavaObject.AndroidJavaObjectDeleteLocalRef (IntPtr jobject) [0x00000] in :0 
 04-21 15:13:58.446: I/Unity(23041):   at UnityEngine.AndroidJavaObject._GetStatic[AndroidJavaObject] (System.String fieldName) [0x00000] in :0 
 04-21 15:13:58.446: I/Unity(23041):   at UnityEngine.AndroidJavaObject.GetStatic[AndroidJavaObject] (System.String fieldName) [0x00000] in :0 
 04-21 15:13:58.446: I/Unity(23041):   at Share.callShareApp () [0x00000] in :0 
 04-21 15:13:58.446: I/Unity(23041):   at Share.OnGUI () [0x00000] in :0 
 04-21 15:13:58.446: I/Unity(23041):  

My Java code:

  package com.example.tomek.shareproject;
     
             import android.content.Intent;
             import com.unity3d.player.UnityPlayerActivity;
           //  import android.content.Context;
             import android.os.Bundle;
     public class MainActivity extends UnityPlayerActivity {
         public static MainActivity ctx;
         //@Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             MainActivity.ctx = this;
         }
     
         public void shareText(String subject, String body) {
             Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
             sharingIntent.setType("text/plain");
             sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
             sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
             startActivity(Intent.createChooser(sharingIntent, "Share via"));
         }
     
     }
     
 

And My unity code:

 using UnityEngine;
 using System.Collections;
 
 public class Share : MonoBehaviour {
     
  
  string subject = "TITLE";
  string body = "TEST BODY TEXT";
  
  public void callShareApp()
  {
 
 #if UNITY_ANDROID
      AndroidJavaClass cls = new AndroidJavaClass("com.example.tomek.shareproject.MainActivity");
   
      
      AndroidJavaObject obj = cls.GetStatic<AndroidJavaObject> ("ctx");
      obj.Call("shareText", subject, body);
 #endif
 
  }
 
     void OnGUI()
     {
         if (GUI.Button(new Rect(10, 10, 50, 50), "Click me "))
             callShareApp();
 
     }
 }


Also my manifest:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.unity3d.playe"
       android:versionCode="1"
       android:versionName="1.0">
     <uses-sdk android:minSdkVersion="9" />
     <application android:label="@string/app_name">
         <activity android:name="com.unity3d.player.UnityPlayerActivity"
                   android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
           <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
           <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
         </activity>
       <!-- Required by my Plugin -->
       <activity android:name="com.example.tomek.shareproject.MainActivity" />
     </application>
 </manifest>


So I read few dozens of topic regarding this error but cannot find a solution. Can anybody point out where I might go wrong about it ?

Best Regards

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

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

20 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

Related Questions

Using AndroidJavaClass in a java Unity3d plugin 0 Answers

Can I instance ArrayList[String] through AndroidJavaObject ? 2 Answers

Unity Plugin or Unity in Android SDK. 0 Answers

Uncomiled Java code Android 0 Answers

AndroidJavaClass. Call returns null ptr. 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