gpt4 book ai didi

java - Android MySQL连接教程

转载 作者:行者123 更新时间:2023-11-30 22:21:05 24 4
gpt4 key购买 nike

我使用了本教程 (https://www.simplifiedcoding.net/android-mysql-tutorial-to-perform-basic-crud-operation/) 并且一切正常,但是当我单击“查看员工”按钮时,它显示一个空白屏幕。有谁知道出了什么问题吗?

我的OneEvent.java类(教程中的ViewEmployee.java)

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) {

}
}

配置.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";
}

最佳答案

Juliano 所说,因为您的 URL 不正确,所以从服务器请求它时您什么也得不到。

 public static final String URL_GET_EMP = "http://diplomandroid.esy.es/get_event_details.php.?id=";

应该是:

 public static final String URL_GET_EMP = "http://diplomandroid.esy.es/get_event_details.php?id=";

关于java - Android MySQL连接教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36608059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com