>
> Now when I try to do a simple getText() method on textArray[][], it

gives me a runtime error but setText() method works fine on textArray[]

[]


What's the error? Are you checking for null?

Also, are you seriously defining 81 objects in your layout and then finding
each one by ID?
Why don't you generate your EditTexts programmatically in a double loop?

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking


On Fri, Jan 8, 2010 at 11:08 AM, zosq <yellasrich...@gmail.com> wrote:

> I am simple sudoku app. My main.xml has 81 EditText and 2 buttons as
> shown below.
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <RelativeLayout
>        xmlns:android="http://schemas.android.com/apk/res/android";
>        android:layout_width="fill_parent"
>        android:layout_height="wrap_content"
>        android:background="@color/activity_background">
>        <EditText
>                android:id="@+id/text1"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="2dip"
>                android:layout_marginLeft="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text2"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text1"
>                android:layout_alignTop="@id/text1"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text3"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="4dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text2"
>                android:layout_alignTop="@id/text1"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text4"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text3"
>                android:layout_alignTop="@id/text1"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text5"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text4"
>                android:layout_alignTop="@id/text1"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text6"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="4dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text5"
>                android:layout_alignTop="@id/text1"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text7"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text6"
>                android:layout_alignTop="@id/text1"
>                android:selectAllOnFocus="true" />
>
> ....
> ....
> ....
> ....
> ....
>
>
>        <EditText
>                android:id="@+id/text80"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:layout_marginRight="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text79"
>                android:layout_alignTop="@id/text73"
>                android:selectAllOnFocus="true" />
>        <EditText
>                android:id="@+id/text81"
>                android:layout_width="33dip"
>                android:layout_height="33dip"
>                android:background="@color/textBox_background"
>                android:layout_marginBottom="2dip"
>                android:maxLength="1"
>                android:textColor="@color/textBox_color"
>                android:numeric="integer"
>                android:paddingLeft="11dip"
>                android:layout_toRightOf="@id/text80"
>                android:layout_alignTop="@id/text73"
>                android:selectAllOnFocus="true" />
>        <Button
>                android:id="@+id/solveButton"
>                android:layout_width="wrap_content"
>                android:layout_height="wrap_content"
>                android:layout_below="@id/text73"
>                android:layout_alignParentRight="true"
>                android:layout_marginTop="10dip"
>                android:text="Solve" />
>        <Button
>                android:id="@+id/resetButton"
>                android:layout_width="wrap_content"
>                android:layout_height="wrap_content"
>                android:layout_toLeftOf="@id/solveButton"
>                android:layout_alignTop="@id/solveButton"
>                android:text="Reset" />
> </RelativeLayout>
>
> In my activity class, I have grouped all these 81 EditTexts into one 2-
> dimensional array as shown below.
>
> EditText[][] textArray = new EditText[9][9];
>
> textArray[0][0] = (EditText)findViewById(R.id.text1);
> textArray[0][1] = (EditText)findViewById(R.id.text2);
> textArray[0][2] = (EditText)findViewById(R.id.text3);
> textArray[0][3] = (EditText)findViewById(R.id.text4);
> textArray[0][4] = (EditText)findViewById(R.id.text5);
> textArray[0][5] = (EditText)findViewById(R.id.text6);
> textArray[0][6] = (EditText)findViewById(R.id.text7);
> textArray[0][7] = (EditText)findViewById(R.id.text8);
> textArray[0][8] = (EditText)findViewById(R.id.text9);
> textArray[1][0] = (EditText)findViewById(R.id.text10);
> textArray[1][1] = (EditText)findViewById(R.id.text11);
> textArray[1][2] = (EditText)findViewById(R.id.text12);
> textArray[1][3] = (EditText)findViewById(R.id.text13);
>
> ...
> ...
> ...
>
> textArray[8][8] = (EditText)findViewById(R.id.text81);
>
>
> Now when I try to do a simple getText() method on textArray[][], it
> gives me a runtime error but setText() method works fine on textArray[]
> []
>
> textArray[i][j].getText().toString()
>
>
> Please help me find out what I am doing wrong or what I need to
> change. Thank you in advance.
>
> --
> 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
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to