Android中获取参数值有问题



我有一个异步键的问题,它没有得到到达onCreate方法的参数。你知道问题出在哪里吗?在Android中获取参数值有问题代码如下:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_unos);
getSupportActionBar().hide();
context = this;
Bundle extras = getIntent().getExtras();
username = extras.getString("username");
password = extras.getString("password");
Intent intent = getIntent();
voznja = (Voznja) intent.getSerializableExtra("voznja");
voznjaId = voznja.getId();
System.out.println(voznjaId);//it works here


public class Home extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... strings) {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new FormBody.Builder()
.add("voznja_id", voznja.getId())//but i get null here, dont know why//
.build();
Request request = new Request.Builder()
.url("http://www.autotrack.rs/android_juzna_backa/get_voznja.php?")
.method("POST", body)
.build();
try {
response = client.newCall(request).execute();
//                System.out.println(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
return "";
}

protected void onPostExecute(String unused) {
try {
String rezultat = response.body().string();
//System.out.println(rezultat);
Gson gson = new Gson();
Type type = new TypeToken<Data>() {
}.getType();
Data data = gson.fromJson(rezultat, type);
// System.out.println(model);//
//listaVoznjiAL.add(data.data);
//adapter.notifyDataSetChanged();
Intent i = new Intent(Unos.this, Landing.class);
i.putExtra("data",data);
i.putExtra("voznja", voznja);
i.putExtra("username", username);
i.putExtra("password", password);
startActivity(i);
} catch (Exception m) {
m.printStackTrace();
}
}
}

ERROR: Caused by: java.lang.NullPointerException: Parameter specified非空为null:方法kotlin.jvm.internal.Intrinsics.checkNotNullParameter,参数值

看起来你的AsyncTask在onCreate之前执行。

你在哪里调用AsyncTask?

相关内容

  • 没有找到相关文章

最新更新