android studio声称这个类是抽象的,这个类是如何以及为什么抽象的?

时间:2017-02-06 18:39:13

标签: java android

我的类在类声明中的class关键字之前没有抽象关键字,但是当我尝试在活动上实例化它时,它告诉我WHERE NetworkAddress = @Address & NetworkSubnet

这没有任何意义,因为它对我来说看起来不像是一个抽象类。请帮我弄清楚我做错了什么以及如何解决它

错误发生在class is abstract; can not be instantiated

这是班级new ConnectionClass()

ConnectionClass

以下是活动final public class ConnectionClass { String ip = ""; String classs = "net.sourceforge.jtds.jdbc.Driver"; String db = "tmseprd"; String un = ""; String password = ""; @SuppressLint("NewApi") public Connection CONN() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .permitAll().build(); StrictMode.setThreadPolicy(policy); Connection conn = null; String ConnURL = null; try { Class.forName(classs); ConnURL = "jdbc:jtds:sqlserver://" + ip + ";" + "databaseName=" + db + ";user=" + un + ";password=" + password + ";"; conn = DriverManager.getConnection(ConnURL); } catch (SQLException se) { Log.e("ERRO", se.getMessage()); } catch (ClassNotFoundException e) { Log.e("ERRO", e.getMessage()); } catch (Exception e) { Log.e("ERRO", e.getMessage()); } return conn; } }

activity_connection

1 个答案:

答案 0 :(得分:0)

我假设您在new ConnectionClass()收到错误。

似乎没有必要进行最后的课程。添加构造函数也是为了确保。您可能意味着需要使用静态方法的静态类。

请改用:

public class ConnectionClass {
        String ip = "";
        String classs = "net.sourceforge.jtds.jdbc.Driver";
        String db = "tmseprd";
        String un = "";
        String password = "";

        public ConnectionClass(){}

        @SuppressLint("NewApi")
        public Connection CONN() {
            ....
        }
}