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 6678375
In Process

The Archive Base Latest Questions

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

Activity: package hi.com; import android.app.Activity; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import

  • 0

Activity:

package hi.com;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class TestsqliteActivity extends Activity {
       /** Called when the activity is first created. */

    EditText inputContent1, inputContent2,inputContent3;
    Button buttonAdd, buttonDeleteAll;
    ListView listContent;

    Cursor cursor;
    SimpleCursorAdapter cursorAdapter;

    private handle mySQLiteAdapter;
    private SQLiteDatabase db;
    private static final String fields[] = {handle.KEY_ID,handle.COMPANY_NAME};
    private ContentValues conValues;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.asdasd);

        inputContent1 = (EditText)findViewById(R.id.content1);
        inputContent2 = (EditText)findViewById(R.id.content2);
        inputContent3 = (EditText)findViewById(R.id.content3);

        buttonAdd = (Button)findViewById(R.id.add);
        listContent = (ListView)findViewById(R.id.contentlist);

        mySQLiteAdapter = new handle(this);
        db = (new handle(this)).getWritableDatabase();
        Cursor data = db.query(handle.COMPANY_TABLE, fields, null, null, null, null, null);

        String[] from = new String[]{handle.COMPANY_NAME};
        int[] to = new int[]{R.id.text1};
        cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, data, from, to);
        listContent.setAdapter(cursorAdapter);

        buttonAdd.setOnClickListener(buttonAddOnClickListener);
    }

    Button.OnClickListener buttonAddOnClickListener
    = new Button.OnClickListener(){
        @Override
        public void onClick(View arg0) {

        saveRecords();
        }
    };


private void updateList() {
    // TODO Auto-generated method stub
      cursor.requery();
}


protected void saveRecords() {
    // TODO Auto-generated method stub

                conValues.put(handle.COMPANY_NAME, inputContent1.getText().toString());


                try {

                    db.insert(handle.COMPANY_TABLE, null, conValues);

                    Log.d("DDMS'ye", "kayit basarili degerini yaz.");

                } catch (SQLiteException e) {

                    Log.d("eHata", e.getLocalizedMessage());

                }

            }

}

Error

ERROR/AndroidRuntime(19930): java.lang.NullPointerException 10-05 12:01:31.302:
ERROR/AndroidRuntime(19930): at hi.com.TestsqliteActivity.saveRecords(TestsqliteActivity.java:75)
10-05 12:01:31.302: ERROR/AndroidRuntime(19930): at
hi.com.TestsqliteActivity$1.onClick(TestsqliteActivity.java:61) 10-05
12:01:31.302: ERROR/AndroidRuntime(19930): at
android.view.View.performClick(View.java:2408) 10-05 12:01:31.302:
ERROR/AndroidRuntime(19930): at
android.view.View$PerformClick.run(View.java:8816) 10-05 12:01:31.302:
ERROR/AndroidRuntime(19930): at
android.os.Handler.handleCallback(Handler.java:587) 10-05
12:01:31.302: ERROR/AndroidRuntime(19930): at
android.os.Handler.dispatchMessage(Handler.java:92) 10-05
12:01:31.302: ERROR/AndroidRuntime(19930): at
android.os.Looper.loop(Looper.java:123) 10-05 12:01:31.302:
ERROR/AndroidRuntime(19930): at
android.app.ActivityThread.main(ActivityThread.java:4627) 10-05
12:01:31.302: ERROR/AndroidRuntime(19930): at
java.lang.reflect.Method.invokeNative(Native Method) 10-05
12:01:31.302: ERROR/AndroidRuntime(19930): at
java.lang.reflect.Method.invoke(Method.java:521) 10-05 12:01:31.302:
ERROR/AndroidRuntime(19930): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-05 12:01:31.302: ERROR/AndroidRuntime(19930): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 10-05
12:01:31.302: ERROR/AndroidRuntime(19930): at
dalvik.system.NativeStart.main(Native Method)

Please advice me on what i have done wrong…. 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:14:08+00:00Added an answer on May 26, 2026 at 4:14 am

    Be sure, to initialize your SQLiteDatabase object and also open your database. Here is the idea of a DatabaseHelper Class. You can find appropriate code snippets for this class as well.

    public DatabaseHelper(Context aContext)
    {
    
        sqlDB = aContext.openOrCreateDatabase(DatabaseName, SQLiteDatabase.CREATE_IF_NECESSARY, null);
    
        OpenHelper openHelper = new OpenHelper(aContext, sqlDB);
    
        sqlDB = openHelper.getWritableDatabase();
    }
    

    Here sqlDB is your SQLiteDatabase object. And OpenHelper is a helper class to open your database.

    OpenHelper(Context context, SQLiteDatabase sql_db)
        {
            super(context, DatabaseName, null,DatabaseVersion);         
            onCreate(sql_db);
        }
    

    You can implement your own constructor and classes. Get more help on this. Its easy to implement and handle using a DatabaseHelper class.

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

Sidebar

Related Questions

I have created following activity package com.ali.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import
package com.geoo; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle;
package com.duncan.hello.world; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;
aka, what is wrong with this code:- package com.mez.appofjaq; import com.mez.appofjaq.RssParser.RssFeed; import android.app.Activity; import
I'm following http://developer.android.com/guide/topics/search/search-dialog.html to create a searchable activity for my app. SearchableActivity.java package com.xxxx.xx;
I wrote simple android app with bugs. When open second activity from menu- android
I have an Activity in Android, with two elements: EditText ListView When my Activity
I was reading over http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html But I'm really not grasping how to ignore certain
A couple of other people and me are working on an app for android.
My android app is supposed to go through twitter using twitter4j libraries, and return

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.