Find my Error????

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

Find my Error????

Postby shank586 » Thu Jul 31, 2008 7:41 am

HI all,


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));

}

}
Attachments
untitled.GIF
This is my Error!!!!!!
(22.98 KiB) Downloaded 79 times
shank586
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri Jun 20, 2008 3:22 pm

Top

Postby cgreen » Fri Aug 01, 2008 9:59 am

use the ddms tool to debug. the device exception messages are rubbish.
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby janaomate » Wed Aug 06, 2008 6:35 am

cgreen wrote:use the ddms tool to debug. the device exception messages are rubbish.



Hi cgreen,

how to use the ddms tool in debug....
Always

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

Postby janaomate » Wed Aug 06, 2008 6:37 am

that means steps...
Always

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

Postby cgreen » Wed Aug 06, 2008 9:09 am

Dalvik Debug Monitor Service
Google's page about the DDMS

This is an essential debugging tool for android. Without it, you'll be lost searching the cause of NullPointerExceptions forever, because there aren't any comprehensible stacktraces anywhere in the default UI.

Starting is as easy as starting the emulator:
1) Open a shell ( e.g. Start->Run->cmd )
2) Change directory to your Android SDK Installation directory.
3) There change to the directory tools/
4) Type ddms
5) On the left hand side, if started, you're ought to see your emulator. Click on it!
6) Get ready for a lot of debugging information. NullPointerExceptions are usually colored red.


Any questions or advice ?
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby janaomate » Wed Aug 06, 2008 11:00 am

cgreen wrote:Dalvik Debug Monitor Service
Google's page about the DDMS

This is an essential debugging tool for android. Without it, you'll be lost searching the cause of NullPointerExceptions forever, because there aren't any comprehensible stacktraces anywhere in the default UI.

Starting is as easy as starting the emulator:
1) Open a shell ( e.g. Start->Run->cmd )
2) Change directory to your Android SDK Installation directory.
3) There change to the directory tools/
4) Type ddms
5) On the left hand side, if started, you're ought to see your emulator. Click on it!
6) Get ready for a lot of debugging information. NullPointerExceptions are usually colored red.


Any questions or advice ?


hii cgreen,

I got the nullpointerexceptions is "Granting new permission android.permission to WRITE_CONTACTS TO android.server.packagemanagerservice$shared usersettings".
I got a no of these like lines in ddms... what can i do
Always

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

Top

Postby cgreen » Wed Aug 06, 2008 12:50 pm

maybe add
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.WRITE_CONTACTS">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
to your AndroidManifestFile.xml. just a guess
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby janaomate » Fri Aug 08, 2008 5:07 am

cgreen wrote:maybe add
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.WRITE_CONTACTS">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
to your AndroidManifestFile.xml. just a guess




sorry cgreen,

it didnt work.. I will continue to clear this exception....

thnks.......
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 6 guests