При запуске потока приложение вылетает с этой ошибкой
05-24 20: 50: 28.664 17513-17684 / alexeutuan.myapplication A / libc: фатальный сигнал 11 (SIGSEGV),код 1, адрес ошибки 0x0 в tid 17684 (нить-3)
05-24 20: 50: 28.732 17685-17685 /?A / DEBUG: * *
05-24 20: 50: 28,732 17685-17685 /?A / DEBUG: Создание отпечатка пальца: 'xiaomi / mido / mido: 7.0 / NRD90M / V9.5.9.0.NCFMIFA: пользовательские / клавиши разблокировки'
05-24 20: 50: 28.732 17685-17685 /?A / DEBUG: Редакция: '0'
05-24 20: 50: 28.732 17685-17685 /?A / DEBUG: ABI: 'arm64'
05-24 20: 50: 28.732 17685-17685 /?A / DEBUG: pid: 17513, tid: 17684, имя: Thread-3 >>> alexeutuan.myapplication <<< </p>
05-24 20: 50: 28.732 17685-17685 /?A / DEBUG: сигнал 11 (SIGSEGV), код 1 (SEGV_MAPERR), адрес ошибки 0x0
05-24 20: 50: 28,732 17685-17685 /?A / DEBUG: x0 0000000000000003 x1 0000007f61310a98 x2 0000000000000000 x3 0000000000000000
05-24 20: 50: 28,732 17685-17685 /?A / DEBUG: x4 0000000000000000 x5 0000007f61310818 x6 0000007f728465d8 x7 ffffffffffffffff
05-24 20: 50: 28,732 17685-17685 /?A / DEBUG: x8 0000000000000000 x9 0000007f72839170 x10 441cc0004403c000 x11 0000007f7283abcc
05-24 20: 50: 28,732 17685-17685 /?A / DEBUG: x12 0000007f7283af92 x13 0000007f7d18a418 x14 ffffffffffcf65ec x15 0000007f61310898
05-24 20: 50: 28,732 17685-17685 /?A / DEBUG: x16 0000007f7d553f08 x17 0000007f7d18a318 x18 0000007f7d493d9c x19 0000007f61310c88
05-24 20: 50: 28,733 17685-17685 /?A / DEBUG: x20 0000007f6d690cc0 x21 0000007f61310b88 x22 0000007f7d494a40 x23 0000007f61310a48
05-24 20: 50: 28,733 17685-17685 /?A / DEBUG: x24 0000007f61310aa0 x25 0000007f61310aa8 x26 0000007f61310ab0 x27 0000000000000004
05-24 20: 50: 28,733 17685-17685 /?A / DEBUG: x28 0000007f613109d0 x29 0000007f61310b70 x30 0000007f7d1d66b8
05-24 20: 50: 28,733 17685-17685 /?A / DEBUG: sp 0000007f61310950 pc 0000007f7d1d6728 pstate 0000000080000000
05-24 20: 50: 28,736 17685-17685 /?A / DEBUG: # 00 pc 0000000000246728 /system/lib64/libskia.so ( ZNK8SkStroke10strokePathERK6SkPathPS0 + 460)
05-24 20: 50: 28.736 17685-17685 /?A / DEBUG: # 01 pc 0000000000246e38 /system/lib64/libskia.so ( ZNK11SkStrokeRec11applyToPathEP6SkPathRKS0 + 152)
05-24 20: 50: 28.736 17685-17685 /?A / DEBUG: # 02 pc 00000000001f3e74 /system/lib64/libskia.so (_ZNK7SkPaint11getFillPathERK6SkPathPS0_PK6SkRectf + 136)
05-24 20: 50: 28,736 17685-17685 /?A / DEBUG: # 03 pc 00000000001c2838 /system/lib64/libskia.so (_ZNK6SkDraw8drawPathERK6SkPathRK7SkPaintPK8SkMatrixbbP9SkBlitter + 640)
05-24 20: 50: 2868568A / DEBUG: # 04 pc 00000000001ace50 /system/lib64/libskia.so (_ZN8SkCanvas10onDrawPathERK6SkPathRK7SkPaint + 720)
05-24 20: 50: 28.737 17685-17685 /?A / DEBUG: # 05 pc 0000000000102134 /system/lib64/libandroid_runtime.so
05-24 20: 50: 28.737 17685-17685 /?A / DEBUG: # 06 pc 00000000750fc664 /data/dalvik-cache/arm64/system@framework@boot.oat (смещение 0x2f11000)
При нажатии в начальном потоке asyncTask
play = (Button) findViewById(R.id.bPlay);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setTrueFalse();
if (hasConn.isOnline(getApplicationContext())) {
RequestTask requestTask = new RequestTask();
requestTask.execute("2");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println(e);
}
Intent i = new Intent(AuthActivity.this, GameActivity.class);
i.putExtra("true_returnes", true_returnes);
i.putExtra("false_returnes", false_returnes);
startActivityForResult(i, 1);
} else
Toast.makeText(getApplicationContext(), "Отсутствует подключение к интернету!", Toast.LENGTH_SHORT).show();
}
});
Поток подключается к серверу
class RequestTask extends AsyncTask<String, String, String> {
String arr;
String url = "http://192.168.0.5:8888/servlet";
HttpURLConnection con;
@Override
protected String doInBackground(String... params) {
try {
this.arr = params[0];
URL obj = new URL(url);
con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
// For POST only - START
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(arr.getBytes());
os.flush();
os.close();
// For POST only - END
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
if(arr.startsWith("2")) return response.toString();
} else {
Log.d("TAG", "POST NOT WORKED");
}
} catch (Exception e) {
System.out.println(e);
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(arr.startsWith("2")) {
System.out.println("RequestTask " + result);
GameActivity.arr = result;
}
// con.disconnect();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
}
К серверу все нормально, запрос к серверу - отправь запрос, получи ответ.Ошибка лежит в клиенте
После вызова Thread.sleep () активность GameActivity
public class GameActivity extends AppCompatActivity {
int true_returnes;
int false_returnes;
public static String arr;
private SurfaceHelperGame sHelperGame;
Button ok,okName;
EditText imageName;
Button accept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
sHelperGame = (SurfaceHelperGame) findViewById(R.id.surfaceView2);
true_returnes = getIntent().getIntExtra("true_returnes",0);
false_returnes = getIntent().getIntExtra("false_returnes",0);
sHelperGame.arr = arr;
ok = (Button) findViewById(R.id.bOk);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sHelperGame.drawThread.running = false;
Intent i = new Intent();
i.putExtra("true_returnes",true_returnes);
i.putExtra("false_returnes", false_returnes);
setResult(RESULT_OK, i);
finish();
}
});
accept = (Button) findViewById(R.id.bAccept);
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RequestTask requestTask = new RequestTask();
requestTask.execute("2");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println(e);
}
imageName.setText("");
sHelperGame.arr = arr;
sHelperGame.invalidate();
okName.setEnabled(true);
}
});
okName = (Button) findViewById(R.id.bOkGame);
okName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imageName.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(),"Введите название!",Toast.LENGTH_SHORT).show();
} else {
if(imageName.getText().toString().equals(sHelperGame.name)) true_returnes++;
else false_returnes++;
okName.setEnabled(false);
}
}
});
imageName = (EditText) findViewById(R.id.imageNameRes);
imageName.setText("");
}
@Override
protected void onStop() {
super.onStop();
sHelperGame.drawThread.running = false;
}
@Override
protected void onPause() {
super.onPause();
// sHelperGame.drawThread.running = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
sHelperGame.drawThread.running = false;
}
}
Он в виджете SurfaceView (связан с классом SurfaceHelperGame) возвращаетпуть
public class SurfaceHelperGame extends SurfaceView implements SurfaceHolder.Callback {
String arr;
String[] ss;
String name;
DrawThread drawThread;
public SurfaceHelperGame(Context context,AttributeSet attributeSet) {
super(context,attributeSet);
getHolder().addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
ss = arr.split(",");
name = ss[ss.length-1];
System.out.println("Name " + name);
drawThread = new DrawThread(getContext(),getHolder());
drawThread.start();
myDrawPath();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// изменение размеров SurfaceView
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
@Override
public void invalidate() {
super.invalidate();
clearCanvas();
ss = arr.split(",");
name = ss[ss.length-1];
System.out.println("Name " + name);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
drawThread.requestStop();
boolean retry = true;
while (retry) {
try {
drawThread.join();
retry = false;
} catch (InterruptedException e) {/* ... */}
}
}
public void clearCanvas() {
drawThread.path.reset();
drawThread.canvas.drawColor(Color.WHITE);
}
public void myDrawPath() {
drawThread.path.moveTo(Float.valueOf(ss[1]),Float.valueOf(ss[2]));
drawThread.path.lineTo(Float.valueOf(ss[3]), Float.valueOf(ss[4]));
for (int i = 5; i <ss.length-2 ; i += 2) {
if(Math.abs(Float.valueOf(ss[i]) - Float.valueOf(ss[i-2])) > 100 || Math.abs(Float.valueOf(ss[i+1]) - Float.valueOf(ss[i-1])) > 100)
drawThread.path.moveTo(Float.valueOf(ss[i]), Float.valueOf(ss[i+1]));
drawThread.path.lineTo(Float.valueOf(ss[i]),Float.valueOf(ss[i+1]));
}
}
public class DrawThread extends Thread {
Path path = new Path();
Canvas canvas;
private SurfaceHolder surfaceHolder;
volatile boolean running = true;//флаг для остановки потока
public DrawThread(Context context, SurfaceHolder surfaceHolder) {
this.surfaceHolder = surfaceHolder;
}
public void requestStop() {
running = false;
}
@Override
public void run() {
while (running) {
Paint paint = new Paint();
canvas = surfaceHolder.lockCanvas();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(10);
if (canvas != null) {
try {
canvas.drawColor(Color.WHITE);
canvas.drawPath(path, paint);
myDrawPath();
} finally {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
}
Я не могу понять, почему происходит сбой приложения из-за потока.Я искал похожие темы - я не нашел своей проблемы.Помогите, пожалуйста, разобраться