0

アンドロイドRはかなり長い間私を悩ませてきました。私の多くのプロジェクトでそれを見てきましたが、時々消えてしまうこともあれば、プロジェクトを再作成しなければならないこともあります。それでも、これは私の現在のプロジェクトでは何も解決しません。

論理的には、XMLファイルにエラーが含まれていると思われますが、それを見つけることができません。

私は開発環境としてEclipseを使用していますが、これは私のmain.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/title"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/title"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/btnNewTime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/overview" />

    <Button
        android:id="@+id/btnOverview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/overview" />

    <Button
        android:id="@+id/btnValues"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/values" />

    <Button
        android:id="@+id/btnExit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/exit" />

</LinearLayout>

これは私のstrings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Werkregistratie</string>
    <string name="title">Werkregistratie</string>
    <string name="overview">Overzicht</string>
    <string name="values">Salaris/reiskosten aanpassen</string>
    <string name="exit">Afsluiten</string>
</resources>

私は問題を見つけることができないので、あなたが私を助けてくれることを本当に望んでいます。

4

6 に答える 6

1

わかりました、これはEclipseの単なるバグのようですが、かなりの数の答えが部分的に正しいです。名前が検証されていることを確認してください(場合によってはLintを使用できます)。xmlが検証されていることを確認してください。次に、ビルドパスにエラーがないか確認します。その後、プロジェクトをクリーンに実行すると、すべてが正常になります。

また、この問題は新しいandroid SDKにはあまり現れないため、修正されたようです。

于 2014-07-23T03:12:00.543 に答える
0

パッケージ名が「com.example.test」の場合

次に、このようなものを試してください-

findViewById(com.example.test.R.id.textview1);

このようではない-

findViewById(R.id.textview1);

(* Rファイルが生成されていない場合にのみ使用してください)

于 2012-07-08T19:16:47.930 に答える
0

私はあなたのxmlを試しましたが、それは私にとってうまく機能します。うまくいけば、あなたのJavaクラスコードに問題があるかもしれません。内部の問題を見つけて、プロジェクトを確実にクリーンアップしてください。ではごきげんよう :)

于 2012-07-08T19:18:33.140 に答える
0

パッケージ名がcom.foo.bar.packageの場合、次のようにする必要がありますimport

import com.foo.bar.package.R;

次に、findViewByIdこの表記を使用して機能する必要があります。

Button btnValue = (Button)findViewById(R.id.btnValue);

時々、Eclipseは「リソースが不足している」ということになると非常に不快になることがあります。láはR生成されないファイルを見つけることができません。

于 2012-07-08T19:19:33.027 に答える
0

I think I've ran into this problem before, the only way I could get around it is to try again with a fresh project and import my code. Inefficient and clunky I know but this was how I managed to get the R file to generate after a frustrating few hours.

Failing that you might be able to find something to help you here

于 2012-07-08T21:14:12.773 に答える
0

今日、ワークスペースからアプリsrcをインポートするときに、この問題に直面しました。Rを使用するすべてのコード行でエラーが表示されていました。

プロパティ/Androidビューから実際にtagetSDKを4.0に設定する必要があることをどこかで読みました。マニフェストの8としてのminsdkバージョン。

それは魅力のように機能しました。

もう1つ、res file / layouts/drawableの名前に大文字が付いていることが問題になる可能性があります。いつかThumbs.dbがドローアブルフォルダに生成され、同じ問題が発生します。

ありがとう!!!

于 2012-07-08T21:09:21.683 に答える