Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:59:12+00:00 2026-06-09T14:59:12+00:00

here i tried to take name and password from database if the user have

  • 0

here i tried to take name and password from database if the user have already an account, or sign up him by enter his data.

This is the first activity which has force close by clicking on first button to log into the data base

public class SelesMeter2Activity extends Activity implements OnClickListener {
    EditText ed1;
    EditText ed2;
    Button b1;
    Button b2;
    SQLiteDatabase sql;
    Cursor c;
    Intent in;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ed1 = (EditText) findViewById(R.id.ed1);
        ed2 = (EditText) findViewById(R.id.ed2);
        b1 = (Button) findViewById(R.id.bt1);
        b2 = (Button) findViewById(R.id.bt2);
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
        sql = openOrCreateDatabase("db", 0, null);
        sql.execSQL("CREATE TABLE if not exists "
                + "Employee2 (password integer NOT NULL PRIMARY KEY,name text NOT NULL)");
    }

    @Override
    public void onClick(View arg0) {
        // log in
        if (arg0.getId() == R.id.bt1) {
            int p = 0;
            String name = ed1.getText().toString();
            String sp = ed2.getText().toString();
            try {
                // Attempt to parse the number as an integer
                p = Integer.parseInt(sp);
            } catch (NumberFormatException nfe) {
                // parseInt failed, so tell the user it's not a number
                Toast.makeText(this,
                        "Sorry, " + sp + " is not a number. Please try again.",
                        Toast.LENGTH_LONG).show();
            }
            if (c.getCount() != 0) {
                c = sql.rawQuery("select * from Employee", null);
                while (c.moveToNext()) {
                    if (name.equals("c.getString(1)") && p == c.getInt(0)) {
                        in = new Intent(this, secondview.class);
                        startActivity(in);
                        break;
                    }
                }
            }

            else {
                Toast.makeText(this,
                        "please sign up first or enter " + "correct data", 2000)
                        .show();
            }

        } else if (arg0.getId() == R.id.bt2) {
            // sign up
            Intent in2 = new Intent(this, signup.class);

            startActivity(in2);

        }
    }
}

the second class that enter the new user which is not working as expected,
the toast does not work :

public class signup extends Activity implements OnClickListener {
    EditText e1;
    EditText e2;
    SQLiteDatabase sql;
    Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.singupx);
        Intent in = getIntent();
        e1 = (EditText) findViewById(R.id.ed1s);
        e2 = (EditText) findViewById(R.id.ed2s);
        b = (Button) findViewById(R.id.bt1s);
        b.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String n = e1.getText().toString();
        String sp = e2.getText().toString();
        try {
            // Attempt to parse the number as an integer
            int p = Integer.parseInt(sp);
            // This insertion will *only* execute if the parseInt was successful
            // sql.execSQL("insert into Employee2(password,name)values('"+n+"',"+p+")");
            ContentValues values = new ContentValues();
            values.put("password", p);
            values.put("name", n);
            sql.insert("Employee2", null, values);
            Toast.makeText(this, "Data inserted", Toast.LENGTH_LONG).show();
            Intent in2 = new Intent(this, secondview.class);
            startActivity(in2);
        } catch (NumberFormatException nfe) {
            // parseInt failed, so tell the user it's not a number
            Toast.makeText(this,
                    "Sorry, " + sp + " is not a number. Please try again.",
                    Toast.LENGTH_LONG).show();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:59:14+00:00Added an answer on June 9, 2026 at 2:59 pm

    In the SelesMeter2Activity you’ll have a NullPointerException at the line:

    if (c.getCount() != 0) {
    

    as you don’t initialize the Cursor before that line. Move the query before the above line:

    c = sql.rawQuery("select * from Employee", null);
    if (c.getCount() != 0) {
         // ...
    

    You should post the exception you get from the logcat.

    Also regarding your signup activity please don’t instantiate the first activity to access fields from it. Open the database again in the second activity and insert the values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked on here and tried every answer available, but it is still
Here is what I have tried thus far: > cd /Applications/MAMP/bin/php5/bin/ > ./pear channel-discover
In the below code snippet, the intention is to take value for name from
here am trying to take the set of database values as comma separated and
I have tried solving this problem by posting other related questions here that focused
I have made a flash webcam application to allow the user to take a
I have written a small script with which I take the name of a
all i want to take number from phonebook of android in my application database..
I have a working excel vba macro that does what I want from here
Has anyone here tried to use a custom animation with MBProgressHUD. There is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.