Unable to bundle datas

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Unable to bundle datas

Postby janaomate » Fri Aug 08, 2008 8:38 am

hi,
i did try to bundle the datas to pass to another activity. but i got the one error that can be in file attachments.


this is my code.....

newcontact.java:

package com.android.contact;

import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class newcontact extends Activity {
private final String MY_DATABASE_NAME = "DemoContact";
private final String MY_DATABASE_TABLE = "CONTACTS";
private EditText nametxt;
private EditText mobilenotxt;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
nametxt=(EditText)findViewById(R.id.addnametxt);
mobilenotxt=(EditText)findViewById(R.id.addnotxt);
Button save=(Button)findViewById(R.id.buttonsave);
save.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
filldata();
}
});
Button list=(Button)findViewById(R.id.buttoncancel);
list.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
listdata();
}
});
}
public void listdata()
{
Intent i=new Intent(this,democontact.class);
startActivity(i);
}
public void filldata()
{
SQLiteDatabase mydb=null;
String name=nametxt.getText().toString();
String mobileno=mobilenotxt.getText().toString();
try
{
//this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
mydb=this.openDatabase(MY_DATABASE_NAME, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS "
+MY_DATABASE_TABLE
+"(_id integer primary key autoincrement,name VARCHAR,mobileno NUMBER(15))");

try{

ContentValues initialvalues=new ContentValues();
initialvalues.put("name", name);
initialvalues.put("mobileno", mobileno);
mydb.insert(MY_DATABASE_TABLE, null, initialvalues);
}
catch(NullPointerException e)
{
}

}
catch(FileNotFoundException e)
{
}
finally {
if (mydb != null)
mydb.close();
}
Intent i=new Intent(this,democontact.class);
startActivity(i);
}

}

democontact.java:

package com.android.contact;

import java.io.FileNotFoundException;
import android.content.Intent;
import java.util.ArrayList;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;


public class democontact extends ListActivity
{
private static final int ACTIVITY_UPDATE=0;
private final String MY_DATABASE_NAME = "DemoContact";
private final String MY_DATABASE_TABLE = "CONTACTUsers";
public static final String KEY_NAME = "name";
public static final String KEY_MOBILE = "mobileno";

private Cursor c;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.contacts);
filldata();
}
public void filldata()
{
EditText et = new EditText(this);
et.setSelection(et.getText().length());
ArrayList<String> results = new ArrayList<String>();
SQLiteDatabase myDB = null;
try
{
//this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
myDB = this.openDatabase(MY_DATABASE_NAME, null);
c = myDB.query(true,MY_DATABASE_TABLE, new String[] {"name","mobileno"},"mobileno",null,null,null,null);

/* Get the indices of the Columns we will need */
int nameColumn = c.getColumnIndex("name");
int mobilenoColumn = c.getColumnIndex("mobileno");

/* Check if our result was valid. */
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. */
String Name = c.getString(nameColumn);
long Mobileno = c.getLong(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 mobilenoColumName = c.getColumnName(mobilenoColumn);

/* Add current Entry to results. */
results.add("" + i + ": " + Name
+ " (" + mobilenoColumName + ": " + Mobileno + ")");
} 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));

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);

Intent i=new Intent(this, contactupdate.class);
i.putExtra(KEY_NAME,c.getString(c.getColumnIndex("name")));
i.putExtra(KEY_MOBILE,c.getString(c.getColumnIndex("mobileno")));
startSubActivity(i,ACTIVITY_UPDATE);

}

}


thanks in advance
Attachments
error.JPG
error.JPG (13.34 KiB) Viewed 198 times
Always

thnks for every viewers
janaomate
Freshman
Freshman
 
Posts: 7
Joined: Wed Aug 06, 2008 6:30 am
Location: India

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 8 guests