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

  • Home
  • SEARCH
  • 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 6683831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:52:05+00:00 2026-05-26T04:52:05+00:00

I am having problem with inserting string values (user_name, password) into a table, named

  • 0

I am having problem with inserting string values (user_name, password)
into a table, named login.
Here are the codes:
I have added “//THIS IS WHERE THE PROBLEM OCCURS” comment to highlight the problem…the DBAdapter class which is containing all the database-related methods, are also given after this code..

package images.tests.proj;

import java.io.IOException;
import images.tests.proj.DBAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.database.Cursor;

public class username extends Imagetest1Activity {
    /** Called when the activity is first created. */
    private DBAdapter db1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.username);
        Button lbtn = (Button) findViewById(R.id.loginb);
        Button rbtn = (Button) findViewById(R.id.registerb);
        final EditText utext = (EditText) findViewById(R.id.utext);
        final EditText ptext = (EditText) findViewById(R.id.ptext);
        db1 = new DBAdapter(this);
        rbtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                String ut = utext.getText().toString();
                String pt = ptext.getText().toString();
                try {
                    // THIS IS WHERE THE PROBLEM OCCURS
                    db1.insertContact(ut, pt);

                } catch (NullPointerException e) {
                    Toast.makeText(username.this, "Error", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
}

The DBAdapter class contains the insertContact method as follows:

//---insert a contact into the database---
public long insertContact(String user_name, String password)
{
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_USERNAME, user_name);
    initialValues.put(KEY_PASSWORD, password);
    return db.insert(DATABASE_TABLE, null, initialValues);
}

Could you point out the mistake?
Any help would be appreciable. Thank you!

  • 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-05-26T04:52:05+00:00Added an answer on May 26, 2026 at 4:52 am

    You need to have opened database that can be writeable in the DBAdapter class:

    Try:

     public long insertContact(String user_name, String password)
    {
    db= this.getWritableDatabase();
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_USERNAME, user_name);
    initialValues.put(KEY_PASSWORD, password);
    return db.insert(DATABASE_TABLE, null, initialValues);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange problem in that I have php inserting text into a
Hi i am having problem inserting data into multiple table from one view. First
Having trouble inserting new records into a table. Anybody care to help? <?php include('config.php');
I was having problems inserting a string into the following tag : <tr id=rowBulkOptions
I have a multilingual site and I am having a problem inserting Chinese meta
We are having problem with the server migration. We have one application that are
I'm having problem when running my Windows Forms program. In the program, I have
I am having a problem getting the FormView Control in Visual Studio 2010 inserting
I'm having problems inserting a particular line of code into my MySQL database. It
I'm currently having difficulty inserting a node into a binary tree using recursion. I've

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.