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 8585995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:12:09+00:00 2026-06-11T22:12:09+00:00

I have a table layout inside a scroll view , I want to fill

  • 0

I have a table layout inside a scroll view , I want to fill them dynamically with 5 N Table Rows. Each Table Row contains an ImageView and an EditText. The app crashed
Here is the complete stack:

    09-25 10:03:07.496: E/AndroidRuntime(1695): FATAL EXCEPTION: main
09-25 10:03:07.496: E/AndroidRuntime(1695): java.lang.ClassCastException: android.widget.TableLayout$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.TableRow.mapIndexAndColumns(TableRow.java:164)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.TableRow.getVirtualChildCount(TableRow.java:149)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.TableRow.getColumnsWidths(TableRow.java:289)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.TableLayout.findLargestCells(TableLayout.java:504)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.TableLayout.measureVertical(TableLayout.java:469)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.TableLayout.onMeasure(TableLayout.java:435)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.View.measure(View.java:15172)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1196)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.ScrollView.onMeasure(ScrollView.java:318)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.View.measure(View.java:15172)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.View.measure(View.java:15172)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.View.measure(View.java:15172)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.View.measure(View.java:15172)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.View.measure(View.java:15172)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.Choreographer.doFrame(Choreographer.java:525)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.os.Handler.handleCallback(Handler.java:615)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.os.Looper.loop(Looper.java:137)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at android.app.ActivityThread.main(ActivityThread.java:4745)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at java.lang.reflect.Method.invokeNative(Native Method)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at java.lang.reflect.Method.invoke(Method.java:511)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-25 10:03:07.496: E/AndroidRuntime(1695):     at dalvik.system.NativeStart.main(Native Method)

CODE:

private TableLayout Table;//in XML

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

                //here I define the TR params   
        Table=(TableLayout)findViewById(R.id.Table);
        TableLayout.LayoutParams tableRowParams=new TableLayout.LayoutParams 
(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT,1.0f);
            //fill the table with Table rows dynamicly
    for(int i=0;i<N;i++){


        TableRow TR= new TableRow(this);
        TR.setLayoutParams(tableRowParams);
        Table.addView(TR);
        //Table Row contains EditText and ImageView
                    EditText editText1 =new EditText(this);
        ImageView imgview=new ImageView(this);
        TR.addView(editText1);
        TR.addView(imgview);

        editText1.setText("foo");
        editText1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,1.0f));

        int id = getResources().getIdentifier("com.example.university2:drawable/news1", null, null);


        imgview.setImageResource(id);
        imgview.setAdjustViewBounds(true);
        imgview.setMaxHeight(50);
        imgview.setMaxWidth(50);

        imgview.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,1.0f));


    }

}

Here is the XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

    <TableLayout
        android:id="@+id/Table"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </TableLayout>

</ScrollView>

I would appreciate your help.
Thank you.

  • 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-11T22:12:10+00:00Added an answer on June 11, 2026 at 10:12 pm

    Looks that issue is caused by TR.setLayoutParams(tableRowParams);
    (java.lang.ClassCastException: android.widget.TableLayout$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams)
    becouse tableRowParams (declaration: TableLayout.LayoutParams tableRowParams) is not TableRow.LayoutParams

    Try to replace

    TableLayout.LayoutParams tableRowParams=new TableLayout.LayoutParams (TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT,1.0f);
    

    with (updated)

    TableRow.LayoutParams tableRowParams=new TableRow.LayoutParams (TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT,1.0f);
    

    and edit

    TR.addView(editText1, new TableRow.LayoutParams (TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT,1.0f));
    TR.addView(imgview, new TableRow.LayoutParams (TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT,1.0f));
    

    remove

    imgview.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,1.0f));
    

    and

    editText1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,1.0f));
    

    Issue was caused by incorrect creation of LayoutParams for particular control added to particular owner, e.g.: if You are adding control to LinearLayout – You should use LinearLayout.LayoutParams for that control, TableLayout.LayoutParams – in case You are adding control to TableLayout, … etc…

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

Sidebar

Related Questions

I have a flow layout. Inside it I have about 900 tables. Each table
I have different table rows, each of it contains some information text which should
I am using Table layout. I have two(columns) text-views in table row. I want
So I have a table layout that Im adding rows to through code since
I have created a table layout in which my table row height is too
I want to have a dynamic table, with rows added over time as a
I have HTML Like Below. I have a table inside another table.Each TD in
I have an application with a view-based NSTableView in it. Inside this table view,
The part I want to tab is inside a nested table layout. It starts
I have a table layout that I want to populate with the result from

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.