using findViewById() 81 times seems more demanding than creating them
at runtime to me.

There is always an Exception thrown if your app is crashing, look at
the logcat in the 'DDMS' view in Eclipse.
If you only see a runtime exception then you need to get the cause
from the exception. Surround the call with a try-catch and use
something like this:

catch (Exception e)
{
   final static String TAG = "you app name";
   StackTraceElement[] arr = e.getStackTrace();

   for (int i=0; i<arr.length; i++)
   {
       Log.e(TAG,arr[i].toString());
   }
    Throwable cause = e.getCause();
             if(cause != null) {
                 Log.e(TAG,"Cause: "+e.toString());
                 arr = cause.getStackTrace();
                 for (int i=0; i<arr.length; i++)
                 {
                        Log.e(TAG,arr[i].toString());
                 }

             }
}


On Jan 9, 11:47 am, zosq <yellasrich...@gmail.com> wrote:
> I have tried doing the EditTexts programatically in a loop. No luck.
> Still gives me the same problem. I am having a hard time trying to
> figure out what the exact problem is. I am new to the eclipse IDE and
> the android programming.
>
> On Jan 9, 12:31 am, TreKing <treking...@gmail.com> wrote:
>
> > > 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 
> > deviceshttp://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);
>
> ...
>
> read more »
-- 
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