Hello. I am trying to learn how to create an android plugin for a game. I am getting this error in LogCat: ```
2022-03-19 13:52:03.157 7866-7911/? E/Unity: Error: Object reference not set to an instance of an object :: at BlueTootheLEWrapperAndroid.Tester (System.String name) [0x0000a] in <3c57ec3dcf8d4354bd414392ea186135>:0
at TestUiManipulator.ChangeTextField () [0x00000] in <3c57ec3dcf8d4354bd414392ea186135>:0
In my scene I have a button that calls TestUimanipulator.cs > ChangeTextField() and then that calls BluetoothLEWrapperAndroid.cs > Tester(string). I have confirmed that name does have a value, it is not null. There is no error logged during the instantiation of the wrapper.
Here is the code:
```csharp
//TestUiManipulator
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestUiManipulator : MonoBehaviour
{
public Text TextField;
private IBlueToothLE BlueTooth;
public void Start()
{
if (Application.platform == RuntimePlatform.Android)
BlueTooth = new BlueTootheLEWrapperAndroid();
else
BlueTooth = new BlueToothWrapperWindows();
}
public void ChangeTextField()
{
try
{
TextField.text = BlueTooth.Tester("Jeremy");//"OMG! WHY DID YOU CLICK THE BUTON!";
}
catch (Exception e)
{
TextField.text = "Error: " + e.Message;
Debug.LogError($"Error: {e.Message} :: {e.StackTrace}");
}
}
}
//BluetoothLEWrapperAndroid.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlueTootheLEWrapperAndroid : MonoBehaviour, IBlueToothLE
{
private AndroidJavaObject BlueToothLE;
// Start is called before the first frame update
void Start()
{
try
{
BlueToothLE = new AndroidJavaObject("com.studiokitsune.bluetoothlelibrary.BluetoothLeRunner");
}
catch(Exception e)
{
Debug.LogError($"Error instantiating BlueToothLERunner :: {e.Message} :: {e.StackTrace}");
}
}
// Update is called once per frame
void Update()
{
}
public string Tester(string name)
{
if (name == null)
name = "No Name";
return BlueToothLE.Call<string>("tester", new object[] { name });
}
}
Any help would be appreciated, thank you.
EDIT: The android Code
//Java was not an option for code insert but this is Java
package com.studiokitsune.bluetoothlelibrary;
import android.util.Log;
public class BluetoothLeRunner {
public String tester(String name)
{
//Log.d("Unity", "Hello from Android plugin");
return "Hello from android " + name;
}
}