title: Trying to make ListView display new information using CursorAdapter
body: <p>I am a new Android programmer. I am entering data into an SQLite database, and I want my ListView to then refresh and show the information that I have just added to the database. The ListView is below the add button. The logcat error shows a NullPointerException.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/LinearLayout1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;LinearLayout
          android:id="@+id/LinearLayout6"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/textView1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="0.34"
              android:text="Registration No:"
              android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
  
          &lt;EditText
              android:id="@+id/vehicle_reg"
              android:layout_width="175dp"
              android:layout_height="wrap_content"
              android:ems="10"
              /&gt;
            &lt;requestFocus /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/LinearLayout7"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/textView3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="0.43"
              android:text="Mileage:"
              android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
  
          &lt;EditText
              android:id="@+id/vehicle_mileage"
              android:layout_width="114dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.29"
              android:ems="10" &gt;
  
  
          &lt;/EditText&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/LinearLayout8"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/textView4"
              android:layout_width="wrap_content"
              android:layout_height="36dp"
              android:layout_weight="0.51"
              android:text="Budget Amount:"
              android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
  
          &lt;EditText
              android:id="@+id/vehicle_budget"
              android:layout_width="167dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.13"
              android:ems="10"
              android:inputType="numberDecimal" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/LinearLayout9"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/textView2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="0.37"
              android:text="Tank Capacity: "
              android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
  
          &lt;EditText
              android:id="@+id/vehicle_capacity"
              android:layout_width="172dp"
              android:layout_height="wrap_content"
              android:ems="10" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
             android:id="@+id/LinearLayout10"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" &gt;
  
          &lt;Button
              android:id="@+id/add_button_vehicle"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="Add Vehicle" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/LinearLayout11"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.43"
          android:orientation="vertical" &gt;
  
          &lt;ListView
              android:id="@+id/vehicleList_reg"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1" &gt;
          &lt;/ListView&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.Toast;
  
  import com.example.budgetfuel.databasemodel.Car;
  import com.example.budgetfuel.databasemodel.DBhelper;
  import com.example.budgetfuel.databasemodel.DatabaseHelper;
  import com.example.budgetfuel.databasemodel.SQLController;
  
  public class VehicleSetup extends FragmentActivity {
  
      Button addvehicle;
      ListView lv;
      SQLController dbcon;
      Button btnAdd;
      EditText reg, milge, cap, budgt;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.fragment_settings);
  
          // get action bar
          ActionBar actionBar = getActionBar();
  
          // Enabling Up / Back navigation
          actionBar.setDisplayHomeAsUpEnabled(true);
          dbcon = new SQLController(this);
          dbcon.open();
          addvehicle = (Button) findViewById(R.id.add_button_vehicle);
          lv = (ListView) findViewById(R.id.listViewVehicles);
          reg = (EditText) findViewById(R.id.vehicle_reg);
          milge = (EditText) findViewById(R.id.vehicle_mileage);
          cap = (EditText) findViewById(R.id.vehicle_budget);
          budgt = (EditText) findViewById(R.id.vehicle_capacity);
  
  
  
          // Attach The Data From DataBase Into ListView Using Crusor Adapter
          Cursor cursor = dbcon.readData();
          String[] from = new String[] {DBhelper.VEHICLE_ID,DBhelper.VEHICLE_REG, DBhelper.VEHICLE_BUDGET, DBhelper.VEHICLE_CAPACITY };
  
          int[] to = new int[] { R.id.vehicle_id, R.id.vehicle_reg, R.id.vehicle_mileage, R.id.vehicle_budget,
                  R.id.vehicle_capacity };
          @SuppressWarnings("deprecation")
  
          SimpleCursorAdapter adapter = new SimpleCursorAdapter(
                  VehicleSetup.this, R.layout.view_car_entry, cursor, from, to);
          adapter.notifyDataSetChanged();
          lv.setAdapter(adapter);
  //      
          addvehicle.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  String registration = reg.getText().toString();
                  int mileage = Integer.parseInt(milge.getText().toString());
                  int capacity = Integer.parseInt(cap.getText().toString());
                  double budget = Double.parseDouble(budgt.getText().toString());
                  dbcon.insertData(registration, mileage, budget, capacity);
  
                  reg.setText("");
                  milge.setText("");
                  cap.setText("");
                  budgt.setText("");
  
  
              }
          });
  
  
  
      }
  </code></pre>