在保存信息之前,尝试将Android应用程序中4个字段的信息传递到java中的字符串,以测试连接
我正在编写一个android应用程序,连接到MySQL服务器,到目前为止,我已经有了它,用户可以输入服务器ip、数据库名称、用户名和密码,并将其存储到手机上。在保存到.txt文件之前,我正在尝试根据用户刚刚输入的用于测试连接的信息构建一个字符串。我知道它可能就在我面前,但在这一天之后,我被卡住了,请帮帮我!!问题位于“TestButtonListener”中在保存信息之前,尝试将Android应用程序中4个字段的信息传递到java中的字符串,以测试连接,java,android,mysql,Java,Android,Mysql,我正在编写一个android应用程序,连接到MySQL服务器,到目前为止,我已经有了它,用户可以输入服务器ip、数据库名称、用户名和密码,并将其存储到手机上。在保存到.txt文件之前,我正在尝试根据用户刚刚输入的用于测试连接的信息构建一个字符串。我知道它可能就在我面前,但在这一天之后,我被卡住了,请帮帮我!!问题位于“TestButtonListener”中 public class AppInfo extends Activity { public static final String D
public class AppInfo extends Activity {
public static final String DEBUGTAG = "It's Broke";
public static final String DATABASEPASSWORD = "pinfo.txt";
public static final String SERVERIP = "sinfo.txt";
public static final String DATABASEUSER = "ninfo.txt";
public static final String DATABASE = "dinfo.txt";
public static final String FILESAVED = "filesaved";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_info);
addTestButtonListener();
///Test connection
private void addTestButtonListener() {
Button test = (Button) findViewById(R.id.testcon);
test.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
///need information from the R.id.server, R.id.database, R.id.name, R.id.pword
/// and insert it into the string as serverIp, dataBase, name, pword.
///
try {
/// everything I've tried in here spits out the name of the text file,
/// or the memory address, but not the value just typed in.
}
String serverConnect = new String("jdbc:mysql://" + serverIp
+ "/" + dataBase + ", " + name + ", " + pword);
Toast.makeText(AppInfo.this, serverConnect, Toast.LENGTH_LONG)
.show();
}
});
}
不用麻烦了,我已经找到了如何用.getText().toString()修复它的方法,并且最终发现Android不能与jdbc连接器一起工作。您的代码片段太长了。很想帮助你,但不想阅读所有这些行来发现问题。。。你能提供重要且唯一有用的行吗?你在文件中存储了什么?db用户名和密码?为什么不将它们存储在应用程序首选项中呢?我正在尝试获取用户刚刚输入的信息,以确保在保存之前它能正常工作。