Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:42:16+00:00 2026-06-14T19:42:16+00:00

Possible Duplicate: Looping through editTexts to check values I have a layout with about

  • 0

Possible Duplicate:
Looping through editTexts to check values

I have a layout with about 100 editTexts (15 rows, 10 columns), all named based on their row / column IDs (e.g. box0101, box0102 etc.).

I have a method clearBoard() that is called when a ‘clear’ button is clicked (see code below). It is intended to loop through all of the boxes (box0101, box0102, box0103 etc.) and replace the contents with “” – making them blank.

The error that comes up in the LogCat says java.lang.NoSuchFieldException: box0101
at java.lang.Class.getDeclaredField(Class.java:631) – but there is definitely a box0101 defined in my xml and i reference it several other times during the code with no problem.

Any ideas?

From XML

           <EditText 
            android:gravity="center"
            android:layout_marginLeft="10dp"
            android:id="@+id/box0101"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/boxoutlineone" />    
        <EditText 
            android:gravity="center"
            android:id="@+id/box0201"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="#000000" />   
        <EditText
            android:gravity="center" 
            android:id="@+id/box0301"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="#000000" />   
        <EditText 
            android:gravity="center"
            android:id="@+id/box0401"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="#000000" />

In Activity:

final EditText box0101 = (EditText)findViewById(R.id.box0101);
    final EditText box0201 = (EditText)findViewById(R.id.box0201);
    final EditText box0301 = (EditText)findViewById(R.id.box0301);
    final EditText box0401 = (EditText)findViewById(R.id.box0401);
    final EditText box0501 = (EditText)findViewById(R.id.box0501);

etc…

    public void clearBoard() {
    final int ROW_COUNT = 14;
    final int COL_COUNT = 9;
    final String ROWS[] = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15"};
    final String COLS[] = {"01","02","03","04","05","06","07","08","09","10"};

    for(int i=0; i<ROW_COUNT; i++) {
        for(int j=0; j<COL_COUNT; j++) {
            String a = ROWS[i];
            String b = COLS[j];
            int editTextId=getResId("box"+a+b,this,id.class);
            EditText et=(EditText)findViewById(editTextId);    
            et.setText("");
        }
    }
}

public static int getResId(String variableName, Context context, Class<?> c) {

    try {
        Field idField = c.getDeclaredField(variableName);
            return idField.getInt(idField);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:42:17+00:00Added an answer on June 14, 2026 at 7:42 pm

    I don’t know why you decided to use the Field class to get the id instead of the more practical Resources.getIdetifier method:

    for(int i=0; i<ROW_COUNT; i++) {
        for(int j=0; j<COL_COUNT; j++) {
            String a = ROWS[i];
            String b = COLS[j];
            int editTextId = getResources().getIdentifier("box" + a + b , "id", getPackageName());
            EditText et=(EditText)findViewById(editTextId);    
            et.setText("");
        }
    }
    

    Or, based on those EditText being in a TableLayout, you could just pass a reference to the TableLayout into a method which will traverse it with the method getChildAt(position).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Looping through rows in a DataView I have created a dataview from
Possible Duplicate: How does foreach work when looping through function results? If I have
Possible Duplicate: Looping through Markers with Google Maps API v3 Problem I have a
Possible Duplicate: Looping through mysql_fetch_array in PHP I have a simple join query that
Possible Duplicate: looping through enum values Suppose we're dealing with a deck of cards
Possible Duplicate: iterate through pairs of items in python list I have a list
Possible Duplicate: UTF-8 all the way through Searching high & low for a solution.
Possible Duplicate: How to connect TFS through Internet I have a project I've been
Possible Duplicate: Get Information about a SHA-1 commit object? I needed to check when
Possible Duplicate: Looping through a directory on the web and displaying its contents (files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.