我一直在一個Android項目,但一個非常惱人的錯誤是殺了我:「R無法解決或不是一個領域」。那麼,有很多問題誰得到了答案,但我現在嘗試的一切都不起作用:乾淨的項目,銷燬R.java &乾淨的項目,導入x.y.z.R;並銷燬任何導入的android.R;但它仍然存在。你能幫助我嗎?Android項目 - R無法解析或不是字段
這裏來發生錯誤代碼(ListArretsActivity.java):
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<Void, Void, Void> {
@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
}
這裏說到那裏是沒有問題的代碼...(ArretAdapter.java):
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<Arret> mListArret;
private LayoutInflater inflater;
public ArretAdapter(Context p_oContext, List<Arret> 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
}
而且完成後,我的程序包資源管理器的圖片爲src & gen文件夾。想要發佈圖片,但沒有足夠的聲譽,因爲我是一個新用戶,所以這裏有一個鏈接:http://img217.imageshack.us/img217/5511/tosend.png
這已經過去了一個星期,因爲我沒有能夠做一件事情...也許是太明顯,我沒有看到,或者是一個嚴重的問題,但我真的需要你的幫助。
在此先感謝您提供給我的任何答案(即使它是我嘗試過三次的其他問題的答案,如果需要,我會再次嘗試)。
編輯:你的答案之一是檢查我的XML文件的任何錯誤。但是Eclipse不會發回任何錯誤,我也沒有看到任何錯誤(我根本沒有嘗試過......)。 在我的資源>佈局文件夾:arret_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
在我的資源>佈局文件夾:arret_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
</RelativeLayout>
這些人是我res.layout僅有的兩個.xml文件我可能會被編輯。
EDIT 2:運行Android的細絨,它只返回我警告:
不針對Android系統的最新版本;適用性模式適用。 .gif注意位圖格式不鼓勵(64項) 實測值位圖繪製RES /抽拉/ l_1.gif在densityless文件夾(68項) 的的ressource R.drawable.l_1似乎是未使用的(70項)
由於我正在使用API 17(Android 4.2),並且我的清單是16,所以我立即糾正了第一個錯誤。但它不能糾正我的錯誤。
對於另外3個警告,這是正常的,因爲我暫時不使用它們,因爲我給這個項目帶來了這個項目。
好,這纔是我的AndroidManifest.xml因爲我編輯它:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.onetantan"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.onetantan.ListArretsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答:對不起大家,還有我沒有給一個代碼,它是ArretRestMethod.java。如果我已經給你這個,你可能會明白:
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();
}
...
}
我的一個朋友指出我在ListArretsActivity中的一行。java的
ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this.R);
必須這樣寫:
ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this);
免費鞭子將分配給任何人誰願意給我的懲罰...:X(我很慚愧,我沒有看到這個......對不起大家,但是我通過詢問得知有至少一些事情。)
你不應該被導入進口com.example.onetantan.R; – Jameo
在arret_item.xml的頂部是否是<?xml version =「1.0」encoding =「utf-8」?>?這是必要的,如果t不是,可能會打破你的_R_引用。 – Kirk
嘗試將您的** API **更改爲另一個級別後,再轉回原始級別。並檢查** ErrorLog **或**問題**查看有一些錯誤。 –