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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---