title: Android & SQLite : Sum column, send to Setter and get the value from another activity
body: <p>i have method getJumHutang, this method use for SUM all hutang column and save it to class Hutang, class Hutang use for setter and getter.</p>
  
  <p>this is the code for method getJumHutang :</p>
  
  <pre><code>public class HutangDAO extends HutangDBDAO  {
  
      public HutangDAO(Context context) {
          super(context);
      }
  
      public Cursor getJumHutang(Hutang hutang){
          Cursor cursor = database.rawQuery("select sum("+DataBaseHelperHutang.JUMLAH+") FROM "+DataBaseHelperHutang.HUTANG_TABLE+"", null);
          try {
              if(cursor.moveToFirst()){
                  hutang.setJumHutang(cursor.getDouble(0));
              }
          } finally {
              cursor.close();
              close();
          }
  
          return getJumHutang(hutang);
      }
  </code></pre>
  
  <p>this code in MainActivity that call method setJumHutang :</p>
  
  <pre><code>package mainmenu;
  
  import pemasukan.PemasukanMainActivity;
  import piutang.PiutangActivity;
  import hutang.Hutang;
  import hutang.HutangDAO;
  import hutang.HutangActivity;
  
  import com.androidopentutorials.sqlite.R;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.TextView;
  
  public class MainActivity extends Activity   {
  
      TextView txtHutang;
      TextView txtPiutang;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_mainmenu);
          txtHutang = (TextView) findViewById(R.id.textHutang);
          HutangDAO dao = new HutangDAO(this);
          Hutang hutang = new Hutang();
          dao.getJumHutang(hutang);
          txtHutang.setText(hutang.getJumHutang()+"");
      }
  
      public void callPiutang (View view){
          Intent intent = new Intent(this, PiutangActivity.class);
          startActivity(intent);
      }
  
      public void callHutang (View view){
          Intent intent = new Intent(this, HutangActivity.class);
          startActivity(intent);
      }
  
      public void callPemasukan (View view){
          Intent intent = new Intent(this, PemasukanMainActivity.class);
          startActivity(intent);
      }
  
      @Override
      public void onBackPressed() {
          onShowQuitDialog();
      }
  
      public void onShowQuitDialog() {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setCancelable(false);
  
          builder.setMessage("Do You Want To Quit?");
          builder.setPositiveButton(android.R.string.yes,
                  new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int id) {
                          finish();
                      }
                  });
          builder.setNegativeButton(android.R.string.no,
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          dialog.cancel();
                      }
                  });
          builder.create().show();
      }
  
  }
  </code></pre>
  
  <p>and the class Hutang (Setter and Getter) :</p>
  
  <pre><code>public class Hutang {
  
      private double jumhutang;
  
      public Hutang(){
          super();
      }
  
      public double getJumHutang(){
          return jumhutang;
      }
  
      public void setJumHutang(double jumhutang){
          this.jumhutang = jumhutang;
      }
  }
  </code></pre>
  
  <p>class HutangDBDAO :</p>
  
  <pre><code>package hutang;
  
  import android.content.Context;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  
  public class HutangDBDAO {
      protected SQLiteDatabase database;
      private DataBaseHelperHutang dbHelper;
      private Context mContext;
  
      public HutangDBDAO(Context context) {
          this.mContext = context;
          open();
      }
  
      public void open() throws SQLException {
          if(dbHelper == null)
              dbHelper = DataBaseHelperHutang.getHelper(mContext);
          database = dbHelper.getWritableDatabase();
      }
  
  
      public void close() {
          dbHelper.close();
          database = null;
      }
  }
  </code></pre>
  
  <p>and the last is DataBaseHelperHutang :</p>
  
  <pre><code>package hutang;
  
  
  import android.content.Context;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  import android.util.Log;
  
  public class DataBaseHelperHutang extends SQLiteOpenHelper {
  
      private static final String DATABASE_NAME = "hutang.db";
      private static final int DATABASE_VERSION = 3;
  
      public static final String HUTANG_TABLE = "hutang";
  
      public static final String ID_COLUMN = "id";
      public static final String TANGGAL_PINJAM = "pinjam";
      public static final String JUMLAH = "jumlah";
      public static final String TANGGAL_KEMBALI = "kembali";
      public static final String DARI = "dari";
      public static final String KETERANGAN = "keterangan";
  
      public static final String CREATE_HUTANG_TABLE = "CREATE TABLE "
              + HUTANG_TABLE + "(" + ID_COLUMN + " INTEGER PRIMARY KEY, "
              + TANGGAL_PINJAM + " DATE, " + JUMLAH + " DOUBLE, "
              + TANGGAL_KEMBALI + " DATE ," + DARI + " TEXT,  "
              + KETERANGAN + " TEXT);";
  
      private static DataBaseHelperHutang instance;
  
      public static synchronized DataBaseHelperHutang getHelper(Context context) {
          if (instance == null)
              instance = new DataBaseHelperHutang(context);
          return instance;
      }
  
      private DataBaseHelperHutang(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onOpen(SQLiteDatabase db) {
          super.onOpen(db);
          if (!db.isReadOnly()) {
              // Enable foreign key constraints
              db.execSQL("PRAGMA foreign_keys=ON;");
          }
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          db.execSQL(CREATE_HUTANG_TABLE);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          Log.w(DataBaseHelperHutang.class.getName(),"Upgrading database from version " + oldVersion + " to "
                  + newVersion + ", which will destroy all old data");
          db.execSQL("DROP TABLE IF EXISTS " + HUTANG_TABLE);
          onCreate(db);
      }
  }
  </code></pre>
  
  <p>and i got this error :</p>
  
  <pre><code>08-12 13:42:47.721: W/dalvikvm(1504): threadid=1: thread exiting with uncaught exception (group=0xb2a95ba8)
  08-12 13:42:47.741: E/AndroidRuntime(1504): FATAL EXCEPTION: main
  08-12 13:42:47.741: E/AndroidRuntime(1504): Process: com.androidopentutorials.sqlite, PID: 1504
  08-12 13:42:47.741: E/AndroidRuntime(1504): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidopentutorials.sqlite/mainmenu.MainActivity}: java.lang.NullPointerException
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.os.Handler.dispatchMessage(Handler.java:102)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.os.Looper.loop(Looper.java:136)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.ActivityThread.main(ActivityThread.java:5017)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at java.lang.reflect.Method.invokeNative(Native Method)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at java.lang.reflect.Method.invoke(Method.java:515)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at dalvik.system.NativeStart.main(Native Method)
  08-12 13:42:47.741: E/AndroidRuntime(1504): Caused by: java.lang.NullPointerException
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at hutang.HutangDAO.getJumHutang(HutangDAO.java:30)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at hutang.HutangDAO.getJumHutang(HutangDAO.java:40)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at mainmenu.MainActivity.onCreate(MainActivity.java:33)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.Activity.performCreate(Activity.java:5231)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  08-12 13:42:47.741: E/AndroidRuntime(1504):     ... 11 more
  </code></pre>
  
  <p>when i click  08-12 13:42:47.741: E/AndroidRuntime(1504):   at hutang.HutangDAO.getJumHutang(HutangDAO.java:30) eclipse highlights this line at HutangDAO.class :</p>
  
  <pre><code>Cursor cursor = database.rawQuery("select sum("+DataBaseHelperHutang.JUMLAH+") FROM "+DataBaseHelperHutang.HUTANG_TABLE+"", null);
  </code></pre>
  
  <p>for 08-12 13:42:47.741: E/AndroidRuntime(1504):     at hutang.HutangDAO.getJumHutang(HutangDAO.java:40) eclipse highlights this line at HutangDAO.class :</p>
  
  <pre><code>return getJumHutang(hutang);
  </code></pre>
  
  <p>and 08-12 13:42:47.741: E/AndroidRuntime(1504):     at mainmenu.MainActivity.onCreate(MainActivity.java:33)  eclipse highlights this line at MainActivity.class :</p>
  
  <pre><code>txtHutang.setText(hutang.getJumHutang()+"");
  </code></pre>
  
  <p>sorry if my question kind like a noob question, but i find myself stuck in this error.. </p>