我用 Omegle 集成创建了一个 Android 应用程序,omegle java 客户端是一个开源项目形式 github,它有一个控制台客户端示例,在 java 控制台中运行良好,我试图在我想要的 Android 活动中插入代码在 TextView 中显示它并在需要时插入我自己的文本。
这是我的代码
MainActivity.java
package com.example.com.omegle.test;
import org.nikki.omegle.Omegle;
import org.nikki.omegle.core.OmegleException;
import org.nikki.omegle.core.OmegleMode;
import org.nikki.omegle.core.OmegleSession;
import org.nikki.omegle.event.OmegleEventAdaptor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OmegleChat om=new OmegleChat();
om.execute();
}
private class OmegleChat extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
txt=(TextView)findViewById(R.id.omegle);
txt.append("Omegele Connection Started... \n");
}
@Override
protected void onProgressUpdate(Void... values) {
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
OmgeleChatOn();
return null;
}
@Override
protected void onPostExecute(Void result) {
}
}
public void OmgeleChatOn()
{
Omegle omegle = new Omegle();
try {
System.out.println("Opening session...");
OmegleSession session = omegle.openSession(OmegleMode.NORMAL, new OmegleEventAdaptor() {
@Override
public void chatWaiting(OmegleSession session) {
System.out.println("Waiting for chat...");
}
@Override
public void chatConnected(OmegleSession session) {
System.out
.println("You are now talking to a random stranger!");
}
@Override
public void chatMessage(OmegleSession session, String message) {
System.out.println("Stranger: " + message);
}
@Override
public void messageSent(OmegleSession session, String string) {
System.out.println("You: " + string);
}
@Override
public void strangerDisconnected(OmegleSession session) {
System.out.println("Stranger disconnected, goodbye!");
//System.exit(0);
}
@Override
public void omegleError(OmegleSession session, String string) {
System.out.println("ERROR! " + string);
System.exit(1);
}
});
} catch (OmegleException e) {
e.printStackTrace();
}
}
}
现在这是错误日志,应用程序在几秒钟后崩溃,陌生人可以回复,在他回复后应用程序像这样崩溃 -->
07-05 04:05:26.758: I/Process(661): Sending signal. PID: 661 SIG: 9
07-05 04:05:58.358: I/System.out(673): Opening session...
07-05 04:05:59.598: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:05:59.618: I/dalvikvm(673): Could not find method org.json.JSONArray.<init>, referenced from method org.nikki.omegle.core.OmegleSession.fireEvent
07-05 04:05:59.618: W/dalvikvm(673): VFY: unable to resolve direct method 3626: Lorg/json/JSONArray;.<init> (Ljava/lang/Object;)V
07-05 04:05:59.618: D/dalvikvm(673): VFY: replacing opcode 0x70 at 0x003e
07-05 04:05:59.628: D/dalvikvm(673): VFY: dead code 0x0041-0041 in Lorg/nikki/omegle/core/OmegleSession;.fireEvent (Lorg/nikki/omegle/core/OmegleEvent;Ljava/lang/Object;)V
07-05 04:05:59.658: I/System.out(673): Waiting for chat...
07-05 04:06:05.208: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:05.218: I/System.out(673): You are now talking to a random stranger!
07-05 04:06:09.969: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:17.139: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:17.149: I/System.out(673): Stranger: hlelo [: .,.
07-05 04:06:21.378: W/KeyCharacterMap(673): No keyboard for id 0
07-05 04:06:21.378: W/KeyCharacterMap(673): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
07-05 04:06:28.538: D/dalvikvm(673): GC_FOR_MALLOC freed 6183 objects / 399936 bytes in 85ms
07-05 04:06:28.538: W/KeyCharacterMap(673): No keyboard for id 0
07-05 04:06:28.538: W/KeyCharacterMap(673): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
07-05 04:06:28.588: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:30.068: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:35.708: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:45.478: I/global(673): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-05 04:06:45.510: W/dalvikvm(673): threadid=9: thread exiting with uncaught exception (group=0x4001d800)
07-05 04:06:45.510: E/AndroidRuntime(673): FATAL EXCEPTION: pool-1-thread-3
07-05 04:06:45.510: E/AndroidRuntime(673): java.lang.NoSuchMethodError: org.json.JSONArray.<init>
07-05 04:06:45.510: E/AndroidRuntime(673): at org.nikki.omegle.core.OmegleSession.fireEvent(OmegleSession.java:250)
07-05 04:06:45.510: E/AndroidRuntime(673): at org.nikki.omegle.core.OmegleSession.checkEvents(OmegleSession.java:204)
07-05 04:06:45.510: E/AndroidRuntime(673): at org.nikki.omegle.Omegle$1.run(Omegle.java:124)
07-05 04:06:45.510: E/AndroidRuntime(673): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-05 04:06:45.510: E/AndroidRuntime(673): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-05 04:06:45.510: E/AndroidRuntime(673): at java.lang.Thread.run(Thread.java:1096)
池 1 线程 -3 异常的原因可能是什么。