I'm Trying to make a grocery app to practice some of the things that I learned form bucky's tutorial.
One of the things is that I'm trying to make an activity that shows everything on the DB that I made.
this is the SQL handler I made (its heavily based on what bucky did)

package com.example.itayrabin.grocery_lol;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.Cursor;
import android.content.Context;
import android.content.ContentValues;


public class MyDBHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "products.db";
    private static final String TABLE_PRODUCTS = "products";
    private static final String COLUMN_ID = "_id";
    private static final String COLUMN_PRODUCTNAME = "productname";
    private static final String COLUMN_BUYINGPRICE = "buyingprice";
    private static final String COLUMN_SELLINGPRICE = "sellingprice";
    private static final String COLUMN_QUANTITY = "quantity";
    private static final String COLUMN_TYPE = "type";

    public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DATABASE_NAME, factory, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {


        String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
                COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                COLUMN_PRODUCTNAME + " TEXT, " + COLUMN_BUYINGPRICE + " SMALLINT, " +
                COLUMN_SELLINGPRICE + " SMALLINT, " + COLUMN_QUANTITY + " SMALLINT, " +
                COLUMN_TYPE + " SMALLINT " + ");";
        db.execSQL(query);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_PRODUCTS);
        onCreate(db);
    }


    public void addProduct (Products product){
        SQLiteDatabase db = getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(COLUMN_PRODUCTNAME,product.get_productname());
        values.put(COLUMN_BUYINGPRICE,product.get_buyingprice());
        values.put(COLUMN_SELLINGPRICE,product.get_sellingprice());
        values.put(COLUMN_QUANTITY,product.get_quantity());
        values.put(COLUMN_TYPE,product.get_type());
        db.insert(TABLE_PRODUCTS,null,values);
        db.close();
    }

    public void deleteProduct(String productname){
        SQLiteDatabase db = getWritableDatabase();
        db.execSQL("DELETE FROM " + TABLE_PRODUCTS + "WHERE " + COLUMN_PRODUCTNAME +
        "=\"" + productname + "\";");
    }

    public void changeProperties(int id, String newValue, String COLUMN){
        ContentValues values = new ContentValues();
        if (COLUMN.equals(COLUMN_PRODUCTNAME))
            values.put(COLUMN,newValue);

        else
            values.put(COLUMN,Double.parseDouble(newValue));

        SQLiteDatabase db = getWritableDatabase();
        db.update(TABLE_PRODUCTS,values,COLUMN_ID+ "=\"" + id + "\"",null);
    }


    public String databaseToString(String COLUMN) {


        String dbString = " ";
        SQLiteDatabase db = getWritableDatabase();
        String query = "SELECT " + COLUMN + " FROM " + TABLE_PRODUCTS + " WHERE 1";

        //Cursor points to a location in your results
        Cursor c = db.rawQuery(query, null);
        //Move to the first row in your results
        c.moveToFirst();

        //Position after the last row means the end of the results
        while (!c.isAfterLast()) {
            if (c.getString(c.getColumnIndex(COLUMN)) != null) {
                dbString += c.getString(c.getColumnIndex(COLUMN));
                dbString += "\n";
            }
            c.moveToNext();
        }
        db.close();
        return dbString;
    }


    //finds specific detail in row. finds row using name

    public String findInDataBase(String COLUMN,String itemName) {
        String dbString = "";
        SQLiteDatabase db = getWritableDatabase();
        String query = "SELECT " + COLUMN + " FROM " + TABLE_PRODUCTS + " WHERE "
                + COLUMN_PRODUCTNAME + "=\"" + itemName + "\"";

        //Cursor points to a location in your results
        Cursor c = db.rawQuery(query, null);
        //Move to the first row in your results
        c.moveToFirst();

        //Position after the last row means the end of the results
        while (!c.isAfterLast()) {
            if (c.getString(c.getColumnIndex("price")) != null) {
                dbString += c.getString(c.getColumnIndex("price"));
            }
            c.moveToNext();
        }
        db.close();
        return dbString;
    }

    //finds specific detail in row. finds row using ID


    public String findInDataBase(String COLUMN,int ID) {
        String dbString = "";
        SQLiteDatabase db = getWritableDatabase();
        String query = "SELECT " + COLUMN + " FROM " + TABLE_PRODUCTS + " WHERE "
                + COLUMN_ID + "=\"" + ID + "\"";

        //Cursor points to a location in your results
        Cursor c = db.rawQuery(query, null);
        //Move to the first row in your results
        c.moveToFirst();

        //Position after the last row means the end of the results
        while (!c.isAfterLast()) {
            if (c.getString(c.getColumnIndex(COLUMN)) != null) {
                dbString += c.getString(c.getColumnIndex(COLUMN));
            }
            c.moveToNext();
        }
        db.close();
        return dbString;
    }

    public String lastDatabaseToString(String COLUMN) {


        String dbString = "";
        SQLiteDatabase db = getWritableDatabase();
        String query = "SELECT " + COLUMN + " FROM " + TABLE_PRODUCTS + " WHERE 1";

        //Cursor points to a location in your results
        Cursor c = db.rawQuery(query, null);
        //Move to the first row in your results
        c.moveToFirst();

        //Position after the last row means the end of the results
        while (!c.isAfterLast()) {
            if (c.getString(c.getColumnIndex(COLUMN)) != null) {
                dbString = c.getString(c.getColumnIndex(COLUMN));
            }
            c.moveToNext();
        }
        db.close();
        return dbString;
    }
}

I'm using a class "Products" that I made as my general item:

package com.example.itayrabin.grocery_lol;

/**
 * Created by ItayRabin on 22/01/2015.
 */
public class Products {

    private int _id;
    private String _productname;
    private double _buyingprice;
    private double _sellingprice;
    private double _quantity;
    private double _type;

    public static final double PRODUCT_SINGULAR = 1;
    public static final double PRODUCT_WEIGHT = 2;


    public Products(){
    }

    public Products(String productname, double buyingprice,double sellingprice, double quantity,double type) {
        this._productname = productname;
        this._buyingprice = buyingprice;
        this._sellingprice = sellingprice;
        this._quantity = quantity;
        this._type = type;
    }

    //getter and setter for ID
    public int get_id() {
        return _id;
    }

    public void set_id(int _id) {
        this._id = _id;
    }

    //getter and setter for productname
    public String get_productname() {
        return _productname;
    }

    public void set_productname(String _productname) {
        this._productname = _productname;
    }

    //getter and setter for buyingprice
    public double get_buyingprice() {
        return _buyingprice;
    }

    public void set_buyingprice(double _buyingprice) {
        this._buyingprice = _buyingprice;
    }

    //getter and setter for sellingprice
    public double get_sellingprice() {
        return _sellingprice;
    }
    public void set_sellingprice(double _sellingprice) {
        this._sellingprice = _sellingprice;
    }

    //getter and setter for quaintity
    public double get_quantity() {
        return _quantity;
    }
    public void set_quantity(double _quantity) {
        this._quantity = _quantity;
    }

    //getter and setter for type
    public double get_type() {
        return _type;
    }
    public void set_type(double _type) {
        this._type = _type;
    }
}

nothing special, like bucky did.

MakeTransaction.java is my launcher activity, even though I haven't got to messing with it yet.

package com.example.itayrabin.grocery_lol;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridLayout;
import android.widget.EditText;



public class MakeTransaction extends ActionBarActivity {

    GridLayout receipt;
    static MyDBHandler dbHandler;


    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_PRODUCTNAME = "productname";
    public static final String COLUMN_BUYINGPRICE = "buyingprice";
    public static final String COLUMN_SELLINGPRICE = "sellingprice";
    public static final String COLUMN_QUANTITY = "quantity";
    public static final String COLUMN_TYPE = "type";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_make_tranaction);
       dbHandler = new MyDBHandler(this,null,null,1);
       dbHandler.ScrewYou(new Products("eggs",7,10,5,Products.PRODUCT_SINGULAR));
       //dbHandler.addProduct(new Products("milk",3,5,7,Products.PRODUCT_SINGULAR));
       Intent i = new Intent(this,Inventory.class);
       startActivity(i);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_make_tranaction, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void newItem (View view){

    }
}

It adds a product or 2 (I comment out when It out if I don't need it) and then it calls the Inventory activity which is supposed to show the database using a listview that I made:

package com.example.itayrabin.grocery_lol;


import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;



public class Inventory extends ActionBarActivity {


    private TextView cash;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inventory);

        int productsInDB = Integer.parseInt(MakeTransaction.dbHandler.lastDatabaseToString(MakeTransaction.COLUMN_ID));
        TextView cash = (TextView) findViewById(R.id.cashView);

        Products[] products = new Products[productsInDB];


       for (int i=1; i< productsInDB; i++){;

           String name = MakeTransaction.dbHandler.findInDataBase(MakeTransaction.COLUMN_PRODUCTNAME,i);
           double buyingprice = Double.parseDouble( MakeTransaction.dbHandler.findInDataBase(MakeTransaction.COLUMN_BUYINGPRICE,i));
           double sellingprice = Double.parseDouble( MakeTransaction.dbHandler.findInDataBase(MakeTransaction.COLUMN_SELLINGPRICE,i));
           double quantity = Double.parseDouble( MakeTransaction.dbHandler.findInDataBase(MakeTransaction.COLUMN_QUANTITY,i));
           double type = Double.parseDouble(MakeTransaction.dbHandler.findInDataBase(MakeTransaction.COLUMN_TYPE,i));

           products[i-1] = new Products(name,buyingprice,sellingprice,quantity,type);
           cash.setText(cash.getText() + String.valueOf(i));
       }


        ListAdapter inventoryAdapter = new CustomAdapter(this,products);
        ListView inventoryListView = (ListView) findViewById(R.id.inventoryListView);
        inventoryListView.setAdapter(inventoryAdapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_inventory, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

And here's the UI for it:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.itayrabin.grocery_lol.inventory">



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="You have "
        android:id="@+id/cashView"
        android:layout_marginLeft="17dp"
        android:layout_marginStart="17dp"
        android:layout_marginBottom="20dp"
        android:layout_above="@+id/addCashButton"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add more money"
        android:id="@+id/addCashButton"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Product"
        android:id="@+id/addProductButton"
        android:layout_marginRight="37dp"
        android:layout_marginEnd="37dp"
        android:layout_below="@+id/cashView"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/inventoryListView"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="100dp"  />

</RelativeLayout>


My CustomAdapter just has a few Text fields(when I run it it looks super weird, I need to improve it:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:id="@+id/RelativeLayout">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Bread"
        android:id="@+id/itemName"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_margin="5dp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Quantity: "
        android:id="@+id/quantityView"
        android:layout_below="@+id/itemName"
        android:layout_toRightOf="@+id/itemName"
        android:layout_toEndOf="@+id/itemName" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Buying Price: "
        android:id="@+id/buyingPriceView"
        android:layout_below="@+id/quantityView"
        android:layout_alignLeft="@+id/itemName"
        android:layout_alignStart="@+id/itemName"
        android:layout_marginTop="19dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Selling Price: "
        android:id="@+id/sellingPriceView"
        android:layout_marginLeft="44dp"
        android:layout_marginStart="44dp"
        android:layout_alignTop="@+id/buyingPriceView"
        android:layout_toRightOf="@+id/quantityView"
        android:layout_toEndOf="@+id/quantityView" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change Data"
        android:id="@+id/changeDBButton"
        android:layout_below="@+id/buyingPriceView"
        android:layout_toRightOf="@+id/buyingPriceView"
        android:layout_toEndOf="@+id/buyingPriceView"
        android:layout_marginTop="49dp"
        android:onClick="changeDB"
        android:nestedScrollingEnabled="false" />
</RelativeLayout>

And here's my code for the adapter:

package com.example.itayrabin.grocery_lol;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

class CustomAdapter extends ArrayAdapter<Products> {

    CustomAdapter(Context context, Products[] products) {
        super(context, R.layout.custom_row, products);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inventoryInflater = LayoutInflater.from(getContext());
        View customView = inventoryInflater.inflate(R.layout.custom_row,parent,false);

        TextView itemName = (TextView) customView.findViewById(R.id.itemName);
        TextView quantityView = (TextView) customView.findViewById(R.id.quantityView);
        TextView buyingPriceView = (TextView) customView.findViewById(R.id.buyingPriceView);
        TextView sellingPriceView = (TextView) customView.findViewById(R.id.sellingPriceView);

        itemName.setText(getItem(position).get_productname());
        quantityView.setText(quantityView.getText() + String.valueOf(getItem(position).get_quantity()));
        buyingPriceView.setText(buyingPriceView.getText() + String.valueOf(getItem(position).get_buyingprice()));
        sellingPriceView.setText(sellingPriceView.getText() + String.valueOf(getItem(position).get_sellingprice()));

        return customView;
    }
}

The problem  is that when I run it for less then a full screen of rows it just crashes saying that _productname is null (even though I checked with the debug tool and it does have one)
and when I run it with something like 10 rows, it makes all of those 10 rows and it doesn't crash, but when I scroll down there are more than the rows I have in my array and the second it enters the screen's space it crashes.
its like its trying to make more rows then there are for some reason.
can anyone please help??