title: Keep getting a null pointer exception, can't find the source
body: <pre><code>E/AndroidRuntime(2886): FATAL EXCEPTION: main
  E/AndroidRuntime(2886): java.lang.NullPointerException
  E/AndroidRuntime(2886):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
  E/AndroidRuntime(2886):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
  E/AndroidRuntime(2886):     at android.widget.AbsListView.obtainView(AbsListView.java:2033)
  E/AndroidRuntime(2886):     at android.widget.GridView.onMeasure(GridView.java:1026)
  E/AndroidRuntime(2886):     at android.view.View.measure(View.java:12728)
  E/AndroidRuntime(2886):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1017)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
  E/AndroidRuntime(2886):     at android.view.View.measure(View.java:12728)
  E/AndroidRuntime(2886):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
  E/AndroidRuntime(2886):     at android.view.View.measure(View.java:12728)
  E/AndroidRuntime(2886):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
  E/AndroidRuntime(2886):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
  E/AndroidRuntime(2886):     at android.view.View.measure(View.java:12728)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
  E/AndroidRuntime(2886):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
  E/AndroidRuntime(2886):     at android.view.View.measure(View.java:12728)
  E/AndroidRuntime(2886):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
  E/AndroidRuntime(2886):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
  E/AndroidRuntime(2886):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
  E/AndroidRuntime(2886):     at android.view.View.measure(View.java:12728)
  E/AndroidRuntime(2886):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
  E/AndroidRuntime(2886):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
  E/AndroidRuntime(2886):     at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(2886):     at android.os.Looper.loop(Looper.java:137)
  E/AndroidRuntime(2886):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  E/AndroidRuntime(2886):     at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(2886):     at java.lang.reflect.Method.invoke(Method.java:511)
  E/AndroidRuntime(2886):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  E/AndroidRuntime(2886):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  E/AndroidRuntime(2886):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>there's the Logcat</p>
  
  <p>and here's (hopefully) relevant code. Where I think the problem originates</p>
  
  <pre><code>public class Main extends Activity {
      private static final int REQUEST_CODE = 0;
      List&lt;String&gt; custom1 = new ArrayList&lt;String&gt;();
      List&lt;String&gt; custom2 = new ArrayList&lt;String&gt;();
      List&lt;String&gt; custom3 = new ArrayList&lt;String&gt;();
      String title = null;
      ArrayAdapter&lt;String&gt; a1;
      ArrayAdapter&lt;String&gt; a2;
      ArrayAdapter&lt;String&gt; a3;
      Button b_1;
      Button b_2;
      Button b_3;
      NotesDataSource dataSource;
      MySQLiteHelper dbHelper;
      SQLiteDatabase db;
      int id;
      int position;
      boolean newNote;
  
      static int ADAPTER = 1;
  
       GridView gv;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          String savedText = null;
  
          Bundle extras = getIntent().getExtras();
          id = extras.getInt("id");
          position = extras.getInt("pos");
          newNote = !extras.getBoolean("load");
  
          dataSource = new NotesDataSource(this);
  
          final EditText tv = (EditText)findViewById(R.id.textArea);
          final EditText title_tv = (EditText)findViewById(R.id.noteTitle);
  
          if(!newNote){
              savedText = extras.getString("textData");
              title = extras.getString("title");
              if(savedText.length() != 0){
                  tv.append(savedText);
              }
              if(title.length() != 0){
                  title_tv.append(title);
              }
          }
          if(dataSource.getArray1() != null){
              custom1.addAll(dataSource.getArray1());
          }
          else{
              custom1.addAll(Arrays.asList(getResources().getStringArray(R.array.SymbolArray)));
          }
          if(dataSource.getArray2() != null){
              custom2.addAll(dataSource.getArray2());
          } 
          else{
              custom2.addAll(Arrays.asList(getResources().getStringArray(R.array.SymbolArray)));
          }
          if(dataSource.getArray3() != null){
              custom3.addAll(dataSource.getArray3());
          }
          else{
              custom3.addAll(Arrays.asList(getResources().getStringArray(R.array.SymbolArray)));
          }
  
          a1 = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,custom1);
          a2 = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,custom2);
          a3 = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,custom3);
  
          gv = (GridView)findViewById(R.id.gridView);
          gv.setAdapter(a1);
          ADAPTER = 1;
          gv.isFocusable();
          gv.isFocusableInTouchMode();
  
          gv.setOnItemClickListener(new OnItemClickListener(){
              public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id){
                  switch(ADAPTER){
                  case 1:
                      tv.append(custom1.get(position));
                      break;
                  case 2:
                      tv.append(custom2.get(position));
                      break;
                  case 3:
                      tv.append(custom3.get(position));
                  default:
                      break;
                  }
              }
          });
  
          b_1 = (Button)findViewById(R.id.button1);
          b_2 = (Button)findViewById(R.id.button2);
          b_3 = (Button)findViewById(R.id.button3);
          Button b_save = (Button)findViewById(R.id.save_button);
  
          b_1.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  gv.setAdapter(a1);
                  ADAPTER = 1;
  
              }
          });
  
          b_2.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  gv.setAdapter(a2);
                  ADAPTER = 2;
              }
          });
  
          b_3.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  gv.setAdapter(a3);
                  ADAPTER = 3;
  
              }
          });
  
          b_save.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  if(newNote == false){
                      dataSource.open();
                      String text = tv.getText().toString();
                      if(title.length() != 0){
                          title = title_tv.getText().toString();
                          dataSource.updateString(text,title,id);
                      }
                      else{
                          dataSource.updateString(text, "no title", id);
                      }
                      dataSource.close();
                  }
                  else{
                      dataSource.open();
                      String text = tv.getText().toString();
                      title = title_tv.getText().toString();
  
                      dataSource.createString(text, title);
                      newNote = false;
                      dataSource.close();
                  }
              }
          });    
  
      }
  </code></pre>
  
  <p>Here's the three array methods</p>
  
  <pre><code>    public List&lt;String&gt; getArray1(){
              ArrayList&lt;String&gt; array1 = new ArrayList&lt;String&gt;();
  
              open();
              Cursor cursor = db.query(MySQLiteHelper.TABLE_ARRAY, new String[]{MySQLiteHelper.COLUMN_ARRAY_1}, null, null, null, null, null);
              cursor.moveToFirst();
              while(!cursor.isAfterLast()){
                  String data = cursorToArrayString(cursor);
                  array1.add(data);
                  cursor.moveToNext();
              }
              //make sure to close the cursor
              close();
              return array1;
          }
  
          public List&lt;String&gt; getArray2(){
              ArrayList&lt;String&gt; array2 = new ArrayList&lt;String&gt;();
  
              open();
              Cursor cursor = db.query(MySQLiteHelper.TABLE_ARRAY, new String[]{MySQLiteHelper.COLUMN_ARRAY_2}, null,null,null,null,null);
              cursor.moveToFirst();
              while(!cursor.isAfterLast()){
                  String data = cursorToArrayString(cursor);
                  array2.add(data);
                  cursor.moveToNext();
              }
              //make sure to close the cursor
              close();
              return array2;
          }
  
          public List&lt;String&gt; getArray3(){
              ArrayList&lt;String&gt; array3 = new ArrayList&lt;String&gt;();
  
              open();
              Cursor cursor = db.query(MySQLiteHelper.TABLE_ARRAY, new String[]{MySQLiteHelper.COLUMN_ARRAY_3}, null,null,null,null,null);
              cursor.moveToFirst();
              while(!cursor.isAfterLast()){
                  String data = cursorToArrayString(cursor);
                  array3.add(data);
                  cursor.moveToNext();
              }
              //make sure to close the cursor
              close();
              return array3;
          }
  
  
  and finally how they're updated 
  
  
  public void updateArray(String[] array1, String[] array2, String[] array3){
  
          db.delete(MySQLiteHelper.TABLE_ARRAY, null, null);
  
          ContentValues values1 = new ContentValues();
          for(int i = 0; i &lt; array1.length; i++){
              values1.put(MySQLiteHelper.COLUMN_ARRAY_1, array1[i]);
              int rows = db.update(MySQLiteHelper.TABLE_ARRAY, values1, MySQLiteHelper.COLUMN_ID + " = " + i, null);
              if(rows == 0){
                  db.insert(MySQLiteHelper.TABLE_ARRAY, null, values1);
              }
          }
  
  
          ContentValues values2 = new ContentValues();
          for(int i = 0; i &lt; array2.length; i++){
              values2.put(MySQLiteHelper.COLUMN_ARRAY_2, array2[i]);
              int rows = db.update(MySQLiteHelper.TABLE_ARRAY, values2, MySQLiteHelper.COLUMN_ID + " = " + i, null);
              if(rows == 0){
                  db.insert(MySQLiteHelper.TABLE_ARRAY, null, values2);
              }
          }
  
          ContentValues values3 = new ContentValues();
          for(int i = 0; i &lt; array3.length; i++){
              values3.put(MySQLiteHelper.COLUMN_ARRAY_3, array3[i]);
              int rows = db.update(MySQLiteHelper.TABLE_ARRAY, values3, MySQLiteHelper.COLUMN_ID + " = " + i, null);
              if(rows == 0){
                  db.insert(MySQLiteHelper.TABLE_ARRAY, null, values3);
              }
          }
      }
  </code></pre>
  
  <p>go easy on me, this is my first time working with databases, but I'd love to know what the issues is, I've been working on this problem for days now</p>