Reputation: 19474
I'm a newbie with Android dev. I have a simple "learning" app with a very simple layout. The layout shows only one warning (hardcoded string ... should should use @string resource) which I doubt is related to the problem. Yet, in my activity code, I have the error "R cannot be resolved to a variable".
Here's the java:
package com.example.treefields;
import android.app.Activity;
import android.os.Bundle;
public class TreeFieldsActivity extends Activity
{
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContextView (R.layout.activity_tree_fields);
}
}
And, here's the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine"
android:text="multiline text" />
</LinearLayout>
Any ideas? Thanks.
Upvotes: 0
Views: 857
Reputation: 431
If you're using Eclipse, you can always use Ctrl+Shift+o to let the IDE figure out what to import, but like Bostwickenator said, you should make sure you include the R generated by your package, and not android.R on accident (as that would not resolve to any layout elements you created, but rather some Android common stuff).
Upvotes: 1
Reputation: 380
It doesn't look like you are even including R. You need to include the resources package as such:
import your.package.name.R;
The lint string warning is likely unrelated as you say.
Upvotes: 2