In this following program i got NullPointerException could any one help me on this..
Thanks in advace
Shankar
package com.shankar.android2;
import android.app.ListActivity;
import android.os.Bundle;
import android.database.Cursor;
import java.lang.NullPointerException;
import java.io.FileNotFoundException;
import android.content.ContentValues;
import java.util.ArrayList;
import android.widget.EditText;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ArrayAdapter;
public class PhoneContacts extends ListActivity
{
private final String MY_DATABASE_NAME = "myCoolDB";
private final String MY_DATABASE_TABLE = "UserContacts";
private EditText nametxt;
private EditText mobilenotxt;
/** Called when the activity is first created. */
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.contact_list);
EditText et = new EditText(this);
et.setSelection(et.getText().length());
/* Will hold the 'Output' we want to display at the end. */
ArrayList<String> results = new ArrayList<String>();
nametxt=(EditText)findViewById(R.id.addnametxt);
mobilenotxt=(EditText)findViewById(R.id.addnotxt);
String name=nametxt.getText().toString();
String mobileno=mobilenotxt.getText().toString();
SQLiteDatabase myDB = null;
try
{
/* Create the Database (no Errors if it already exists) */
this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
/* Open the DB and remember it */
myDB = this.openDatabase(MY_DATABASE_NAME, null);
/* Create a Table in the Database. */
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ MY_DATABASE_TABLE
+ " (name VARCHAR NOT NULL"+ "mobileno INT(10)NOT NULL);");
ContentValues initialvalues = new ContentValues();
initialvalues.put("name", name);
initialvalues.put("mobileno", mobileno);
myDB.insert(MY_DATABASE_TABLE, null,initialvalues);
Cursor c = myDB.query(true,MY_DATABASE_TABLE, new String[] {"FirstName","Age"},"Age",null,null,null,null);
int namecolumn=c.getColumnIndex("name");
int mobilenocolumn=c.getColumnIndex("mobileno");
if (c != null)
{
/* Check if at least one Result was returned. */
if (c.first())
{
int i = 0;
/* Loop through all Results */
do
{
i++;
/* Retrieve the values of the Entry
* the Cursor is pointing to. */
try
{
String Name = c.getString(namecolumn);
int Mobileno = c.getInt(mobilenocolumn);
/* We can also receive the Name
* of a Column by its Index.
* Makes no sense, as we already
* know the Name, but just to shwo we can
*/
String MobilenoColumn = c.getColumnName(mobilenocolumn);
/* Add current Entry to results. */
results.add("" + i + ": " + Name
+ " (" + MobilenoColumn + ": " + Mobileno + ")");
}
catch(NullPointerException e)
{
}
} while (c.next());
}
}
}
catch (FileNotFoundException e)
{
}
finally
{
if (myDB != null)
myDB.close();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results));
}
}



