简体   繁体   中英

android studio claims this class is abstract, how and why is this class abstract?

My class dose not have a abstract keyword before the class keyword in the class declaration, but when i tried to instantiate the class on an activity it tells me class is abstract; can not be instantiated class is abstract; can not be instantiated .

This makes no sense because it doesn't look like an abstract class to me. please help me figer out what I'm doing wrong and how I can fix it

The error is at new ConnectionClass()

Here is the class 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;
    }

    }

Here is the activity activity_connection

public class ConnectionActivity extends AppCompatActivity {

    ConnectionClass connectionClass;
    EditText edtuserid,edtpass;
    Button btnlogin;
    ProgressBar pbbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_connection);

        connectionClass = new ConnectionClass();
        edtuserid = (EditText) findViewById(R.id.edtuserid);
        edtpass = (EditText) findViewById(R.id.edtpass);
        btnlogin = (Button) findViewById(R.id.btnlogin);
        pbbar = (ProgressBar) findViewById(R.id.pbbar);
        pbbar.setVisibility(View.GONE);

        btnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DoLogin doLogin = new DoLogin();
                doLogin.execute("");

            }
        });

    }

I am assuming you are getting the error at new ConnectionClass() .

There seems no need to have a final class. Add a constructor just to be sure also. You might have meant that you needed a static class with static methods.

Use this instead:

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() {
            ....
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM