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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:16:53+00:00 2026-06-13T12:16:53+00:00

I keep facing this type of error about java.lng.NullPointerExeption .Anyone know how to solve

  • 0

I keep facing this type of error about java.lng.NullPointerExeption .Anyone know how to solve it ?

main.java
package com.example.shoppingassistantnew;

import greendroid.app.GDActivity;
import greendroid.widget.ActionBarItem;
import greendroid.widget.ActionBarItem.Type;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;

public class main extends GDActivity {


    private static final int EXPAND = 0;

    private static final int ADD = 1;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setActionBarContentView(R.layout.shoppinglist);

        initActionBar();
    }
    private void initActionBar(){

        addActionBarItem(Type.List,EXPAND);
        addActionBarItem(Type.Add,ADD);

    }


     @Override
        public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
            // TODO Auto-generated method stub
         switch(item.getItemId()){
         case ADD:
             Intent intent=new Intent(main.this,AddShoppingList.class);
             startActivity(intent);

         }
            return super.onHandleActionBarItemClick(item, position);
        }

     static final class ProductData{

            String barcode;
            String format;
        }
}

AddShoppingList.java

package com.example.shoppingassistantnew;

import com.cyrilmottier.android.greendroid.R;
import com.example.shoppingassistantnew.main.ProductData;


import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import greendroid.app.GDActivity;

public class AddShoppingList extends Activity implements OnClickListener {
    private static final ProductData mProductData = new ProductData();
    private Button mSaveBttn;
    EditText mBarcodeEdit;
    EditText mFormatEdit;
    ProductDatabase mProductDb;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addshoppinglist);
        mBarcodeEdit = (EditText) findViewById(R.id.shoppingListNameEdit);
        mFormatEdit = (EditText) findViewById(R.id.shoppingDateEdit);

        mSaveBttn.setOnClickListener(this);


    }



    private void showInfoDialog(Context context, String title,
            String information) {
        new AlertDialog.Builder(context).setMessage(information)
                .setTitle(title)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                }).show();
    }



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

    }

}

ProductDatabase.java

package com.example.shoppingassistantnew;
import com.example.shoppingassistantnew.main.ProductData;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class ProductDatabase  {
private static final String PRODUCT_TABLE="products";
private static final String DATABASE_NAME="spot_pay.db";
private static final int DATABASE_VERSION=1;
private SQLiteDatabase db;


private static class ProductDatabaseHelper extends SQLiteOpenHelper {

    private static final String TAG = null;

    public ProductDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        StringBuilder sql=new StringBuilder();

        sql.append("create table ").append(PRODUCT_TABLE)
            .append("(  ")
            .append("   _id integer primary key,")
            .append("   barcode text,")
            .append("   format text,")
          .append(")  ");


        db.execSQL(sql.toString());
          Log.d(TAG, PRODUCT_TABLE + "table created");    
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
         db.execSQL("drop table if exists " + PRODUCT_TABLE);                    
            onCreate(db);
    }



}



public ProductDatabase(Context context){
     ProductDatabaseHelper helper = new ProductDatabaseHelper(context);
  db = helper.getWritableDatabase();

}
public boolean insert(ProductData product){
    ContentValues vals = new ContentValues();
      vals.put("barcode", product.barcode);
        vals.put("format", product.format);
     return db.insert(PRODUCT_TABLE, null, vals) != -1;
}
}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.shoppingassistantnew"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
         android:theme="@style/Theme.GDActionBarExample"
            android:name=".GDIntroApp">
        <activity
            android:name=".main"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".AddShoppingList" android:theme="@style/myDialog"></activity>
    </application>

</manifest>

LOGCAT

10-27 10:18:15.545: D/AndroidRuntime(1633): Shutting down VM
10-27 10:18:15.545: W/dalvikvm(1633): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-27 10:18:15.555: E/AndroidRuntime(1633): FATAL EXCEPTION: main
10-27 10:18:15.555: E/AndroidRuntime(1633): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shoppingassistantnew/com.example.shoppingassistantnew.AddShoppingList}: java.lang.NullPointerException
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.os.Looper.loop(Looper.java:123)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at java.lang.reflect.Method.invokeNative(Native Method)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at java.lang.reflect.Method.invoke(Method.java:521)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at dalvik.system.NativeStart.main(Native Method)
10-27 10:18:15.555: E/AndroidRuntime(1633): Caused by: java.lang.NullPointerException
10-27 10:18:15.555: E/AndroidRuntime(1633):     at com.example.shoppingassistantnew.AddShoppingList.onCreate(AddShoppingList.java:39)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-27 10:18:15.555: E/AndroidRuntime(1633):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-27 10:18:15.555: E/AndroidRuntime(1633):     ... 11 more
10-27 10:18:17.825: I/Process(1633): Sending signal. PID: 1633 SIG: 9
  • 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-13T12:16:54+00:00Added an answer on June 13, 2026 at 12:16 pm

    in AddShoppingList.java , mSaveBttn is null give refrence first from xml , then use it

        mFormatEdit = (EditText) findViewById(R.id.shoppingDateEdit);
    
        mSaveBttn =(Button)findViewById(R.id.mSaveBttn);<<<< Give Refrence from xml
        mSaveBttn.setOnClickListener(this);
        ^^^^^^^^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Keep in mind this is on OSX Snow Leopard) I don't know how to
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep going around circles, but I am still unclear about this. Have a feeling
I keep getting this error and have no idea why. I googled and scanned
I keep on facing this question from my manager how SSO will work if
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I keep coming back to this problem, since there doesn't seem to be a
This is in continuation of two ongoing problems I'm facing: Problems trying to attach
The current issue I'm facing is this. I have a directory as such webroot:banners/users/

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.