- Home /
Question by
Fun_Royal · May 16, 2016 at 03:35 PM ·
androidandroid sdkandroidjavaobject
unity Exception:JNI:Init'd AndroidJavaObject with null prt!
when my program run at 5 line in Unity Test.cs, " AndroidJavaObject jo = jc.CallStatic("instance");", it throw out the exception as described and end up.
Exception:JNI:Init'd AndroidJavaObject with null prt! at UnityEngine.AndroidJavaObject..ctor(IntPtr jobject)(0x00000)in:0
MainActivity.java
public class MainActivity extends UnityPlayerActivity {
private static MainActivity instance;
private static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainActivity.instance = this;
context = getApplicationContext();
}
public void InstallAPK(String path)
{
Log.d("debug","InstallAPK path"+path);
File apkFile = new File(path);
if(apkFile.exists())
{
Log.d("debug","InstallAPK!");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(apkFile),"application/vnd.android.package-archive");
context.startActivity(intent);
}
else
{
Log.d("debug","fiald file!");
}
}
public static MainActivity instance()
{
return instance;
}
}
AndroidManifest.xml
<application
android:name="com.talkingsdk.sdk.SdkMainApplication"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:debuggable="false">
<activity android:configChanges="locale|mcc|mnc|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
android:label="@string/app_name"
android:launchMode="singleTask"
android:name="com.unity3d.player.UnityPlayerProxyActivity"
android:screenOrientation="landscape"/>
<activity android:configChanges="locale|mcc|mnc|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
android:label="@string/app_name"
android:launchMode="singleTask"
android:name="com.unity3d.player.UnityPlayerActivity"
android:screenOrientation="landscape"/>
<activity android:configChanges="locale|mcc|mnc|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
android:label="@string/app_name"
android:name="com.talkingsdk.umeng.GamePushActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.cmd.kz3d.qihu.MainActivity"
android:label="@string/app_name" >
</activity>
Unity Test.cs
void OnGUI()
{
if(GUI.Button(new Rect(10,250,450,100),"Install"))
{
AndroidJavaClass jc = new AndroidJavaClass("com.cmd.kz3d.qihu.MainActivity");
AndroidJavaObject jo = jc.CallStatic<AndroidJavaObject>("instance");
string path = Application.persistentDataPath+"/test.apk";
Debug.Log(path);
if(!File.Exists(path))
{
Debug.Log("not found");
}
//jc.Call("InstallAPK", path);
jc.Call("InstallAPK", path);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612080912im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple errors: Gradle/SDK/JDK related. Unity android build 5 Answers
I want to know how to access an external USB camera connected to my Android smartphone. 0 Answers
How to translate ArrayList to C# using AndroidJavaClass? 1 Answer
Facebook SDK Android Error Message: "Failed to re-package resources. See Console for details" 0 Answers