Error encountered while adding data to SQLite database in android

Attempting to insert data into an sqLite database upon button OnClick is resulting in the following exception:

Logcat:

03-24 17:54:14.773: D/AndroidRuntime(1579): --------- beginning of crash
03-24 17:54:14.774: E/AndroidRuntime(1579): FATAL EXCEPTION: main
03-24 17:54:14.774: E/AndroidRuntime(1579): Process: com.snappy.stevekamau.cosmeticsapp, PID: 1579
03-24 17:54:14.774: E/AndroidRuntime(1579): java.lang.IllegalStateException: Could not execute method of the activity
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View$1.onClick(View.java:4007)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View.performClick(View.java:4756)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View$PerformClick.run(View.java:19749)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.os.Handler.handleCallback(Handler.java:739)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.os.Handler.dispatchMessage(Handler.java:95)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.os.Looper.loop(Looper.java:135)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Native Method)
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Method.java:372)
03-24 17:54:14.774: E/AndroidRuntime(1579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-24 17:54:14.774: E/AndroidRuntime(1579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-24 17:54:14.774: E/AndroidRuntime(1579): Caused by: java.lang.reflect.InvocationTargetException
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Native Method)
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Method.java:372)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View$1.onClick(View.java:4002)
03-24 17:54:14.774: E/AndroidRuntime(1579): ... 10 more
03-24 17:54:14.774: E/AndroidRuntime(1579): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference
03-24 17:54:14.774: E/AndroidRuntime(1579): at com.snappy.stevekamau.cosmeticsapp.Details.run(Details.java:83)
03-24 17:54:14.774: E/AndroidRuntime(1579): ... 13 more
I am facing this issue while trying to save data in the database and display it in MyBasket Activity. Any assistance would be greatly appreciated. Below is the code snippet:

DBHelper:

public class DBHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "MyDBName.db";
    public static final String CONTACTS_TABLE_NAME = "contacts";
    public static final String CONTACTS_COLUMN_ID = "id";
    public static final String CONTACTS_COLUMN_NAME = "name";
    public static final String CONTACTS_COLUMN_EMAIL = "email";
    public static final String CONTACTS_COLUMN_PHONE = "phone";

    private HashMap hp;

    public DBHelper(Context context)
    {
        super(context, DATABASE_NAME , null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(
                "create table contacts " +
                        "(id integer primary key, title text,phone text,email text)"
        );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS contacts");
        onCreate(db);
    }

    public boolean insertContact  (String name, String phone, String email)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();

        contentValues.put("title", name);
        contentValues.put("amount", phone);
        contentValues.put("description", email);


        db.insert("contacts", null, contentValues);
        return true;
    }
    ...

}

MyBasket.java:

public class MyBasket extends ActionBarActivity {
    private ListView obj;
    DBHelper mydb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_basket);
        Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);

        getSupportActionBar().setHomeButtonEnabled(true);
        ...
    }

Details.java:

public class Details extends ActionBarActivity {
    ...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        ...
    }

    public void run(View view) {
        ...
    }
    ...

}

Answer №1

An error occurred: java.lang.NullPointerException: Trying to call a method on an object that is not initialized. Look at Line 83 in Details.java for more information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Continuously update in JavaScript based on a condition, cease updating when the condition no longer

I have a scenario on my page where specific data needs to be refreshed every minute, but at the same time, the user should be able to view and edit certain modals. I want to ensure that when a modal is open, the data refreshes are paused so that the modal ...

What is the correct way to include URL parameters within an AJAX data object?

I'm experiencing a strange issue that I can't seem to solve. My application makes use of AJAX to access JSON data. I am utilizing the platform's built-in parameter support to filter by category and tag. The format that is currently functiona ...

Using a Java application to provide a parameter to the Duckling Clojure function

While working with wit.ai's Duckling (https://duckling.wit.ai/), I find myself relying on and invoking Duckling from within my Java application. Despite having no experience with Clojure... I can successfully execute Duckling's parse method, but ...

Fancybox may be difficult to spot when using Safari

Currently, I am utilizing fancybox with the latest versions of jquery.min.js (3.3.1), jquery.fancybox.css (3.5.7), and jquery.fancybox.pack.js (3.5.7). Everything is functioning as expected on all browsers except for Safari. On Safari, the content within ...

Struggling to make the custom javascript toggle switch function properly

I've been attempting to create a switch that, when clicked, toggles between "ski" and "snowboard." My JavaScript code seems like it should work, but for some reason, nothing is happening. function toggleDisplay(a,b){ document.getElementById(a).sty ...

Removing a row by its id in VueJs using the splice method

After successfully deleting an item from the database, I am facing an issue where the item is not being removed from the list. I understand that I should use the index to splice the item from the list. However, using the index means I cannot pass the it ...

Creating a sticky v-stepper-header while scrolling in VuetifyJS

Can anyone help me figure out how to make the <v-stepper-header> component stay sticky when scrolling? I attempted to create custom CSS for this but was unsuccessful. Below is a snippet of code that I tried: <v-stepper v-model="step"&g ...

Converting numbers to strings based on locale in React Native

I have a quantity that, when using the amount.toFixed() function, produces the string "100.00". I would like this result to be formatted according to the specific locale. For example, in Italian the desired output is 100,00, while in English it should be ...

The perfect timing for incorporating a JavaScript MVC framework into your project

As part of my job at a small web agency specializing in web applications for startups, I'm urging my boss to invest more in developing strong client-side frameworks using Javascript MVC standards like BackboneJS and templating with Underscore. I unde ...

Can hoek (from hapi.js) transform() function work with arrays?

Exploring the transform() functionality demonstrated in the Hoek documentation, is there a method to transform arrays within the source object? For instance, modifying the example to work with an array structure, such as this: var source = { address: ...

Difficulty with local storage overwriting

I've been developing a quiz app using only JavaScript. The app allows users to choose a username, answer questions to increase their score, and saves the data in variables. When the game ends, a message is displayed along with the top 5 scores achieve ...

Retrieve information transmitted from Angularjs through a multipart POST request to Nodejs and save it to a file

I am currently struggling with a challenging issue regarding uploading files from a web browser using angular js for the front end. After clicking send, the data is routed to a Nodejs express server, but unfortunately I am unable to retrieve my data. My m ...

Retrieve information from a mysql database based on selected date using the ajax method

To retrieve data from a MySQL database based on the chosen date_time, I need to ensure that the content is seamlessly displayed without any page refresh. After successfully extracting the date_time from the database and showing it on the webpage, my focus ...

Ways to apply CSS styling to a specific SVG element without affecting others?

Originally, I had created a single bar chart using SVG: bars.append("rect") .attr("x", midX) .attr("y", 0) .attr("width", function(d) { return x(d.values[0].value); }) .attr("height", y.bandwidth()) .classed("highlight", function(d) { retu ...

What is causing the search filter in the App.js code to malfunction?

After fetching a list of names from an array using the Fetch method, I attempted to implement a search filter by adding the resetData() method in my componentDidMount. Unfortunately, this resulted in an error as shown here: https://i.stack.imgur.com/1Z7kx. ...

How to trigger an event following client-side script validation in ASP.NET?

Is it possible to run a JavaScript function after client-side validation in asp.net? I have multiple validation controls on my page along with an input button that has CausesValidation set to true. The OnClientClick handler currently executes JavaScript b ...

Leveraging Firebase Realtime Database for concurrent data insertion via web applications

Having an issue with firebase Realtime database integration in html/js. Attempting to insert data like colors of a pattern, but each time it replaces the existing node. For example: Patterns Monopattern color: white Whenever adding the color ...

ng2-idle server side rendering problem - Uncaught ReferenceError: document is undefined

Can ng2-idle be used for idle timeout/keepalive with pre-rendering in Angular 4? I followed this link for implementation: It works fine without server pre-rendering, but when I add rendering back to my index.html, I keep getting the following error: Exce ...

Troubleshooting an issue with Laravel's Bootstrap 5.2 dropdown functionality

After setting up a pre-configured navbar from the Bootstrap website, I noticed that the dropdown feature is not working. This issue arose with the latest version of Bootstrap 5.2 which was integrated into my Laravel project without any modifications to the ...

Is there a way to seamlessly transition between two different applications while testing on Appium?

I'm encountering an issue with my Appium test script in Java that interacts with my Android application. The script is supposed to begin at my application's main activity, then navigate to the second activity. However, I then need to switch to t ...