Я пытаюсь создать приложение для Android, которое будет отправлять строку через сокет, однако приложение мгновенно останавливается после запуска на моем Android. Мой основной код активности:
package com.example.phoenix.coreclient;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings.System;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
class AsyncTaskActivity extends Activity implements OnClickListener {
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button_id);
// because we implement OnClickListener we only have to pass "this"
// (much easier)
btn.setOnClickListener(this);
}
public void onClick(View view) {
// detect the view that was "clicked"
switch (view.getId()) {
case (R.id.button_id):
new LongOperation().execute("");
break;
}
}
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.interrupted();
}
}
return "Executed";
}
@Override
protected void onPostExecute(String result) {
final TextView mStatusText = (TextView) findViewById(R.id.text_view_id);
try {
Socket socket = new Socket("192.168.1.68", 60000);
OutputStream out = socket.getOutputStream();
PrintWriter output = new PrintWriter(out);
mStatusText.setText("Sending Data to PC");
output.println("Hello from Android");
out.flush();
out.close();
mStatusText.setText("Data sent to PC");
socket.close();
mStatusText.setText("Socket closed");
} catch (Exception e) {
mStatusText.setText(e.toString());
}
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
}
Я не такойхорош в отладке Мне нужна помощь
09-15 21:01:38.837 29818-29818/? D/dalvikvm: Late-enabling CheckJNI
09-15 21:01:38.951 29818-29818/com.example.phoenix.coreclient D/HyLog: I : /data/font/config/dfactpre.dat, No such file or directory (2)
09-15 21:01:39.061 29818-29818/com.example.phoenix.coreclient D/AndroidRuntime: Shutting down VM
09-15 21:01:39.061 29818-29818/com.example.phoenix.coreclient W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x419a8d58)
09-15 21:01:39.080 29818-29818/com.example.phoenix.coreclient E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.phoenix.coreclient, PID: 29818
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.phoenix.coreclient/com.example.phoenix.coreclient.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.phoenix.coreclient.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.phoenix.coreclient-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.phoenix.coreclient-2, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.phoenix.coreclient.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.phoenix.coreclient-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.phoenix.coreclient-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2119)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Так в чем здесь проблема и как я могу ее решить?Я добавил разрешение на подключение к Интернету, и на стороне сервера есть простой код Python на компьютере, который тестируется и работает просто отлично