Trouble with ID in AIDE

2.1k Views Asked by At

I'm writing a simple Android App using AIDE (Android IDE). I gave one of my layout elements an ID, but when I try to access the element using findViewById(), I get an error tht says: "Unknown member 'id' of 'com.mycompany.mailscomunes.R'. I haven't seen this error outside of AIDE.

This is the Java code:

package com.mycompany.mailscomunes;

import android.app.*;
import android.os.*;
import android.content.Intent;
import android.provider.ContactsContract;

public class MainActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findViewById(R.id.one);

    }
}

And this is the relevant XML:

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/one"/>
3

There are 3 best solutions below

1
On

Remove these lines:

import android.app.*;
import android.os.*;

You're literally importing the entire Android framework, which includes layout files, which has ID's in them.
And you're not including your own ID file (called "R.java").

So remove those two lines, and include this one:

import com.mycompany.mailscomunes.R;
0
On

The root of an activity xml should be of Layout type.

<?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="vertical">

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Text"/>

</LinearLayout>
0
On

Goto your project and delete the build folder and do a rebuild. I had the same problem and is fixed