“Unable to start activity ComponentInfo” Switching Components

Every time I switch the order of the components in my xml layout I get an RuntimeException stating "Unable to start activity ComponentInfo." When I switch the order back in works fine again. After debugging, I found out that even though I not changing the code the findViewById method returns the wrong item.

    final Button button = (Button) findViewById(R.id.button);

It seems as if it is returning whatever the first item in the list is instead of the id that I'm using. Since this was the original order, the following works

        <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="Submit" />
    <EditText
    android:id="@+id/edittext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

But this will produce the RuntimeException

        <EditText
    android:id="@+id/edittext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
    <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="Submit" />

Any help would be appreciated. Thanks.

Answers


Need Your Help

Key for Google Maps API

android google-maps key

I am new to API managaments.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.