I used this tutorial ( https://www.simplifiedcoding.net/android-mysql-tutorial-to-perform-basic-crud-operation/ ) and everything was alright, but when I clicked on the View Employee button, it showed an empty screen. Does anyone know what's wrong?
My OneEvent.java class ( ViewEmployee.java in the tutorial)
public class OneEvent extends AppCompatActivity implements View.OnClickListener {
private TextView tvId, tvTitle, tvDate, tvTime, tvAddress, tvPhone, tvDescription;
private String id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.one_event);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
id = intent.getStringExtra(Config.EVENT_ID);
tvId = (TextView) findViewById(R.id.tvId);
tvTitle = (TextView) findViewById(R.id.tvEventTitle);
tvDate = (TextView) findViewById(R.id.tvEventDate);
tvTime = (TextView) findViewById(R.id.tvEventTime);
tvAddress = (TextView) findViewById(R.id.tvEventAddress);
tvPhone = (TextView) findViewById(R.id.tvEventPhone);
tvDescription = (TextView) findViewById(R.id.tvEventDescription);
tvId.setText(id);
getEvent();
}
private void getEvent(){
class GetEvent extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(OneEvent.this,"Loading...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
showEvent(s);
}
@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequestParam(Config.URL_GET_EMP,id);
return s;
}
}
GetEvent ge = new GetEvent();
ge.execute();
}
private void showEvent(String json){
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
JSONObject c = result.getJSONObject(0);
String title = c.getString(Config.TAG_TITLE);
String date = c.getString(Config.TAG_DATE);
String time = c.getString(Config.TAG_TIME);
String address = c.getString(Config.TAG_ADDRESS);
String phone = c.getString(Config.TAG_PHONE);
String description = c.getString(Config.TAG_DESCRIPTION);
tvTitle.setText(title);
tvDate.setText(date);
tvTime.setText(time);
tvAddress.setText(address);
tvPhone.setText(phone);
tvDescription.setText(description);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
}
}
Config.java
public class Config {
public static final String URL_ADD="http://diplomandroid.esy.es/create_event.php";
public static final String URL_GET_ALL = "http://diplomandroid.esy.es/get_all_events.php";
public static final String URL_GET_EMP = "http://diplomandroid.esy.es/get_event_details.php.?id=";
public static final String EVENTS_COLUMN_ID = "_id";
public static final String EVENTS_COLUMN_TITLE = "title";
public static final String EVENTS_COLUMN_DATE = "date";
public static final String EVENTS_COLUMN_TIME = "time";
public static final String EVENTS_COLUMN_ADDRESS = "address";
public static final String EVENTS_COLUMN_PHONE = "phone";
public static final String EVENTS_COLUMN_DESCRIPTION = "description";
public static final String TAG_JSON_ARRAY= "result";
public static final String TAG_ID = "_id";
public static final String TAG_TITLE = "title";
public static final String TAG_DATE = "date";
public static final String TAG_TIME = "time";
public static final String TAG_ADDRESS = "address";
public static final String TAG_PHONE = "phone";
public static final String TAG_DESCRIPTION = "description";
public static final String EVENT_ID = "event_id";
}
As said by Juliano , you're not getting anything when requesting it from the server because your URL is incorrect.
public static final String URL_GET_EMP = "http://diplomandroid.esy.es/get_event_details.php.?id=";
should be:
public static final String URL_GET_EMP = "http://diplomandroid.esy.es/get_event_details.php?id=";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.