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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:51:15+00:00 2026-05-17T16:51:15+00:00

I’m trying to populate a list of files, and I’m using a custom ArrayAdapter

  • 0

I’m trying to populate a list of files, and I’m using a custom ArrayAdapter so that each list item contains multiple Views. The code I use to populate the list is:

File home = MEDIA;
    int numFiles = home.listFiles().length;
    if(numFiles >0) {
        ArrayList<FileInfo> fileData = new ArrayList<FileInfo>(numFiles);

        for (File file : home.listFiles()) {
            FileInfo data = new FileInfo();
            data.title = file.getName();
            data.desc = file.getAbsolutePath();

            fileData.add(data);
        }

        FileAdapter fileAdapter = new FileAdapter(this, R.layout.file_item, fileData);
        setListAdapter(fileAdapter);

    }

The main XML file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"/>

    <TextView android:id="@+id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="No files found on SD Card."/>
</LinearLayout>

And the file_item XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android/com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView android:id="@+id/file_item_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView android:id="@+id/file_item_desc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

Any time I run this and it tries to populate the list, it throws an exception and crashes the application, throwing the error

E/AndroidRuntime( 5320): FATAL EXCEPTION: main
E/AndroidRuntime( 5320): java.lang.RuntimeException: Binary XML file line #6: You must supply a layout_width attribute.
E/AndroidRuntime( 5320):    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
E/AndroidRuntime( 5320):    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3600)
E/AndroidRuntime( 5320):    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3680)

If I add in an additional LinearLayout or something to the file_item XML file, the line that is missing the layout_width will change, which makes me think that it does believe that that first TextView in the file_item XML file is missing a layout_width attribute, but since there’s one there already, I have no idea what it wants me to do.

  • 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-17T16:51:16+00:00Added an answer on May 17, 2026 at 4:51 pm

    I found the issue – this happens if you have a typo in the xmlns declaration.

    I had:

    xmlns:android="http://schemas.android/com/apk/res/android"
    

    What I should have had was:

    xmlns:android="http://schemas.android.com/apk/res/android"
    

    For whatever reason this shows up in the stack trace as a missing layout_width.

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

Sidebar

Related Questions

No related questions found

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.