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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:07:38+00:00 2026-06-13T13:07:38+00:00

Ive made a program which has a view in the top op the window

  • 0

Ive made a program which has a view in the top op the window (right under the title bar).
According to what is goin on in the program, the color of the view will change.

This works just fine.

Now my problem is: I want 2 textviews inside it, next to each other. So probably: View, Tablelayout, tablerow, textview, textview, tablerow end, tablelayout end, view end.

But this does not seem to work. It gave me the error “Java.lang.RuntimeException: Unable to start activity ComponentInfo” and “View can not be cast to viewgroup”.

Nowhere in the java code do i touch any of the new views in the xml code, the only java that touches that XML, is TopView = (View)findViewById(R.id.TopView); and TopView.setBackgroundColor(Color.GREEN ); Topview is the outer view, and works perfectly without anything inside it.

This is the XML code

    ...
<View
        android:id="@+id/TopView"
        android:layout_width="fill_parent"
        android:layout_height="20dp" 
        android:background="#8E8E8E" >



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

                <TableRow
                    android:id="@+id/TableRow000"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:gravity="left"
                    android:orientation="vertical" >


            <TextView
                        android:id="@+id/lbl1"
                        android:layout_width="120dp"
                        android:layout_height="wrap_content"
                        android:text="Vare :"
                        android:textSize="22dp" />

                    <TextView
                        android:id="@+id/lbl2"
                        android:layout_width="180dp"
                        android:layout_height="wrap_content"
                        android:text="du grim" />

            </TableRow>
            </TableLayout>


    </View>
...
  • 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-13T13:07:38+00:00Added an answer on June 13, 2026 at 1:07 pm

    You can not have child-views inside a View.

    A View is always the leaf node in a layout hierarchy.

    1.Re-write the 1st line of your xml-layout as:

    <LinearLayout
        android:id="@+id/TopView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:background="#8E8E8E">
    

    2.Change corresponding Java code as below:

    TopView = (LinearLayout)findViewById(R.id.TopView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a small program which has 2 buttons and each does certain thing.
I've got a program made basically from a ListCtrl and has an add button,
Updated below: I have a script which has a function I made that calculates
I've made a program that uses two shared libraries (which I compiled) and are
I've made a couple of programs which I release as freeware on my webpage.
I've made a program to manage a movie collection and it stores the data
I've made a small program in C++ and Qt. The program displays a list
I'm a beginner in programming. I've just made a program called Guessing Game. And
For an assignment I've made a simple C++ program that uses a superclass (Student)
I'm almost done with my program, but I've made a subtle mistake. My program

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.