我希望我的 Android 应用程序充当客户端并侦听特定端口。我尝试过的所有代码都不起作用。我尝试了本教程来创建一个小型聊天应用程序。服务器端工作正常,但应用程序在我的设备上崩溃。我的手机和服务器都在 VPN 上。
返回的 logcat 文本:
11-20 12:39:12.789: W/dalvikvm(12045): threadid=1: thread exiting with uncaught exception (group=0x4017c560)
11-20 12:39:12.799: E/AndroidRuntime(12045): FATAL EXCEPTION: main
11-20 12:39:12.799: E/AndroidRuntime(12045): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android_port/com.example.android_port.MainActivity}: java.lang.ClassNotFoundException: com.example.android_port.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android_port-1.apk]
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.os.Looper.loop(Looper.java:130)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-20 12:39:12.799: E/AndroidRuntime(12045): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 12:39:12.799: E/AndroidRuntime(12045): at java.lang.reflect.Method.invoke(Method.java:507)
11-20 12:39:12.799: E/AndroidRuntime(12045): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
11-20 12:39:12.799: E/AndroidRuntime(12045): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
11-20 12:39:12.799: E/AndroidRuntime(12045): at dalvik.system.NativeStart.main(Native Method)
11-20 12:39:12.799: E/AndroidRuntime(12045): Caused by: java.lang.ClassNotFoundException: com.example.android_port.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android_port-1.apk]
11-20 12:39:12.799: E/AndroidRuntime(12045): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-20 12:39:12.799: E/AndroidRuntime(12045): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-20 12:39:12.799: E/AndroidRuntime(12045): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-20 12:39:12.799: E/AndroidRuntime(12045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
11-20 12:39:12.799: E/AndroidRuntime(12045): ... 11 more