Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Project - R cannot be resolved or is not a field
    text
    copied!<p>I've been working on an android project, but a really annoying error is killing me: "R cannot be resolved or is not a field". Well, there's many questions who got answers, but everything I tried for now doesn't work: clean project, destroy R.java &amp; clean project, import x.y.z.R; and destroy any import android.R;... but it's still there. Will you be able to help me?</p> <p>Here comes the code where the error occurs (ListArretsActivity.java):</p> <pre><code>package com.example.onetantan; import java.util.ArrayList; import com.example.onetantan.rest.Arret; import com.example.onetantan.rest.ArretRestMethod; import com.example.onetantan.rest.ListArret; import com.example.onetantan.R; import android.app.ListActivity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Menu; public class ListArretsActivity extends ListActivity { ... // Code that doesn't seemed revelant, for me, for the error given class MyAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; { @Override protected Void doInBackground(Void... paramArrayOfParams) { ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this.R); return null; } } ... // Code that doesn't seemed revelant, for me, for the error given } </code></pre> <p>Here comes a code where there's no problem... (ArretAdapter.java):</p> <pre><code>package com.example.onetantan; import java.util.List; import com.example.onetantan.rest.Arret; import com.example.onetantan.R; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class ArretAdapter extends BaseAdapter { private static String LOG_TAG="ArretAdapter"; private Context mContext; private List&lt;Arret&gt; mListArret; private LayoutInflater inflater; public ArretAdapter(Context p_oContext, List&lt;Arret&gt; p_oListArret){ super(); mContext = p_oContext; mListArret = p_oListArret; this.inflater = LayoutInflater.from(mContext); } ... // Code that doesn't seemed revelant, for me, for the error given @Override public View getView(int p_iPosition, View p_oConvertView, ViewGroup p_oParentView) { if (p_oConvertView == null) { p_oConvertView = inflater.inflate(R.layout.arret_item, null); } ((TextView)(p_oConvertView.findViewById(R.id.name))).setText("Heure"); ((TextView)(p_oConvertView.findViewById(R.id.dist))).setText("Heure"); return p_oConvertView; } ... // Code that doesn't seemed revelant, for me, for the error given } </code></pre> <p>And for finishing, a picture of my package explorer for src &amp; gen folders. Wanted to post an image, but doesn't have enough reputation since I'm a new user, so here goes a link : <a href="http://img217.imageshack.us/img217/5511/tosend.png" rel="nofollow">http://img217.imageshack.us/img217/5511/tosend.png</a></p> <p>It's been a week since I haven't been able to do a thing... maybe is something too obvious that I don't see, or a serious problem, but I really need your help.</p> <p>Thanks in advance for any answers you can give me (even if it's answers from other problems that I've tried three times, I'll try again if needed).</p> <p>EDIT: One of your answers was to check my xml files for any error. But Eclipse doesn't send back any error and I don't see any (I'm not experimented at all... :/ ). In my res>layout folder: arret_item.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /&gt; &lt;TextView android:id="@+id/dist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>In my res>layout folder: arret_item.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" tools:context=".ListArretsActivity" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>These are the only two .xml files in my res.layout that I may be edited.</p> <p>EDIT 2: Running Android Lint, it only returns me warnings:</p> <p>Not targeting the latest versions of Android; comptability modes apply. .gif format for bitmaps is discouraged (64 items) Found bitmap drawable res/drawable/l_1.gif in densityless folder (68 items) The ressource R.drawable.l_1 appears to be unused (70 items)</p> <p>I corrected right away the first one since I'm working on API 17 (Android 4.2), and my manifest was on 16. But it doesn't correct my error.</p> <p>For the 3 other warnings, it's normal since I don't use them for the moment an I was given the project with these.</p> <p>Well, here comes my AndroidManifest.xml since I edited it:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.onetantan" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.onetantan.ListArretsActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Answer: Sorry everyone, there's a code I haven't given and it's ArretRestMethod.java. If I've given you this one, you'll maybe understand:</p> <pre><code>package com.example.onetantan.rest; import ... public class ArretRestMethod { private static String LOG_TAG="ArretRestMethod"; Context mContext=null; public ArretRestMethod(Context context) { mContext = context.getApplicationContext(); } ... } </code></pre> <p>One of my friends pointed me out for the line in ListArretsActivity.java</p> <pre><code>ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this.R); </code></pre> <p>must be written like this:</p> <pre><code>ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this); </code></pre> <p>Free whips will be given to anyone who want to give me a punishment... :x (I'm ashamed that I didn't saw this... sorry everyone. But I have learned at least some things by asking there.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload