Jim
Jim

Reputation: 381

Android App Crashes when I try to load it in the Emulator

I'm very new to Android programming and am having a rough start. I've created a general UI for a program and haven't changed any of the actual Java code. Whenever I try to load the app in the emulator just to see what it looks like, the app crashes. Does anyone have an idea as to why this would happen?

Also, other apps that I made from tutorials work perfectly fine, just the one that I recently created a layout for doesn't work.

Here is the Java code

package com.nubs.tableposv0_1;

import android.app.Activity;
import android.os.Bundle;

public class TablePOSv0_1Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Here is the updated XML code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:weightSum="5"
    >
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        >
        <Button android:id="@+id/item1"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 1"
            />
        <Button android:id="@+id/item2"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 2"
            />
        <Button android:id="@+id/item3"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 3"
            />
        <Button android:id="@+id/item4"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 4"
            />
        <Button android:id="@+id/item5"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 5"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        >
        <Button android:id="@+id/item6"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 6"
            />
        <Button android:id="@+id/item7"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 7"
            />
        <Button android:id="@+id/item8"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 8"
            />
        <Button android:id="@+id/item9"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 9"
            />
        <Button android:id="@+id/item10"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Item 10"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_weight="3"
        android:orientation="vertical"
        android:weightSum="9"
        >
        <TableLayout
            android:id="@+id/items_table"
            android:layout_width="fill_parent"
            android:layout_weight="4"
            >
            </TableLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="3"
            >
            <Button android:id="@+id/calc1"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="1"
                />
            <Button android:id="@+id/calc2"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="2"
                />
            <Button android:id="@+id/calc3"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="3"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="3"
            >
            <Button android:id="@+id/calc4"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="4"
                />
            <Button android:id="@+id/calc5"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="5"
                />
            <Button android:id="@+id/calc6"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="6"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="3"
            >
            <Button android:id="@+id/calc7"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="7"
                />
            <Button android:id="@+id/calc8"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="8"
                />
            <Button android:id="@+id/calc9"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="9"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="3"
            >
            <Button android:id="@+id/calc0"
                android:layout_weight="2"
                android:layout_height="fill_parent"
                android:text="0"
                />
            <Button android:id="@+id/calcdec"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="."
                />
        </LinearLayout>
        <Button android:id="@+id/total"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:text="Total"
            />
    </LinearLayout>
</LinearLayout>

Logcat:

07-22 01:24:41.793: ERROR/AndroidRuntime(392):     at android.app.Activity.setContentView(Activity.java:1647)
07-22 01:24:41.793: ERROR/AndroidRuntime(392):     at com.nubs.tableposv0_1.TablePOSv0_1Activity.onCreate(TablePOSv0_1Activity.java:15)
07-22 01:24:41.793: ERROR/AndroidRuntime(392):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-22 01:24:41.793: ERROR/AndroidRuntime(392):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-22 01:24:41.793: ERROR/AndroidRuntime(392):     ... 11 more
07-22 01:25:41.482: ERROR/DefContainer(224): Couldn't copy file: /data/local/tmp/TablePOSv0_1.apk

Upvotes: 0

Views: 231

Answers (1)

davidcesarino
davidcesarino

Reputation: 16209

If I recall correctly, LinearLayouts require both android:layout_width and android:layout_height dimensions.

In your XML, there are several without android:layout_width.

Also, next time post your Logcat output. They are much more useful than the code itself in those cases. That's why I'm only guessing here a problem that happened to me once.

// edit:

If it's still crashing, try to include both dimensions in all widgets. I don't remember exactly if it's just layouts of all widgets that require both dimensions. And puh-lease, give us the logcat. :-)

Upvotes: 1

Related Questions