Aisha Alkateeb Aisha Alkateeb - 2 months ago 10
Android Question

cannot resolve constructor 'class_name(java.lang.String)'

I'm trying to store data in database when clicking add button but an error appears when I created an object in MainActivity.java class with database class as shown enter image description here

Answer

Ok. If you want to make this work, add a constructor something like this:

public class Database {
   public Database(String abc){
    //blah blah
   }
}

And follow naming conventions - Class names should start with capital letters. Constructors should do the same thing. And its not just humans who'll have a problem with this, IDEs will poke you about this as well. So the code you've written should look like this:

Database database = new Database(course.getText());
Database database1 = new Database("xyz");

For naming conventions, refer to http://www.oracle.com/technetwork/java/codeconventions-135099.html

Comments