小编Rad*_*ood的帖子

带有数字EditText字段的警报对话框

我正在通过具有EditText字段的警告对话框警告用户.

AlertDialog.Builder alert = new AlertDialog.Builder(this);
    db.open();
    Cursor f = db.getTitle(position + 1);
    alert.setTitle("Age");
    alert.setMessage("New age?");

    // Set an EditText view to get user input
    final EditText input = new EditText(this);
    alert.setView(input);
    input.setText(f.getString(3));
    db.close();
    alert.setPositiveButton("Change",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String age = input.getText().toString();
                    db.open();
                    Cursor ff = db.getTitle(position + 1);
                    db.updateTitle(ff.getLong(0), ff.getString(1),
                            ff.getString(2), age, ff.getString(4),
                            ff.getString(5));
                    db.close();
                    details();
                    age();
                }
            });

    alert.setNegativeButton("Keep", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // do …
Run Code Online (Sandbox Code Playgroud)

formatting android android-edittext android-alertdialog

3
推荐指数
1
解决办法
9865
查看次数

Android + MySQL使用com.mysql.jdbc.Driver

我正在编写一个将连接到MySQL服务器的Android应用程序.现在,我正在使用http:// localhost:3306 /通过XAMPP在我的计算机上测试MySQL服务器.以下代码严格地作为JAVA应用程序进行测试时可以正常工作.

import java.sql.*;

public class MySQL{
  public static void main(String[] args) {
    System.out.println("MySQL Connect Example.");
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "database";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password = "";
    try {
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url+dbName,userName,password);
      System.out.println("Connected to the database");
      conn.close();
      System.out.println("Disconnected from database");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是当我将它添加到我的Android应用程序时,我得到了Exception e错误.

// interact with MySQL!!!
 private View.OnClickListener onSendRequest = new View.OnClickListener() {
  @Override …
Run Code Online (Sandbox Code Playgroud)

java mysql android exception inner-classes

3
推荐指数
1
解决办法
3万
查看次数