ayesha
ayesha

Reputation: 27

Android Table Layout error

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/">
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:id="@+id/">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Execution Time"
            android:id="@+id/textView"
            android:layout_column="1" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:layout_column="7"
            android:text="118161.4 ms" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Memory"
            android:id="@+id/textView2"
            android:layout_column="1" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText2"
            android:layout_column="7" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="CPU"
            android:id="@+id/textView3"
            android:layout_column="1" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText3"
            android:layout_column="7" />
    </TableRow>
</TableLayout>
</RelativeLayout>

I have used TableLayout.But when I try to run the code I get this error

Error:(8, 18) Resource id cannot be an empty string (at 'id' with value '@+id/').

As I am new to android .Kindly help me in this regard.

Upvotes: 0

Views: 210

Answers (2)

MH.
MH.

Reputation: 45503

Both your RelativeLayout and TableLayout have the following attribute:

android:id="@+id/"

This is incomplete. From the Android documentation:

For the ID value, you should usually use this syntax form: "@+id/name". The plus symbol, +, indicates that this is a new resource ID and the aapt tool will create a new resource integer in the R.java class, if it doesn't already exist.

In other words, change every occurrence above to something in the form of "@+id/name". For example:

<RelativeLayout ... android:id="@+id/root">

And:

<TableLayout ... android:id="@+id/table">

Or, if you don't need to refer to the individual items, just remove the id attribute all together.

Upvotes: 2

Rajen Raiyarela
Rajen Raiyarela

Reputation: 5634

Error is you are specifying android:id but not giving valid id

android:id="@+id/"

so if you want to give id you have give id as

android:id="@+id/<control_id>" 

<control_id> is some valid string using which you will refer control in java code as well as inside layout.

so if you do not want to give any id then simply remove android:id="@+id/" attribute of widget from layout.xml.

Upvotes: 0

Related Questions