Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old September 22nd, 2010, 10:46 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2010
Posts: 11
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default NullPointerException, can't see why??

Hello guys, please have a look at this code and see if you could help me out. viewItem is populating from a database and the method fillRemindersData(long rowId) is only called from the reminder class. I don't know why i am getting a nullPointerException when calling the viewitems.fillRemindersData()method. if i comment the line, the code works fine and the rowId is correct. hat could be the reason? thanks

Code:
// this is a reminder class
public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_list);
		adapter = new DBAdapter(this);
		viewItems = new ViewItems();
		fillReminder();		
	}
	
	private void fillReminder() {
		Bundle extra = getIntent().getExtras();
		if(extra != null){
			rowId = extra.getLong(DBAdapter.KEY_ID);
			
			
			message = extra.getString(NewItem.Test);
		}
		Toast.makeText(this, message + "its ok here" + rowId, Toast.LENGTH_LONG).show();
		viewItems.fillRemindersData(rowId); // having a null pointer exception here.
}
And important part of the viewItems class is:

Code:
public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_list);
		adapter = new DBAdapter(this);
		adapter.open();
		fillData();
		list = (ListView)findViewById(android.R.id.list);
		list.setOnItemClickListener(this);
		
		
	}
	
	
	protected void fillData() {
		
	Cursor c = adapter.retrieveItems(); // method in sqlitedatabase
	startManagingCursor(c);
		
String[] from = new String[]{DBAdapter.NAME, DBAdapter.START_DATE, DBAdapter.START_TIME};
int[] to = new int[]{R.id.viewNameId, R.id.viewDateId, R.id.viewTimeId};
				
customCursorAdapter items = new customCursorAdapter(this, R.layout.view_items, c, from, to);
				setListAdapter(items);			
		       
	}
	
           protected void fillRemindersData(long Id) {
           long row = Id;
          Cursor c = adapter.retrieveRow(row); // method in sqlitedatabase
           startManagingCursor(c);
		
String[] from = new String[]{DBAdapter.NAME, DBAdapter.START_DATE, DBAdapter.START_TIME};

int[] to = new int[]{R.id.RemindNameId, R.id.remindDateId, R.id.remindTimeId};
				
customCursorAdapter items = new customCursorAdapter(this, R.layout.remind_viewer, c, from, to);
setListAdapter(items);			
		       
	}

motoko is offline  
Reply With Quote
Sponsors
Old September 27th, 2010, 06:08 AM   #2 (permalink)
Junior Member
 
Join Date: Jun 2010
Location: Sunderland, UK
Posts: 63
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 4
Thanked 8 Times in 5 Posts
Default

Have you tried moving the } bracket on your if to after the point where you populate your list

Your code

Code:
}
Toast.makeText(this, message + "its ok here" + rowId, Toast.LENGTH_LONG).show();
viewItems.fillRemindersData(rowId); // having a null pointer exception here.
Alternative

Code:
Toast.makeText(this, message + "its ok here" + rowId, Toast.LENGTH_LONG).show();
viewItems.fillRemindersData(rowId); // having a null pointer exception here.
}
I think if your Bundle is empty you will get a null pointer exception.
wabbitt1970 is offline  
Reply With Quote
Reply
Tags
android


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:15 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.