1

Hey Folks am making a simple application in which ill insert two accounts manually into a table for the login authentication and then after that ill do some working based on the accounts type. Am having issues in setting up Sqlite functions. I have one package com.example.emp_management and in it i have 2 classes MainActivity.java and Database_Wrap.java. Code for the Database_Wrap.java is given below:

package com.example.emp_management;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class Database_Wrap            //hotornot
{
public static final String Database_name = "Employee_Managament_System";
public Sql_Lite_Work OurHelper;
public  final Context OurContext;
public SQLiteDatabase ourDatabase;

public static class Sql_Lite_Work extends SQLiteOpenHelper
{   //dbhelper = sql_lite_work

    public Sql_Lite_Work(Context context) 
    {
        super(context,Database_name , null, 1);
        // TODO Auto-generated constructor stub
    }
    @Override
    public void onCreate(SQLiteDatabase db)
    {
        // TODO Auto-generated method stub

        db.execSQL("CREATE TABLE" + "Login_Authentication"+ "(" +
               "ID" + "INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "UserName" + "TEXT NOT NULL," +
               "Password" + "TEXT NOT NULL);"                   
                );

    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        // TODO Auto-generated method stub

        db.execSQL("DROP TABLE IF EXISTS " + "Login_Authentication");
        onCreate(db);
    }


}
public Database_Wrap(Context c)
{
    OurContext = c;
}
public Database_Wrap Open()
{
    OurHelper = new Sql_Lite_Work(OurContext);
    ourDatabase = OurHelper.getWritableDatabase();
    return this;
}
public void close()
{
    OurHelper.close();
}
}

Now next thing i want to do is in my mainactivity i want to do something like:

Database_Wrap entry= new Database_Wrap(MainActivity.this);

and then acces the function written in Database_Wrap to open the database and write the values into table for admin and other users:

entry.Open();

but in eclipse am not able to access open function on entry. I dnt know what is wrong here. Am a beginer. May be am forgetting something. Kindly have a look thankyou!

2
  • the point is when i write entry. i get nothing in eclipse so .Open or .open is not the point here :) Commented Feb 17, 2013 at 15:20
  • 1
    @GreenGuerilla methods in Java start with lower-case (Java convention). Commented Feb 17, 2013 at 15:28

2 Answers 2

1

Java is case sensitive. Try:

Database_Wrap entry= new Database_Wrap(MainActivity.this);

Both your ws in Wrap were lower case.

Sign up to request clarification or add additional context in comments.

2 Comments

i have correct my question the things you are pointing out are already handled in my code. there is this something else which am not able to spot out
@Alfred Check under the problems tab in eclipse for a more exact error message
0

I just put your code into a small test project. It compiles just fine. I then added this code, in an Activity in the same project:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Database_Wrap entry= new Database_Wrap(MainActivity.this);
    entry.Open();
}

That too, works just fine.

Judging by the appearance of the code (nothing at all wrong with it, just that the style makes experienced Java devs cringe), you are new to Java; probably eclipse too. Eclipse is weird and does funky stuff all the time. Perhaps you've just encountered some short term anomaly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.