Android Studio :FATAL EXCEPTION: Thread-2
我在编辑设计注册界面的时候,出现的这个问题,如上 ,系统总是报错,但我不知道我写的程序哪里错了,请指点!
我这段代码主要是向网站提交请求,然后注册账号,并保存token在本地。但是每次点击运行都会闪退,并弹出如题所示的报错,查询无果,所以在此询问。
```java
private void sendRequestWithokhttp() {
new Thread(new Runnable() {
@Override
public void run() {
OkHttpClient client = new OkHttpClient();
javaBean.setName(name);
javaBean.setPassword(password);
String json = new Gson().toJson(javaBean);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"), json);
Request request = new Request.Builder()
.url("https://**************(保密)")
.addHeader("Content-Type", "application/json;charset=UTF-8")
.post(requestBody)
.build();
Response response = null;
try {
response = client.newCall(request).execute();
if (response.isSuccessful()) {
responseData = response.body().string();
LoginClass loginClass = new Gson().fromJson(responseData, LoginClass.class);
SharedPreferences sp = getSharedPreferences("loginToken", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("userName", javaBean.getName());
editor.putString("password", javaBean.getPassword());
editor.putString("Log_Information", loginClass.getData());
editor.apply();
Log.e("MainActivity", "+++++++++++" + loginClass.getData());
finish();
} else {
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).start();
}