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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:23:43+00:00 2026-06-14T03:23:43+00:00

I keep getting this error java.null.pointer exception When ever i trie to run this

  • 0

I keep getting this error java.null.pointer exception When ever i trie to run this code please help me how to solve this problem and update my database values.
Here is my code
Main activity class

package dom.example.database_exp;

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.widget.EditText;

public class MainActivity extends Activity {


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

  MainActivity obj = new MainActivity();

    SQLiteDatabase db =openOrCreateDatabase("Test", MODE_PRIVATE, null);
    obj.Update(1, "Raza", "17", "Nohting"); 
  Cursor c = db.rawQuery("SELECT FirstName FROM test WHERE ID = 1 ",null);
  c.moveToFirst();
  EditText dis=(EditText)findViewById(R.id.editText1);
  String  result =  c.getString(c.getColumnIndex("FirstName")); 

   dis.setText("You have found "+result);

   db.close();

    /**    EditText dis=(EditText)findViewById(R.id.editText1);
       //Creating and opening the  database
     SQLiteDatabase db=openOrCreateDatabase("RamDB", MODE_PRIVATE,null);
     //Creating table with 3 columns
     db.execSQL("CREATE TABLE IF NOT EXISTS Test(ID INTEGER PK NOT NULL FirstName      VARCHAR,LastName VARCHAR,Age INT(3));");
                 **/

  }



 public int Update (int sid, String name, String age, String course)
  {
    String FirstName = "FirstName";
    String LastName = "LastName";
    String test = "test";
    String ID = "ID";
    // String _id = "1" ;
    SQLiteDatabase db =openOrCreateDatabase("Test", MODE_PRIVATE, null);
    ContentValues pau = new ContentValues();
    pau.put(FirstName, name);



   return db.update(test, pau,ID + "=" + sid, null);

   }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
     return true;
   }
   }

My xml file

   <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="51dp"
    android:layout_marginTop="89dp"
    android:ems="10"
    android:inputType="text" >

    <requestFocus />
     </EditText>

    </RelativeLayout>
  • 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-14T03:23:44+00:00Added an answer on June 14, 2026 at 3:23 am

    we need the stack trace to check where is the error. though the constuctor call MainActivity obj = new MainActivity(); within your OnCreate method seems really strange. As far as I know you do not need to call the constructor of you Activity

    and you can refer to your activity call this

    Try to remove the MainActivity obj = new MainActivity(); and this.Update(1, "Raza", "17", "Nohting"); also there is no need to run openOrCreateDatabase twice, you are running it on the OnCreate and on the method.

    In any case, check your trace adb logcat to have a better understanding where the code is failing.

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

Sidebar

Related Questions

I keep getting this error when I compile and run my Java program using
In the code below I keep getting a null exception error and have tested
I keep getting this error with my Play 2.0 application: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError:
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I keep getting a stack overflow error when I run this short program I
I keep getting this error 07-14 23:53:03.653: ERROR/AndroidRuntime(14995): java.lang.NullPointerException 07-14 23:53:03.653: ERROR/AndroidRuntime(14995): at com.fttech.organizeit.meeting_list$meetingHolder.populateFrom(meeting_list.java:110)
I keep getting this error: java.lang.NoClassDefFoundError: org/apache/lucene/index/memory/MemoryIndex Is there any way i can go
I keep getting this error 07-28 19:32:40.536: ERROR/error(534): java.io.IOException: No such file or directory
I keep getting this error? 07-25 17:04:00.796: ERROR/AndroidRuntime(420): Caused by: java.lang.OutOfMemoryError 07-25 17:04:00.796: ERROR/AndroidRuntime(420):
Why do I keep getting this error: javax.servlet.ServletException: java.sql.SQLException: [Oracle][ODBC][Ora]ORA-00904: PURCHASE_PRICE: invalid identifier As

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.