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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:49:45+00:00 2026-05-25T09:49:45+00:00

I tried the following code for table layout in android without using xml file.

  • 0

I tried the following code for table layout in android without using xml file. But i didn’t get my screen on android emulator but getting the errror as “the application has stopped upexpectedly.Please try again.”

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Tablelayout extends Activity{
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    LayoutParams params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

    TextView tv=new TextView(this);
    tv.setLayoutParams(params);
    tv.setTextColor(Color.RED);

    TableRow tr=new TableRow(this);
    tr.addView(tv);

    TableLayout tl=new TableLayout(this);
    TableLayout.LayoutParams layoutparams=new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    tl.addView(tr);

    this.addContentView(tl, layoutparams);
}

}

  • 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-05-25T09:49:46+00:00Added an answer on May 25, 2026 at 9:49 am

    I’m not getting a force close when I run this code, but you are missing something.

    I tried adding the following, but did not see any text:

    tv.setText("Hello world!");
    

    The problem is that when you call to tr.addView, you aren’t setting any layout parameters on the new row. If you change the line to the following, the text appears:

    tr.addView(tv, new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    

    Edit: Here’s a thought on the force close, is Tablelayout correctly defined in your AndroidManifest.xml? You should have something like this.

    <application android:label="@string/app_name">
        <activity android:name=".Tablelayout" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the following code to get an alert upon closing a browser window:
I tried the following code. Although I don't get any errors, it did not
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
How can I iterate ResultSet ? I've tried with the following code, but i
I tried to modify a type using the following code and it gave me
I tried to control email address and reviewer's name with the following code but
I am using following zend code to select all data from a table where
I have been using the following code to query one table: public Cursor fetchFilteredItemsNearSortedByDistance(String
I want to produce an Android screen layout that looks something like the following:
I have a simple table layout in the .xml file. I am adding components

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.