[android-developers] Re: Null pointer exception when finding views by Id

2008-03-31 Thread kaiping

Thanks for the help.  I finally just trashed both the xml and class
files and rewrote then.  It works now, I think it had to do with the
DatePicker.  Thanks for the help.

KaiPing

On Mar 28, 8:07 pm, Peli <[EMAIL PROTECTED]> wrote:
> Which is the line that causes the null-pointer exception? The code
> lines you posted surely don't as they just assign the values. How do
> you know that the values are 'null' in onCreate()?
> What is in EditTransaction.java:47 ?
>
> Peli
>
> On Mar 28, 12:38 pm,kaiping<[EMAIL PROTECTED]> wrote:
>
> > OK, Did that and it still has the same error
>
> > On Mar 27, 11:43 pm, Peli <[EMAIL PROTECTED]> wrote:
>
> > > Sometimes R.java is corrupted. It helps to clean everything either
> > > from within Eclipse or manually (delete bin/ and R.java) and rebuild
> > > from scratch.
>
> > > Peli
>
> > > On Mar 27, 2:44 pm,kaiping<[EMAIL PROTECTED]> wrote:
>
> > > > I am sure, Actually the R.id.account_name was a type I forgot to fix.
> > > > But, even the once that are in there return null.
>
> > > > On Mar 27, 12:16 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > > Are you sure ALL the findViewById return null? This one does for sure:
> > > > > mDescription = (EditText) findViewById(R.id.account_name); since there
> > > > > is no account_name id in your layout.
>
> > > > > On Mar 26, 6:19 am,kaiping<[EMAIL PROTECTED]> wrote:
>
> > > > > > Thanks for the idea.  I have confirmed that the file is named
> > > > > > transaction_edit.xml.
>
> > > > > > On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > > > > Well, he needs to have the filename be transaction_edit.xml. Not 
> > > > > > > sure
> > > > > > > if it is.
>
> > > > > > > On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > Don't you need to name your layout "transaction_edit" in the 
> > > > > > > > XML file?
>
> > > > > > > > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > > > > > > > Hi, For one of my Activities All the findViewById() function 
> > > > > > > > > returns
> > > > > > > > > is null.  I am really astonished by this behaviour because 
> > > > > > > > > this same
> > > > > > > > > function works fine in other parts of my application.  I have 
> > > > > > > > > posted
> > > > > > > > > the code below.  If anybody has any ideas that would be great 
> > > > > > > > > thanks,
>
> > > > > > > > > Josh
>
> > > > > > > > > package com.jingsys.money;
>
> > > > > > > > > import java.util.ArrayList;
>
> > > > > > > > > import android.app.Activity;
> > > > > > > > > import android.database.Cursor;
> > > > > > > > > import android.os.Bundle;
> > > > > > > > > import android.widget.ArrayAdapter;
> > > > > > > > > import android.widget.DatePicker;
> > > > > > > > > import android.widget.EditText;
> > > > > > > > > import android.widget.Spinner;
>
> > > > > > > > > import com.jingsys.money.data.AccountsDbAdapter;
> > > > > > > > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > > > > > > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > > > > > > > public class EditTransaction extends Activity {
>
> > > > > > > > >private  DatePicker mDate;
> > > > > > > > >private  EditText mDescription;
> > > > > > > > >private  EditText mNumber;
> > > > > > > > >private  EditText mAmount;
> > > > > > > > >private  Spinner mFromAccount;
> > > > > > > > >private  Spinner mToAccount;
> > > > > > > > >private  EditText mComments;
>
> > > > > > > > >private TransactionDbAdapter transData;
> > > > > > > > >private AccountsDbAdapter accountData;
>
> > > > > > > > >private Cursor mFrom;
> > > > > > > > >private Cursor mTo;
>
> > > > > > > > >@Override
> > > > > > > > >protected void onCreate(Bundle icicle) {
> > > > > > > > >super.onCreate(icicle);
> > > > > > > > >setContentView(R.layout.transaction_edit);
>
> > > > > > > > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > > > > > > > >mDescription = (EditText) 
> > > > > > > > > findViewById(R.id.account_name);
> > > > > > > > >mNumber = (EditText) 
> > > > > > > > > findViewById(R.id.trans_number);
> > > > > > > > >mAmount = (EditText) 
> > > > > > > > > findViewById(R.id.trans_amount);
> > > > > > > > >mComments = (EditText) 
> > > > > > > > > findViewById(R.id.trans_comments);
>
> > > > > > > > >mFromAccount = (Spinner) 
> > > > > > > > > findViewById(R.id.trans_from);
> > > > > > > > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > > > > > > > XML file
> > > > > > > > > 
> > > > > > > > >  > > > > > > > > xmlns:android="http://schemas.android.com/apk/res/
> > > > > > > > > android"
> > > > > > > > >android:layout_width="fill_parent"
> > > > > > > > >android:layout_height="fill_parent"
> > > > > > > > >android:stretchColumns="1">
> > > > > > > > >
> > > > > > > > > > > > > > > > >android:layout_height="wrap_conten

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-28 Thread Peli

Which is the line that causes the null-pointer exception? The code
lines you posted surely don't as they just assign the values. How do
you know that the values are 'null' in onCreate()?
What is in EditTransaction.java:47 ?

Peli

On Mar 28, 12:38 pm, kaiping <[EMAIL PROTECTED]> wrote:
> OK, Did that and it still has the same error
>
> On Mar 27, 11:43 pm, Peli <[EMAIL PROTECTED]> wrote:
>
> > Sometimes R.java is corrupted. It helps to clean everything either
> > from within Eclipse or manually (delete bin/ and R.java) and rebuild
> > from scratch.
>
> > Peli
>
> > On Mar 27, 2:44 pm,kaiping<[EMAIL PROTECTED]> wrote:
>
> > > I am sure, Actually the R.id.account_name was a type I forgot to fix.
> > > But, even the once that are in there return null.
>
> > > On Mar 27, 12:16 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > Are you sure ALL the findViewById return null? This one does for sure:
> > > > mDescription = (EditText) findViewById(R.id.account_name); since there
> > > > is no account_name id in your layout.
>
> > > > On Mar 26, 6:19 am,kaiping<[EMAIL PROTECTED]> wrote:
>
> > > > > Thanks for the idea.  I have confirmed that the file is named
> > > > > transaction_edit.xml.
>
> > > > > On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > > > Well, he needs to have the filename be transaction_edit.xml. Not 
> > > > > > sure
> > > > > > if it is.
>
> > > > > > On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > > > > > > Don't you need to name your layout "transaction_edit" in the XML 
> > > > > > > file?
>
> > > > > > > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > > > > > > Hi, For one of my Activities All the findViewById() function 
> > > > > > > > returns
> > > > > > > > is null.  I am really astonished by this behaviour because this 
> > > > > > > > same
> > > > > > > > function works fine in other parts of my application.  I have 
> > > > > > > > posted
> > > > > > > > the code below.  If anybody has any ideas that would be great 
> > > > > > > > thanks,
>
> > > > > > > > Josh
>
> > > > > > > > package com.jingsys.money;
>
> > > > > > > > import java.util.ArrayList;
>
> > > > > > > > import android.app.Activity;
> > > > > > > > import android.database.Cursor;
> > > > > > > > import android.os.Bundle;
> > > > > > > > import android.widget.ArrayAdapter;
> > > > > > > > import android.widget.DatePicker;
> > > > > > > > import android.widget.EditText;
> > > > > > > > import android.widget.Spinner;
>
> > > > > > > > import com.jingsys.money.data.AccountsDbAdapter;
> > > > > > > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > > > > > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > > > > > > public class EditTransaction extends Activity {
>
> > > > > > > >private  DatePicker mDate;
> > > > > > > >private  EditText mDescription;
> > > > > > > >private  EditText mNumber;
> > > > > > > >private  EditText mAmount;
> > > > > > > >private  Spinner mFromAccount;
> > > > > > > >private  Spinner mToAccount;
> > > > > > > >private  EditText mComments;
>
> > > > > > > >private TransactionDbAdapter transData;
> > > > > > > >private AccountsDbAdapter accountData;
>
> > > > > > > >private Cursor mFrom;
> > > > > > > >private Cursor mTo;
>
> > > > > > > >@Override
> > > > > > > >protected void onCreate(Bundle icicle) {
> > > > > > > >super.onCreate(icicle);
> > > > > > > >setContentView(R.layout.transaction_edit);
>
> > > > > > > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > > > > > > >mDescription = (EditText) 
> > > > > > > > findViewById(R.id.account_name);
> > > > > > > >mNumber = (EditText) findViewById(R.id.trans_number);
> > > > > > > >mAmount = (EditText) findViewById(R.id.trans_amount);
> > > > > > > >mComments = (EditText) 
> > > > > > > > findViewById(R.id.trans_comments);
>
> > > > > > > >mFromAccount = (Spinner) 
> > > > > > > > findViewById(R.id.trans_from);
> > > > > > > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > > > > > > XML file
> > > > > > > > 
> > > > > > > > http://schemas.android.com/apk/res/
> > > > > > > > android"
> > > > > > > >android:layout_width="fill_parent"
> > > > > > > >android:layout_height="fill_parent"
> > > > > > > >android:stretchColumns="1">
> > > > > > > >
> > > > > > > > > > > > > > >android:layout_height="wrap_content"
> > > > > > > >android:text="@string/transaction_date" />
> > > > > > > > > > > > > > >  android:layout_width="wrap_content"
> > > > > > > >android:layout_height="wrap_content" />
> > > > > > > >
>
> > > > > > > >
> > > > > > > > > > > > > > >android:layout_height="wrap_content"
> > > > > > > >
> > > > > > > > android:text="@string/transaction_descri

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-28 Thread kaiping

OK, Did that and it still has the same error

On Mar 27, 11:43 pm, Peli <[EMAIL PROTECTED]> wrote:
> Sometimes R.java is corrupted. It helps to clean everything either
> from within Eclipse or manually (delete bin/ and R.java) and rebuild
> from scratch.
>
> Peli
>
> On Mar 27, 2:44 pm,kaiping<[EMAIL PROTECTED]> wrote:
>
> > I am sure, Actually the R.id.account_name was a type I forgot to fix.
> > But, even the once that are in there return null.
>
> > On Mar 27, 12:16 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > Are you sure ALL the findViewById return null? This one does for sure:
> > > mDescription = (EditText) findViewById(R.id.account_name); since there
> > > is no account_name id in your layout.
>
> > > On Mar 26, 6:19 am,kaiping<[EMAIL PROTECTED]> wrote:
>
> > > > Thanks for the idea.  I have confirmed that the file is named
> > > > transaction_edit.xml.
>
> > > > On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > > Well, he needs to have the filename be transaction_edit.xml. Not sure
> > > > > if it is.
>
> > > > > On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > > > > > Don't you need to name your layout "transaction_edit" in the XML 
> > > > > > file?
>
> > > > > > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > > > > > Hi, For one of my Activities All the findViewById() function 
> > > > > > > returns
> > > > > > > is null.  I am really astonished by this behaviour because this 
> > > > > > > same
> > > > > > > function works fine in other parts of my application.  I have 
> > > > > > > posted
> > > > > > > the code below.  If anybody has any ideas that would be great 
> > > > > > > thanks,
>
> > > > > > > Josh
>
> > > > > > > package com.jingsys.money;
>
> > > > > > > import java.util.ArrayList;
>
> > > > > > > import android.app.Activity;
> > > > > > > import android.database.Cursor;
> > > > > > > import android.os.Bundle;
> > > > > > > import android.widget.ArrayAdapter;
> > > > > > > import android.widget.DatePicker;
> > > > > > > import android.widget.EditText;
> > > > > > > import android.widget.Spinner;
>
> > > > > > > import com.jingsys.money.data.AccountsDbAdapter;
> > > > > > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > > > > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > > > > > public class EditTransaction extends Activity {
>
> > > > > > >private  DatePicker mDate;
> > > > > > >private  EditText mDescription;
> > > > > > >private  EditText mNumber;
> > > > > > >private  EditText mAmount;
> > > > > > >private  Spinner mFromAccount;
> > > > > > >private  Spinner mToAccount;
> > > > > > >private  EditText mComments;
>
> > > > > > >private TransactionDbAdapter transData;
> > > > > > >private AccountsDbAdapter accountData;
>
> > > > > > >private Cursor mFrom;
> > > > > > >private Cursor mTo;
>
> > > > > > >@Override
> > > > > > >protected void onCreate(Bundle icicle) {
> > > > > > >super.onCreate(icicle);
> > > > > > >setContentView(R.layout.transaction_edit);
>
> > > > > > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > > > > > >mDescription = (EditText) 
> > > > > > > findViewById(R.id.account_name);
> > > > > > >mNumber = (EditText) findViewById(R.id.trans_number);
> > > > > > >mAmount = (EditText) findViewById(R.id.trans_amount);
> > > > > > >mComments = (EditText) 
> > > > > > > findViewById(R.id.trans_comments);
>
> > > > > > >mFromAccount = (Spinner) findViewById(R.id.trans_from);
> > > > > > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > > > > > XML file
> > > > > > > 
> > > > > > > http://schemas.android.com/apk/res/
> > > > > > > android"
> > > > > > >android:layout_width="fill_parent"
> > > > > > >android:layout_height="fill_parent"
> > > > > > >android:stretchColumns="1">
> > > > > > >
> > > > > > > > > > > > >android:layout_height="wrap_content"
> > > > > > >android:text="@string/transaction_date" />
> > > > > > > > > > > > >  android:layout_width="wrap_content"
> > > > > > >android:layout_height="wrap_content" />
> > > > > > >
>
> > > > > > >
> > > > > > > > > > > > >android:layout_height="wrap_content"
> > > > > > >android:text="@string/transaction_description" 
> > > > > > > />
> > > > > > > > > > > > >android:layout_width="wrap_content"
> > > > > > >android:layout_height="wrap_content"/>
> > > > > > >
>
> > > > > > >
> > > > > > > > > > > > >android:layout_height="wrap_content"
> > > > > > >android:text="@string/transaction_number"/>
> > > > > > > > > > > > >android:layout_width="wrap_content"
> > > > > > >

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-27 Thread Peli

Sometimes R.java is corrupted. It helps to clean everything either
from within Eclipse or manually (delete bin/ and R.java) and rebuild
from scratch.

Peli

On Mar 27, 2:44 pm, kaiping <[EMAIL PROTECTED]> wrote:
> I am sure, Actually the R.id.account_name was a type I forgot to fix.
> But, even the once that are in there return null.
>
> On Mar 27, 12:16 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > Are you sure ALL the findViewById return null? This one does for sure:
> > mDescription = (EditText) findViewById(R.id.account_name); since there
> > is no account_name id in your layout.
>
> > On Mar 26, 6:19 am,kaiping<[EMAIL PROTECTED]> wrote:
>
> > > Thanks for the idea.  I have confirmed that the file is named
> > > transaction_edit.xml.
>
> > > On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > Well, he needs to have the filename be transaction_edit.xml. Not sure
> > > > if it is.
>
> > > > On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > > > > Don't you need to name your layout "transaction_edit" in the XML file?
>
> > > > > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > > > > Hi, For one of my Activities All the findViewById() function returns
> > > > > > is null.  I am really astonished by this behaviour because this same
> > > > > > function works fine in other parts of my application.  I have posted
> > > > > > the code below.  If anybody has any ideas that would be great 
> > > > > > thanks,
>
> > > > > > Josh
>
> > > > > > package com.jingsys.money;
>
> > > > > > import java.util.ArrayList;
>
> > > > > > import android.app.Activity;
> > > > > > import android.database.Cursor;
> > > > > > import android.os.Bundle;
> > > > > > import android.widget.ArrayAdapter;
> > > > > > import android.widget.DatePicker;
> > > > > > import android.widget.EditText;
> > > > > > import android.widget.Spinner;
>
> > > > > > import com.jingsys.money.data.AccountsDbAdapter;
> > > > > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > > > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > > > > public class EditTransaction extends Activity {
>
> > > > > >private  DatePicker mDate;
> > > > > >private  EditText mDescription;
> > > > > >private  EditText mNumber;
> > > > > >private  EditText mAmount;
> > > > > >private  Spinner mFromAccount;
> > > > > >private  Spinner mToAccount;
> > > > > >private  EditText mComments;
>
> > > > > >private TransactionDbAdapter transData;
> > > > > >private AccountsDbAdapter accountData;
>
> > > > > >private Cursor mFrom;
> > > > > >private Cursor mTo;
>
> > > > > >@Override
> > > > > >protected void onCreate(Bundle icicle) {
> > > > > >super.onCreate(icicle);
> > > > > >setContentView(R.layout.transaction_edit);
>
> > > > > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > > > > >mDescription = (EditText) 
> > > > > > findViewById(R.id.account_name);
> > > > > >mNumber = (EditText) findViewById(R.id.trans_number);
> > > > > >mAmount = (EditText) findViewById(R.id.trans_amount);
> > > > > >mComments = (EditText) findViewById(R.id.trans_comments);
>
> > > > > >mFromAccount = (Spinner) findViewById(R.id.trans_from);
> > > > > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > > > > XML file
> > > > > > 
> > > > > > http://schemas.android.com/apk/res/
> > > > > > android"
> > > > > >android:layout_width="fill_parent"
> > > > > >android:layout_height="fill_parent"
> > > > > >android:stretchColumns="1">
> > > > > >
> > > > > > > > > > >android:layout_height="wrap_content"
> > > > > >android:text="@string/transaction_date" />
> > > > > > > > > > >  android:layout_width="wrap_content"
> > > > > >android:layout_height="wrap_content" />
> > > > > >
>
> > > > > >
> > > > > > > > > > >android:layout_height="wrap_content"
> > > > > >android:text="@string/transaction_description" />
> > > > > > > > > > >android:layout_width="wrap_content"
> > > > > >android:layout_height="wrap_content"/>
> > > > > >
>
> > > > > >
> > > > > > > > > > >android:layout_height="wrap_content"
> > > > > >android:text="@string/transaction_number"/>
> > > > > > > > > > >android:layout_width="wrap_content"
> > > > > >android:layout_height="wrap_content"/>
> > > > > >
>
> > > > > >
> > > > > > > > > > >android:layout_height="wrap_content"
> > > > > >android:text="@string/transaction_amount"/>
> > > > > > > > > > >android:layout_width="wrap_content"
> > > > > >and

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-27 Thread kaiping

I am sure, Actually the R.id.account_name was a type I forgot to fix.
But, even the once that are in there return null.

On Mar 27, 12:16 am, "Dan U." <[EMAIL PROTECTED]> wrote:
> Are you sure ALL the findViewById return null? This one does for sure:
> mDescription = (EditText) findViewById(R.id.account_name); since there
> is no account_name id in your layout.
>
> On Mar 26, 6:19 am,kaiping<[EMAIL PROTECTED]> wrote:
>
> > Thanks for the idea.  I have confirmed that the file is named
> > transaction_edit.xml.
>
> > On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > Well, he needs to have the filename be transaction_edit.xml. Not sure
> > > if it is.
>
> > > On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > > > Don't you need to name your layout "transaction_edit" in the XML file?
>
> > > > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > > > Hi, For one of my Activities All the findViewById() function returns
> > > > > is null.  I am really astonished by this behaviour because this same
> > > > > function works fine in other parts of my application.  I have posted
> > > > > the code below.  If anybody has any ideas that would be great thanks,
>
> > > > > Josh
>
> > > > > package com.jingsys.money;
>
> > > > > import java.util.ArrayList;
>
> > > > > import android.app.Activity;
> > > > > import android.database.Cursor;
> > > > > import android.os.Bundle;
> > > > > import android.widget.ArrayAdapter;
> > > > > import android.widget.DatePicker;
> > > > > import android.widget.EditText;
> > > > > import android.widget.Spinner;
>
> > > > > import com.jingsys.money.data.AccountsDbAdapter;
> > > > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > > > public class EditTransaction extends Activity {
>
> > > > >private  DatePicker mDate;
> > > > >private  EditText mDescription;
> > > > >private  EditText mNumber;
> > > > >private  EditText mAmount;
> > > > >private  Spinner mFromAccount;
> > > > >private  Spinner mToAccount;
> > > > >private  EditText mComments;
>
> > > > >private TransactionDbAdapter transData;
> > > > >private AccountsDbAdapter accountData;
>
> > > > >private Cursor mFrom;
> > > > >private Cursor mTo;
>
> > > > >@Override
> > > > >protected void onCreate(Bundle icicle) {
> > > > >super.onCreate(icicle);
> > > > >setContentView(R.layout.transaction_edit);
>
> > > > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > > > >mDescription = (EditText) findViewById(R.id.account_name);
> > > > >mNumber = (EditText) findViewById(R.id.trans_number);
> > > > >mAmount = (EditText) findViewById(R.id.trans_amount);
> > > > >mComments = (EditText) findViewById(R.id.trans_comments);
>
> > > > >mFromAccount = (Spinner) findViewById(R.id.trans_from);
> > > > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > > > XML file
> > > > > 
> > > > > http://schemas.android.com/apk/res/
> > > > > android"
> > > > >android:layout_width="fill_parent"
> > > > >android:layout_height="fill_parent"
> > > > >android:stretchColumns="1">
> > > > >
> > > > > > > > >android:layout_height="wrap_content"
> > > > >android:text="@string/transaction_date" />
> > > > > > > > >  android:layout_width="wrap_content"
> > > > >android:layout_height="wrap_content" />
> > > > >
>
> > > > >
> > > > > > > > >android:layout_height="wrap_content"
> > > > >android:text="@string/transaction_description" />
> > > > > > > > >android:layout_width="wrap_content"
> > > > >android:layout_height="wrap_content"/>
> > > > >
>
> > > > >
> > > > > > > > >android:layout_height="wrap_content"
> > > > >android:text="@string/transaction_number"/>
> > > > > > > > >android:layout_width="wrap_content"
> > > > >android:layout_height="wrap_content"/>
> > > > >
>
> > > > >
> > > > > > > > >android:layout_height="wrap_content"
> > > > >android:text="@string/transaction_amount"/>
> > > > > > > > >android:layout_width="wrap_content"
> > > > >android:layout_height="wrap_content"/>
> > > > >
>
> > > > >
> > > > > > > > >android:layout_height="wrap_content"
> > > > >android:text="@string/transaction_from"/>
> > > > > > > > >android:layout_width="wrap_content"
> > > > >android:layout_height="fill_parent"/>
> > > > >
>
> > > > >
> > > > > 

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-26 Thread Dan U.

Are you sure ALL the findViewById return null? This one does for sure:
mDescription = (EditText) findViewById(R.id.account_name); since there
is no account_name id in your layout.

On Mar 26, 6:19 am, kaiping <[EMAIL PROTECTED]> wrote:
> Thanks for the idea.  I have confirmed that the file is named
> transaction_edit.xml.
>
> On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > Well, he needs to have the filename be transaction_edit.xml. Not sure
> > if it is.
>
> > On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > > Don't you need to name your layout "transaction_edit" in the XML file?
>
> > > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > > Hi, For one of my Activities All the findViewById() function returns
> > > > is null.  I am really astonished by this behaviour because this same
> > > > function works fine in other parts of my application.  I have posted
> > > > the code below.  If anybody has any ideas that would be great thanks,
>
> > > > Josh
>
> > > > package com.jingsys.money;
>
> > > > import java.util.ArrayList;
>
> > > > import android.app.Activity;
> > > > import android.database.Cursor;
> > > > import android.os.Bundle;
> > > > import android.widget.ArrayAdapter;
> > > > import android.widget.DatePicker;
> > > > import android.widget.EditText;
> > > > import android.widget.Spinner;
>
> > > > import com.jingsys.money.data.AccountsDbAdapter;
> > > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > > public class EditTransaction extends Activity {
>
> > > >private  DatePicker mDate;
> > > >private  EditText mDescription;
> > > >private  EditText mNumber;
> > > >private  EditText mAmount;
> > > >private  Spinner mFromAccount;
> > > >private  Spinner mToAccount;
> > > >private  EditText mComments;
>
> > > >private TransactionDbAdapter transData;
> > > >private AccountsDbAdapter accountData;
>
> > > >private Cursor mFrom;
> > > >private Cursor mTo;
>
> > > >@Override
> > > >protected void onCreate(Bundle icicle) {
> > > >super.onCreate(icicle);
> > > >setContentView(R.layout.transaction_edit);
>
> > > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > > >mDescription = (EditText) findViewById(R.id.account_name);
> > > >mNumber = (EditText) findViewById(R.id.trans_number);
> > > >mAmount = (EditText) findViewById(R.id.trans_amount);
> > > >mComments = (EditText) findViewById(R.id.trans_comments);
>
> > > >mFromAccount = (Spinner) findViewById(R.id.trans_from);
> > > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > > XML file
> > > > 
> > > > http://schemas.android.com/apk/res/
> > > > android"
> > > >android:layout_width="fill_parent"
> > > >android:layout_height="fill_parent"
> > > >android:stretchColumns="1">
> > > >
> > > > > > >android:layout_height="wrap_content"
> > > >android:text="@string/transaction_date" />
> > > > > > >  android:layout_width="wrap_content"
> > > >android:layout_height="wrap_content" />
> > > >
>
> > > >
> > > > > > >android:layout_height="wrap_content"
> > > >android:text="@string/transaction_description" />
> > > > > > >android:layout_width="wrap_content"
> > > >android:layout_height="wrap_content"/>
> > > >
>
> > > >
> > > > > > >android:layout_height="wrap_content"
> > > >android:text="@string/transaction_number"/>
> > > > > > >android:layout_width="wrap_content"
> > > >android:layout_height="wrap_content"/>
> > > >
>
> > > >
> > > > > > >android:layout_height="wrap_content"
> > > >android:text="@string/transaction_amount"/>
> > > > > > >android:layout_width="wrap_content"
> > > >android:layout_height="wrap_content"/>
> > > >
>
> > > >
> > > > > > >android:layout_height="wrap_content"
> > > >android:text="@string/transaction_from"/>
> > > > > > >android:layout_width="wrap_content"
> > > >android:layout_height="fill_parent"/>
> > > >
>
> > > >
> > > > > > >android:layout_height="wrap_content"
> > > >android:text="@string/transaction_to"/>
> > > > > > >android:layout_width="wrap_content"
> > > >android:layout_height="fill_parent"/>
> > > >
>
> > > >
> > > > > > >android:layout_height="wrap_content

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-26 Thread kaiping

Thanks for the idea.  I have confirmed that the file is named
transaction_edit.xml.

On Mar 26, 3:54 am, "Dan U." <[EMAIL PROTECTED]> wrote:
> Well, he needs to have the filename be transaction_edit.xml. Not sure
> if it is.
>
> On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
>
> > Don't you need to name your layout "transaction_edit" in the XML file?
>
> > On Mar 25, 2008, at 5:26 AM,kaipingwrote:
>
> > > Hi, For one of my Activities All the findViewById() function returns
> > > is null.  I am really astonished by this behaviour because this same
> > > function works fine in other parts of my application.  I have posted
> > > the code below.  If anybody has any ideas that would be great thanks,
>
> > > Josh
>
> > > package com.jingsys.money;
>
> > > import java.util.ArrayList;
>
> > > import android.app.Activity;
> > > import android.database.Cursor;
> > > import android.os.Bundle;
> > > import android.widget.ArrayAdapter;
> > > import android.widget.DatePicker;
> > > import android.widget.EditText;
> > > import android.widget.Spinner;
>
> > > import com.jingsys.money.data.AccountsDbAdapter;
> > > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > > import com.jingsys.money.data.TransactionDbAdapter;
>
> > > public class EditTransaction extends Activity {
>
> > >private  DatePicker mDate;
> > >private  EditText mDescription;
> > >private  EditText mNumber;
> > >private  EditText mAmount;
> > >private  Spinner mFromAccount;
> > >private  Spinner mToAccount;
> > >private  EditText mComments;
>
> > >private TransactionDbAdapter transData;
> > >private AccountsDbAdapter accountData;
>
> > >private Cursor mFrom;
> > >private Cursor mTo;
>
> > >@Override
> > >protected void onCreate(Bundle icicle) {
> > >super.onCreate(icicle);
> > >setContentView(R.layout.transaction_edit);
>
> > >mDate = (DatePicker) findViewById(R.id.trans_date);
> > >mDescription = (EditText) findViewById(R.id.account_name);
> > >mNumber = (EditText) findViewById(R.id.trans_number);
> > >mAmount = (EditText) findViewById(R.id.trans_amount);
> > >mComments = (EditText) findViewById(R.id.trans_comments);
>
> > >mFromAccount = (Spinner) findViewById(R.id.trans_from);
> > >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > > XML file
> > > 
> > > http://schemas.android.com/apk/res/
> > > android"
> > >android:layout_width="fill_parent"
> > >android:layout_height="fill_parent"
> > >android:stretchColumns="1">
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_date" />
> > > > >  android:layout_width="wrap_content"
> > >android:layout_height="wrap_content" />
> > >
>
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_description" />
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="wrap_content"/>
> > >
>
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_number"/>
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="wrap_content"/>
> > >
>
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_amount"/>
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="wrap_content"/>
> > >
>
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_from"/>
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="fill_parent"/>
> > >
>
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_to"/>
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="fill_parent"/>
> > >
>
> > >
> > > > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_comments"/>
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="fill_parent"/>
> > >
>
> > >
> > > > >android:layout_width="wrap_content"
> > >android:layout_height="wrap_content"
> > >android:text="@string/transaction_add"/>
> > >  

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-25 Thread Dan U.

Well, he needs to have the filename be transaction_edit.xml. Not sure
if it is.

On Mar 25, 5:29 am, Rick Genter <[EMAIL PROTECTED]> wrote:
> Don't you need to name your layout "transaction_edit" in the XML file?
>
> On Mar 25, 2008, at 5:26 AM, kaiping wrote:
>
>
>
>
>
> > Hi, For one of my Activities All the findViewById() function returns
> > is null.  I am really astonished by this behaviour because this same
> > function works fine in other parts of my application.  I have posted
> > the code below.  If anybody has any ideas that would be great thanks,
>
> > Josh
>
> > package com.jingsys.money;
>
> > import java.util.ArrayList;
>
> > import android.app.Activity;
> > import android.database.Cursor;
> > import android.os.Bundle;
> > import android.widget.ArrayAdapter;
> > import android.widget.DatePicker;
> > import android.widget.EditText;
> > import android.widget.Spinner;
>
> > import com.jingsys.money.data.AccountsDbAdapter;
> > import com.jingsys.money.data.MoneyDbAdapterFactory;
> > import com.jingsys.money.data.TransactionDbAdapter;
>
> > public class EditTransaction extends Activity {
>
> >private  DatePicker mDate;
> >private  EditText mDescription;
> >private  EditText mNumber;
> >private  EditText mAmount;
> >private  Spinner mFromAccount;
> >private  Spinner mToAccount;
> >private  EditText mComments;
>
> >private TransactionDbAdapter transData;
> >private AccountsDbAdapter accountData;
>
> >private Cursor mFrom;
> >private Cursor mTo;
>
> >@Override
> >protected void onCreate(Bundle icicle) {
> >super.onCreate(icicle);
> >setContentView(R.layout.transaction_edit);
>
> >mDate = (DatePicker) findViewById(R.id.trans_date);
> >mDescription = (EditText) findViewById(R.id.account_name);
> >mNumber = (EditText) findViewById(R.id.trans_number);
> >mAmount = (EditText) findViewById(R.id.trans_amount);
> >mComments = (EditText) findViewById(R.id.trans_comments);
>
> >mFromAccount = (Spinner) findViewById(R.id.trans_from);
> >mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> > XML file
> > 
> > http://schemas.android.com/apk/res/
> > android"
> >android:layout_width="fill_parent"
> >android:layout_height="fill_parent"
> >android:stretchColumns="1">
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_date" />
> > >  android:layout_width="wrap_content"
> >android:layout_height="wrap_content" />
> >
>
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_description" />
> > >android:layout_width="wrap_content"
> >android:layout_height="wrap_content"/>
> >
>
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_number"/>
> > >android:layout_width="wrap_content"
> >android:layout_height="wrap_content"/>
> >
>
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_amount"/>
> > >android:layout_width="wrap_content"
> >android:layout_height="wrap_content"/>
> >
>
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_from"/>
> > >android:layout_width="wrap_content"
> >android:layout_height="fill_parent"/>
> >
>
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_to"/>
> > >android:layout_width="wrap_content"
> >android:layout_height="fill_parent"/>
> >
>
> >
> > >android:layout_height="wrap_content"
> >android:text="@string/transaction_comments"/>
> > >android:layout_width="wrap_content"
> >android:layout_height="fill_parent"/>
> >
>
> >
> > >android:layout_width="wrap_content"
> >android:layout_height="wrap_content"
> >android:text="@string/transaction_add"/>
> > >android:layout_width="wrap_content"
> >android:layout_height="wrap_content"
> >android:text="@string/transaction_clear"/>
> >
>
> > 
>
> > Exception:
> > E/AndroidRuntime(  805): Uncaught handler: thread Main exiting due to
> > uncaught exception
> > E/AndroidRuntime(  805): java.lang.Runt

[android-developers] Re: Null pointer exception when finding views by Id

2008-03-25 Thread Rick Genter

Don't you need to name your layout "transaction_edit" in the XML file?

On Mar 25, 2008, at 5:26 AM, kaiping wrote:
>
> Hi, For one of my Activities All the findViewById() function returns
> is null.  I am really astonished by this behaviour because this same
> function works fine in other parts of my application.  I have posted
> the code below.  If anybody has any ideas that would be great thanks,
>
> Josh
>
> package com.jingsys.money;
>
> import java.util.ArrayList;
>
> import android.app.Activity;
> import android.database.Cursor;
> import android.os.Bundle;
> import android.widget.ArrayAdapter;
> import android.widget.DatePicker;
> import android.widget.EditText;
> import android.widget.Spinner;
>
> import com.jingsys.money.data.AccountsDbAdapter;
> import com.jingsys.money.data.MoneyDbAdapterFactory;
> import com.jingsys.money.data.TransactionDbAdapter;
>
> public class EditTransaction extends Activity {
>
>   private  DatePicker mDate;
>   private  EditText mDescription;
>   private  EditText mNumber;
>   private  EditText mAmount;
>   private  Spinner mFromAccount;
>   private  Spinner mToAccount;
>   private  EditText mComments;
>
>   private TransactionDbAdapter transData;
>   private AccountsDbAdapter accountData;
>
>   private Cursor mFrom;
>   private Cursor mTo;
>
>   @Override
>   protected void onCreate(Bundle icicle) {
>   super.onCreate(icicle);
>   setContentView(R.layout.transaction_edit);
>
>   mDate = (DatePicker) findViewById(R.id.trans_date);
>   mDescription = (EditText) findViewById(R.id.account_name);
>   mNumber = (EditText) findViewById(R.id.trans_number);
>   mAmount = (EditText) findViewById(R.id.trans_amount);
>   mComments = (EditText) findViewById(R.id.trans_comments);
>
>   mFromAccount = (Spinner) findViewById(R.id.trans_from);
>   mToAccount = (Spinner) findViewById(R.id.trans_to);
>
> XML file
> 
> http://schemas.android.com/apk/res/
> android"
>   android:layout_width="fill_parent"
>   android:layout_height="fill_parent"
>   android:stretchColumns="1">
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_date" />
>android:layout_width="wrap_content"
>   android:layout_height="wrap_content" />
>   
>
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_description" />
>  android:layout_width="wrap_content"
>   android:layout_height="wrap_content"/>
>   
>
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_number"/>
>  android:layout_width="wrap_content"
>   android:layout_height="wrap_content"/>
>   
>
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_amount"/>
>  android:layout_width="wrap_content"
>   android:layout_height="wrap_content"/>
>   
>
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_from"/>
>  android:layout_width="wrap_content"
>   android:layout_height="fill_parent"/>
>   
>
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_to"/>
>  android:layout_width="wrap_content"
>   android:layout_height="fill_parent"/>
>   
>
>   
>  android:layout_height="wrap_content"
>   android:text="@string/transaction_comments"/>
>  android:layout_width="wrap_content"
>   android:layout_height="fill_parent"/>
>   
>
>   
>  android:layout_width="wrap_content"
>   android:layout_height="wrap_content"
>   android:text="@string/transaction_add"/>
>  android:layout_width="wrap_content"
>   android:layout_height="wrap_content"
>   android:text="@string/transaction_clear"/>
>   
>
> 
>
>
> Exception:
> E/AndroidRuntime(  805): Uncaught handler: thread Main exiting due to
> uncaught exception
> E/AndroidRuntime(  805): java.lang.RuntimeException: Unable to start
> activity ComponentInfo{com.jingsys.money/
> com.jingsys.money.EditTransaction}: ja