我正在为 Unity 制作一个 android 插件,我需要在 Unity 中集成 XMPP,所以首先我尝试创建 XMPP 的连接并发送和接收消息。它在 android 中运行良好,我可以发送和接收消息但是当我导出.jar文件并在 Unity 中使用时,所以在创建连接时出现以下错误
SmackInitialization: Could not determine Smack version
java.lang.NullPointerException: lock == null
at java.io.Reader.<init>(Reader.java:64)
at java.io.InputStreamReader.<init>(InputStreamReader.java:122)
at java.io.InputStreamReader.<init>(InputStreamReader.java:57)
at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:61)
at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
at com.arvaan.myplugins.ToastExample.connectXMPP(ToastExample.java:99)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer$b$1.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:234)
at com.unity3d.player.UnityPlayer$b.run(Unknown Source)
我不知道 Smack 有什么问题,我是 Unity 的新手,我知道如何在 Unity 中创建插件和调用方法,但不知道这里出了什么问题。
请检查代码:
public class ToastExample extends UnityPlayerActivity implements ConnectionListener, ChatManagerListener, RosterListener, PingFailedListener, StanzaListener, MessageListener, ChatMessageListener {
private static final String TAG = ToastExample.class.getSimpleName();
private AbstractXMPPConnection mConnection = null;
private ChatManager chatManager;
private Chat chat;
private Context context;
private String userName = "";
private String passWord = "";
private String objectName = "";
private static ToastExample instance;
public ToastExample() {
this.instance = this;
}
public static ToastExample instance() {
if (instance == null) {
instance = new ToastExample();
}
return instance;
}
public void setContext(Context context) { // This is also working fine
Log.e(TAG, "setContext called");
this.context = context;
}
public void showMessage(String message) { // I can able to see toast
Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show();
}
public void connectXMPP(String host, int port, String userName, String passWord) {
Log.e(TAG, "_connectXMPP called");
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder(); // Here i got error
configBuilder.setUsernameAndPassword(userName, passWord);
...............
...............
}
我在我的插件和 Unity 中使用下面的.Jar文件
smack-core-4.1.4.jar
smack-extensions-4.1.4.jar
smack-im-4.1.4.jar
smack-android-4.1.4.jar
smack-android-extensions-4.1.4.jar
smack-tcp-4.1.4.jar
jxmpp-util-cache-0.4.2.jar
jxmpp-core-0.4.2.jar
jxmpp-jid-0.4.2.jar
jxmpp-stringprep-libidn-0.4.2.jar
minidns-core-0.2.0.jar**
有人也面临这个问题,但没有找到查看更多
请帮我解决这个问题,在此先感谢.!!!