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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:46:41+00:00 2026-06-12T22:46:41+00:00

i follow the tutorial online , created an app for scanning barcodes and QR

  • 0

i follow the tutorial online , created an app for scanning barcodes and QR code using the ZXing library, and store all the information inside the database . I follow step by step to do it ,but something in my code .The data cannot store in database , and keep force close

Calledspot_pay.java

package com.example.zxing_android_products;

import java.math.BigDecimal;



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

public class Calledspot_pay extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calledspot_pay);
        Button addButton=(Button)findViewById(R.id.addMenuButton);
        addButton.setOnClickListener (new OnClickListener(){
            public void onClick (View v){
                startActivity(new Intent(Calledspot_pay .this, AddProduct.class));
            }
            });
    }  






    static final class ProductData {
        String barcode;
        String format;
        String title;
        BigDecimal price;
    }



}

ProductDatabase.java

package com.example.zxing_android_products;

import java.math.BigDecimal;

import com.example.zxing_android_products.Calledspot_pay.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 static final BigDecimal ONE_HUNDRED = null;

  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) {            
               StringBuilder sql = new StringBuilder();

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

                db.execSQL(sql.toString());    

                Log.d(TAG, PRODUCT_TABLE + "table created");       
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {            
            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);
        vals.put("title", product.title);
        vals.put("price", product.price.multiply(ONE_HUNDRED).longValue());

        return db.insert(PRODUCT_TABLE, null, vals) != -1;
    }
}

AddProduct.java

package com.example.zxing_android_products;

import java.math.BigDecimal;

import com.example.zxing_android_products.Calledspot_pay.ProductData;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AddProduct extends Activity  implements OnClickListener{
    private static final int REQUEST_BARCODE=0;
    private static final ProductData mProductData=new ProductData();
    EditText mBarcodeEdit;
    EditText mFormatEdit;
    EditText mTitleEdit;
      EditText mPriceEdit;
      private Button mScanButton;
        private Button mAddButton;
    //private ProductDatabase mProductDb;
     ProductDatabase mProductDb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_product);


        mBarcodeEdit = (EditText) findViewById(R.id.barcodeEdit);
        mFormatEdit = (EditText) findViewById(R.id.codeFormatEdit);
        mTitleEdit = (EditText) findViewById(R.id.titleEdit);
        mPriceEdit = (EditText) findViewById(R.id.priceEdit);
        mScanButton = (Button) findViewById(R.id.scanButton);
        mScanButton.setOnClickListener(this);
        mAddButton = (Button) findViewById(R.id.addButton);
        mAddButton.setOnClickListener(this);
         mProductDb = new ProductDatabase(this); // not yet shown

}
    public void onClick(View v) {
    // TODO Auto-generated method stub
           switch (v.getId()) {
            case R.id.scanButton:
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
                startActivityForResult(intent, REQUEST_BARCODE);
                break;


            case R.id.addButton:
                String barcode = mBarcodeEdit.getText().toString();
                String format = mFormatEdit.getText().toString();
                String title = mTitleEdit.getText().toString();
                String price = mPriceEdit.getText().toString();

                String errors = validateFields(barcode, format, title, price);
                if (errors.length() > 0) {
                    showInfoDialog(this, "Please fix errors", errors);
                } else {
                    mProductData.barcode = barcode;
                    mProductData.format = format;
                    mProductData.title = title;
                    mProductData.price = new BigDecimal(price);

              mProductDb.insert(mProductData);
                    showInfoDialog(this, "Success", "Product saved successfully");
                    resetForm();
                }
                break;
            }   
        }



    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();  
    }
private void resetForm() {
    // TODO Auto-generated method stub
      mBarcodeEdit.getText().clear();
      mFormatEdit.getText().clear();
      mTitleEdit.getText().clear();
      mPriceEdit.getText().clear();
}





public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_BARCODE) {
        if (resultCode == RESULT_OK) {
            String barcode = intent.getStringExtra("SCAN_RESULT");
            mBarcodeEdit.setText(barcode);

            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            mFormatEdit.setText(format);
        } else if (resultCode == RESULT_CANCELED) {
            finish();
        }
    }
}

private static String validateFields(String barcode, String format, 
        String title, String price) {
        StringBuilder errors = new StringBuilder();

        if (barcode.matches("^\\s*$")) {
            errors.append("Barcode required\n");
        }

        if (format.matches("^\\s*$")) {
            errors.append("Format required\n");
        }

        if (title.matches("^\\s*$")) {
            errors.append("Title required\n");
        }

        if (!price.matches("^-?\\d+(.\\d+)?$")) {
            errors.append("Need numeric price\n");
        }

        return errors.toString();
    }
}

anybody what is the error ?

10-17 10:21:37.746: D/AndroidRuntime(18643): Shutting down VM
10-17 10:21:37.746: W/dalvikvm(18643): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
10-17 10:21:37.746: E/AndroidRuntime(18643): Uncaught handler: thread main exiting due to uncaught exception
10-17 10:21:37.767: E/AndroidRuntime(18643): java.lang.NullPointerException
10-17 10:21:37.767: E/AndroidRuntime(18643):    at java.math.BigDecimal.multiply(BigDecimal.java:1025)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.example.zxing_android_products.ProductDatabase.insert(ProductDatabase.java:69)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.example.zxing_android_products.AddProduct.onClick(AddProduct.java:74)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.View.performClick(View.java:2364)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.View.onTouchEvent(View.java:4179)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.widget.TextView.onTouchEvent(TextView.java:6541)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.View.dispatchTouchEvent(View.java:3709)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.os.Looper.loop(Looper.java:123)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at android.app.ActivityThread.main(ActivityThread.java:4363)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at java.lang.reflect.Method.invokeNative(Native Method)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at java.lang.reflect.Method.invoke(Method.java:521)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-17 10:21:37.767: E/AndroidRuntime(18643):    at dalvik.system.NativeStart.main(Native Method)
10-17 10:21:37.776: I/dalvikvm(18643): threadid=7: reacting to signal 3
10-17 10:21:37.776: E/dalvikvm(18643): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
10-17 10:21:39.636: I/Process(18643): Sending signal. PID: 18643 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-12T22:46:42+00:00Added an answer on June 12, 2026 at 10:46 pm

    your ONE_HUNDRED variable is null.

    private static final BigDecimal ONE_HUNDRED = null;
    

    You can try:

    private static final BigDecimal ONE_HUNDRED = new BigDecimal(100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I follow this tutorial online exactly but somehow it's giving me errors. Saying there
Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However,
Im trying to follow a tutorial that is using SBJsonParser to get twitter feeds,
I'm trying to follow this tutorial using StructureMap : http://iridescence.no/post/Constructor-Injection-for-ASPNET-MVC-Action-Filters.aspx What I'm trying to
I am trying to follow this tutorial ( Using-core-plot-in-an-iphone-application ). When I try to
I follow tutorial here on how to create web service using RESTful web service
i follow the tutorial from youtube writing a code of login & registration but
Im trying to follow some online tutorial on annotating my models in rails. However,
I am trying to follow TDD on Rails Tutorial which is available online here
I follow this tutorial . I success to do all , but i cannot

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.