0

私は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(私はこれを見なかったことを恥ずかしく思います...みんなごめんなさい。しかし私はそこで尋ねることによって少なくともいくつかのことを学びました。)

4

8 に答える 8

1
  • 最近編集した xml ファイルにエラーがないか確認してください。Eclipse は xml ファイルのエラーを見逃すことがあるため、最近編集したファイルを開く必要がある場合があります。
  • res フォルダー内のリソースのファイル名に不正な文字が含まれていないかどうかを確認してください。
于 2012-12-10T14:21:55.770 に答える
1

プロジェクトをきれいにする必要があります....

in eclipse goto -->projects --> select clean --> select your project ( shows in popup )
于 2012-12-10T14:19:00.027 に答える
0

<?xml version="1.0" encoding="utf-8"?>arret_item.xml の先頭にあることを確認します。あなたが投稿したコードには欠けていますが、私は単なるコピペの省略です。それが存在せず、R 参照が壊れる可能性がある場合は、これが必要です。

また、Android LintEclipse で実行してみてください。実際には報告されていないエラーである可能性がある警告を指摘するのに役立ちます。

Lint の詳細: http://tools.android.com/tips/lint#TOC-Eclipse-Usage

ここに画像の説明を入力

于 2012-12-10T14:42:36.987 に答える
0

以下のいずれかがこの問題の解決に役立つと思います。

  • xml ファイルにエラーがないか確認してください。
  • res フォルダーに、ファイル名に無効な文字が含まれているファイルがあるかどうかを確認します
  • プロジェクトを実行->プロジェクトをクリーンアップします。R.java ファイルが再生成されます。

RK
http://ctrlaltsolve.blogspot.in

于 2015-06-04T06:36:51.890 に答える
0
ArretRestMethod arm = new ArretRestMethod(ListArretsActivity.this.R);  

上記の行に R が必要なのはなぜですか? コンテキストインスタンスが必要だと思います。

その場合
は、フィールドを作成しContext context;
ます-onCreateで-context= this;
コンテキストを次のように使用します-ArretRestMethod arm = new ArretRestMethod(context);

他のパラメーターが必要な場合は、代わりにそれを渡します。

于 2012-12-10T16:04:16.707 に答える
0

他にすべて失敗した場合...新しいプロジェクトを作成し、すべてのファイルを手動でコピーします。

私は最近、15 か月間触れられておらず、これを乗り越えることができなかったコードの更新を行っていました。見逃した構成設定やその他の些細な部分がある可能性がありますが、3時間前にこれを行っていたらよかったのにと思います。

于 2013-09-17T07:59:05.557 に答える
0

xml やその他の設定に問題がないことが確実な場合は、まずプロジェクトのバックアップを取り、「gen」フォルダー内の R ファイルを削除します。プロジェクトを再度ビルドすると、R ファイルが再生成されます (これは、プロジェクトが次の場合にのみ機能します)。 「R を解決できないか、フィールドではありません」以外のエラーはありません)。

于 2014-11-07T06:10:14.947 に答える