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 > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > > > > > <TableLayout xmlns:android="http://schemas.android.com/apk/res/ > > > > > > android" > > > > > > android:layout_width="fill_parent" > > > > > > android:layout_height="fill_parent" > > > > > > android:stretchColumns="1"> > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_date" /> > > > > > > <DatePicker android:id="@+id/trans_date" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" /> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_description" /> > > > > > > <EditText android:id="@+id/trans_descr" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content"/> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_number"/> > > > > > > <EditText android:id="@+id/trans_number" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content"/> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_amount"/> > > > > > > <EditText android:id="@+id/trans_amount" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content"/> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_from"/> > > > > > > <Spinner android:id="@+id/trans_from" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="fill_parent"/> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_to"/> > > > > > > <Spinner android:id="@+id/trans_to" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="fill_parent"/> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <TextView android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_comments"/> > > > > > > <EditText android:id="@+id/trans_comments" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="fill_parent"/> > > > > > > </TableRow> > > > > > > > <TableRow> > > > > > > <Button android:id="@+id/transaction_add_button" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_add"/> > > > > > > <Button android:id="@+id/transaction_clear_button" > > > > > > android:layout_width="wrap_content" > > > > > > android:layout_height="wrap_content" > > > > > > android:text="@string/transaction_clear"/> > > > > > > </TableRow> > > > > > > > </TableLayout> > > > > > > > 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}: java.lang.NullPointerException > > > > > > E/AndroidRuntime( 805): at > > > > > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > > > > > 1758) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > > > > > > 1770) > > > > > > E/AndroidRuntime( 805): at android.app.ActivityThread.access > > > > > > $1500(ActivityThread.java:99) > > > > > > E/AndroidRuntime( 805): at android.app.ActivityThread > > > > > > $H.handleMessage(ActivityThread.java:1271) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.os.Handler.dispatchMessage(Handler.java:80) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.os.Looper.loop(Looper.java: > > > > > > 91) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.app.ActivityThread.main(ActivityThread.java:3052) > > > > > > E/AndroidRuntime( 805): at > > > > > > java.lang.reflect.Method.invokeNative(Native Method) > > > > > > E/AndroidRuntime( 805): at > > > > > > java.lang.reflect.Method.invoke(Method.java:356) > > > > > > E/AndroidRuntime( 805): at android.os.ZygoteInit > > > > > > $MethodAndArgsCaller.run(ZygoteInit.java:1547) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.os.ZygoteInit.main(ZygoteInit.java:1445) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.dalvik.NativeStart.main(Native Method) > > > > > > E/AndroidRuntime( 805): Caused by: java.lang.NullPointerException > > > > > > E/AndroidRuntime( 805): at > > > > > > com.jingsys.money.EditTransaction.onCreate(EditTransaction.java:47) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > > > > > > 847) > > > > > > E/AndroidRuntime( 805): at > > > > > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > > > > > 1728) > > > > > > E/AndroidRuntime( 805): ... 11 more > > > > > > > Thanks again for you help. > > > > > > -- > > > > > Rick Genter > > > > > [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new M5 SDK! http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---