私はAndroidプロジェクトに取り組んでいますが、本当に厄介なエラーが私を殺しています:「Rは解決できないか、フィールドではありません」。答えを得た質問はたくさんありますが、今のところ試したすべてが機能しません。プロジェクトをクリーンアップし、R.javaを破棄してプロジェクトをクリーンアップし、xyzRをインポートします。インポートした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
なにかできなくなってから一週間が経ちました…当たり前のことか、深刻な問題かもしれませんが、本当にあなたの助けが必要です。
よろしくお願いします(3回試した他の問題の答えでも、必要に応じてやり直します)。
編集:あなたの答えの1つは、私のxmlファイルにエラーがないかチェックすることでした。しかし、Eclipseはエラーを返送せず、何も表示されません(私はまったく実験されていません...:/)。私のres>layoutフォルダー: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>
私のres>layoutフォルダー: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内の2つの.xmlファイルのみです。
編集2:Android Lintを実行すると、警告のみが返されます:
Androidの最新バージョンを対象としていません。互換性モードが適用されます。ビットマップの.gif形式は推奨されません(64アイテム)密度のないフォルダーでビットマップドローアブルres / drawable / l_1.gifが見つかりました(68アイテム)リソースR.drawable.l_1は未使用のようです(70アイテム)
API 17(Android 4.2)で作業していて、マニフェストが16であったため、最初の1つをすぐに修正しましたが、エラーは修正されません。
他の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();
}
...
}
友人の1人が、ListArretsActivity.javaの行について私に指摘しました。
ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this.R);
このように書く必要があります:
ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this);
私に罰を与えたい人には無料の鞭が与えられます...:x(私はこれを見なかったことを恥ずかしく思います...みんなごめんなさい。しかし私はそこで尋ねることによって少なくともいくつかのことを学びました。)