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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:35:27+00:00 2026-06-17T07:35:27+00:00

My application want to calculate the total sales in a month. I used sql

  • 0

My application want to calculate the total sales in a month. I used sql statements sum. But when I run the application it fails. and I do not know why this error. expect people to help me fix this. I am very thankful.
Code DB_Adapter

public class DB_Adapter {
public static final String DATE="date";
public static final String COST = "cost";
public static final String SALES = "sales";
public static final String NUMBER = "number";
public static final String PROFIT = "profit";
public static final String DB_NAME = "SAIGONFLEAMARKET";
public static final String DB_TABLE = "shipment";
public static final String MONTH="month";
public static final String YEAR="year";
public static final int DB_VERSION = 2;
private final Context mContext;
private SQLiteDatabase mDB;
private DBHelper mDBHelper;

public DB_Adapter(Context c) {
    mContext = c;
}

private static class DBHelper extends SQLiteOpenHelper
{

    public DBHelper(Context context, String name, CursorFactory factory,
            int version) {
        super(context, name, factory, version);
        // TODO Auto-generated constructor stub
    }

    // Khởi tạo một bảng trong database mang tên Saigonfleamarket
    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        try
        {
            db.execSQL("CREATE TABLE shipment (number integer PRIMARY KEY autoincrement, date text, cost float, sales float, profit float, month text, year text );");
        } catch (SQLException ex)
        {
            ex.printStackTrace();
        }
    }

    // Tạo một database mới
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        Log.i("DBAdapter", "Updating database...");
        db.execSQL("DROP TABLE IF EXISTS shipment");
        onCreate(db);
    }
}

// Mở một kết nối đến database
public DB_Adapter openDB()
{
    mDBHelper = new DBHelper(mContext, DB_NAME, null, DB_VERSION);
    mDB = mDBHelper.getWritableDatabase();
    return this;
}

// sau khi hoàn thành, đóng database lại
public void closeDB()
{
    mDBHelper.close();
}

public Cursor Sum(String _month, String _year)

{
    String sql="select Sum (profit) from shipment where month ='"+_month+"' AND year='"+ _year+"'";
    Cursor mCursor = mDB.rawQuery(sql, null);
    int test = mCursor.getCount();
    if (test != 0)
    {
        mCursor.moveToFirst();
    }

    return mCursor;
}  
}

log cat error

01-15 13:49:48.840: E/AndroidRuntime(6953): FATAL EXCEPTION: main
01-15 13:49:48.840: E/AndroidRuntime(6953): java.lang.NullPointerException
01-15 13:49:48.840: E/AndroidRuntime(6953):     at Data.DB_Adapter.Sum(DB_Adapter.java:116)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at com.example.xitinshop.Thongtin.onClick(Thongtin.java:40)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at android.view.View.performClick(View.java:2485)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at android.view.View$PerformClick.run(View.java:9080)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at android.os.Handler.handleCallback(Handler.java:587)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at android.os.Looper.loop(Looper.java:130)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at android.app.ActivityThread.main(ActivityThread.java:3683)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at java.lang.reflect.Method.invokeNative(Native Method)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at java.lang.reflect.Method.invoke(Method.java:507)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-15 13:49:48.840: E/AndroidRuntime(6953):     at dalvik.system.NativeStart.main(Native Method)
  • 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-17T07:35:29+00:00Added an answer on June 17, 2026 at 7:35 am

    use this Method instead of old one.

    public Cursor Sum(String _month, String _year)
    
    {
        String sql="select Sum(profit) from shipment where month =? AND year=?";
        Cursor mCursor = mDB.rawQuery(sql, new String[] { _month ,_year});
        int test = mCursor.getCount();
        if (test != 0)
        {
            mCursor.moveToFirst();
        }
    
        return mCursor;
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my PHP application I want to calculate the sum of two time variables.
how do i calculate the loading percentage of my C# application. i want to
I have sales application. When the user click on EditText the popup calculator want
In my application I want to apply a filter, but I don't want all
Hi I want to develop financial application i have taken total salary and amount
hai,In my application i want to calculate the spped based on x,y,z values.So How
For my application I want to calculate my car/bike speed using iphone. How can
when i run my application its get my location(Lat,logi) both new and old location.But
In my application I want to calculate data usage when application is in foreground.
I am developing an application using codeigniter. In my application I want to calculate

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.