第一次在这里:)
我是一个完整的初学者,尝试学习制作android应用,但是我遇到了问题并且无法解决。
我正在运行下面的代码,当它运行“ StringRequest stringRequest”时,程序错误并且未运行代码,我希望它接下来可以运行。
这是在Android Studio上,我在线上查看了一些类似的条目,但是我还没找到任何地方...帮助:)
public void save(View v){
String name = etName.getText().toString();
SharedPreferences.Editor editor = sp.edit();
editor.putString(KEY_NAME, name);
editor.apply();
getSqlDetails();
Toast.makeText(this, "Saved!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, ReportaFault.class);
AddCustomerNumber.this.finish();
startActivity(intent);
}
private void getSqlDetails() {
String name = etName.getText().toString();
Log.e("eTName is:", name );
String url= "https://localhost/ConvertIDtoName.php?id="+name;
pd.show();
Log.e("URL is:", url );
StringRequest stringRequest = new StringRequest(Request.Method.GET,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
pd.hide();
Log.e("", "Check if it fails after PD" );
try {
JSONArray jsonarray = new JSONArray(response);
for(int i=0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String fullname = jsonobject.getString("fullname");
Log.e("fullname is:", fullname );
//result.setText(id + fullname);
SharedPreferences.Editor editor = sp.edit();
editor.putString(KEY_ID, fullname);
editor.apply();
Log.e("key_id is:", fullname );
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(error != null){
Toast.makeText(getApplicationContext(), "Something went wrong.", Toast.LENGTH_LONG).show();
}
}
}
);
}
2019-05-15 19:49:41.845 19997-19997/faultlogforandroid E/eTName is:: testuser
2019-05-15 19:49:42.205 19997-19997/faultlogforandroid E/URL is::
https://localhost/ConvertIDtoName.php?id=testuser
2019-05-15 19:49:47.310 19997-19997/faultlogforandroid E/WindowManager: android.view.WindowLeaked: Activity faultlogforandroid.AddCustomerNumber has leaked window DecorView@d7ffc93[AddCustomerNumber] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:627)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
at android.app.Dialog.show(Dialog.java:342)
at faultlogforandroid.AddCustomerNumber.getSqlDetails(AddCustomerNumber.java:101)
at faultlogforandroid.AddCustomerNumber.save(AddCustomerNumber.java:85)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:7251)
at android.view.View.performClickInternal(View.java:7228)
at android.view.View.access$3500(View.java:802)
at android.view.View$PerformClick.run(View.java:27843)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7116)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)