2014-10-28 23 views
0

我正在編程一個連接到MySQL服務器的android應用程序,到目前爲止我擁有它,因此用戶可以輸入服務器IP,數據庫名稱,用戶名和密碼並將其存儲到手機中。我試圖從用戶剛剛輸入的信息中建立一個字符串,以便在保存到.txt文件之前測試連接。我知道這可能是在我的面前,但一天後,我卡住了,請幫助!問題是位於「TestButtonListener」試圖將信息從Android應用程序中的4個字段傳遞給Java中的字符串以便在保存信息之前測試連接

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(); 

     } 
    }); 
} 
+0

你的代碼太長。想要幫助你,但不想閱讀所有這些行以找到問題......你能提供重要且唯一有用的線路嗎? – mithrop 2014-10-28 14:20:42

+0

你在文件中存儲什麼?數據庫用戶名和傳球?爲什麼不把它們存儲在應用程序偏好中? – Yazan 2014-10-28 14:42:48

+0

我試圖抓取用戶輸入的信息,以確保它在保存之前能夠正常工作。 – Glenn 2014-10-28 20:08:40

回答

0

不要打擾,我想通了,如何與.getText()修復它。toString()和之後所有來了解一下Android不一起工作jdbc連接器。