我正在开发一个Android聊天应用程序,我是一个web服务,它操纵一个sql server数据库和移动应用程序分离,在移动应用程序中,我的片段(主页,编辑个人资料) ,注销),在编辑配置文件片段中我希望edittext预先填充来自数据库的帐户所有者的信息,所以我将app_login从应用程序发送到webservice,webservice返回一个用户对象,这样我就可以他预先填充edittext的信息,所以这里是webservice的代码:
public synchronized void modifierProfil(String login) {
try {
stmt = con.prepareStatement("Select * from Utilisateurs where login = '" + login + "';");
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
Utilisateur user = new Utilisateur();
user.setLogin(rs.getString("login"));
user.setPassword(rs.getString("password"));
user.setEmail(rs.getString("email"));
user.setDateNaissance(rs.getDate("dateNaissance"));
user.setNomPersonne(rs.getString("nomPersonne"));
user.setPrenomPersonne(rs.getString("prenomPersonne"));
user.setNumTelephone(rs.getInt("numTelephone"));
user.setPhotoProfil(rs.getString("photoProfil"));
user.setSexe(rs.getString("sexe"));
env.setObjet(user);
reponse = "ok";
}
} catch (Exception ex) {
reponse = "erreur";
} finally {
try {
env.setAction(reponse);
TCPConnection.send(env, acceptedSocket);
acceptedSocket.close();
} catch (IOException ex1) {
}
}
}
以及配置文件片段代码:
public static class ProfilFrag extends Fragment implements OnClickListener {
ImageView photoProfil;
EditText username, email, password, nomPrenom;
String UserName, Pwd, Email;
Button submit, changerPhoto;
ModifierProgress connection ;
private DatagramPacket sendP;
private DatagramPacket receiveP;
private DatagramSocket socket;
private int serverPort;
private String send;
public static String serverIP;
private byte data2[];
private SharedPreferences settings;
String rdata;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
connection = new ModifierProgress();
connection.execute();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
username = (EditText) getView().findViewById(R.id.etLogin);
email = (EditText) getView().findViewById(R.id.edEmail);
password = (EditText) getView().findViewById(R.id.edPassword);
nomPrenom = (EditText) getView().findViewById(R.id.edNomPrenom);
submit = (Button) getView().findViewById(R.id.bSubmit);
photoProfil = (ImageView) getView().findViewById(R.id.largeThumbnailView);
changerPhoto = (Button) getView().findViewById(R.id.btnChanger);
submit.setOnClickListener(this);
changerPhoto.setOnClickListener(this);
data2 = new byte[100];
serverPort = 6500;
settings = PreferenceManager
.getDefaultSharedPreferences(Home.current);
serverIP = settings.getString("serverIP", Connection.ipServer);
Log.i("Login", serverIP);
}
private class ModifierProgress extends AsyncTask<Void, String, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
***String un*** = username.getText().toString();
Envoyable env = new Envoyable(un, "modifierProfil");
Socket sock = TCPConnection.send(env);
Log.i("modifierProfil", "modification Profil");
env = (Envoyable) TCPConnection.Receive(sock);
String rep = env.getAction();
Log.i("modifierProfil", "received msg from server: " + rep);
publishProgress("modification");
if (rep.equalsIgnoreCase("ok")){
Utilisateur m = (Utilisateur) env.getObjet();
Utils.Helper.saveUser(settings, "m", m);
getActivity().finish();
UrlImageViewHelper.setUrlDrawable(photoProfil, m.getPhotoProfil());
username.setText(m.getLogin());
password.setText(m.getPassword());
email.setText(m.getEmail());
}
else if (rep.equalsIgnoreCase("erreur")){
publishProgress("err");
Toast.makeText(getActivity().getApplicationContext(), "Une erreur s'est produite", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}
属性&#34; un&#34;获取始终为空值,即使直接在其上放置值,也不会预编译edittext。 那么问题出在哪里?
答案 0 :(得分:0)
您正在致电
在OnCreate方法中connection.execute();
不要打电话给他们。在找到所有edittext和按钮的ID后调用它。