2014-10-27 3 views
0

Это произошло вчера, когда я заменял несколько элементов в моем XML. Когда я пошел в свой основной класс, я увидел, что все ссылки на R были отмечены красным цветом, и мне сказали, что R не может быть разрешен переменной. Сначала я попытался перестроить и очистить свой проект, но это не сработало, поэтому я предполагаю, что проблема заключается в XML-файле, который я недавно редактировал, однако теперь я знаю, где будет проблема. И да, я убедился, что android.R не импортируется.Android не может решить R

Несколько дополнительных деталей:

  • Я использую Android 5.0 (API 21)
  • R проблемы не в моих других файлов классов, которые ссылаются на Р.

Здесь является XML-файл в вопросе:

<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" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView2" 
     android:layout_marginTop="20dp" 
     android:text="@string/rye" 
     android:textColor="#888888" 
     android:textAppearance="?android:textAppearanceLarge" /> 

    <RatingBar 
     android:id="@+id/ratingBar1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView1" 
     android:layout_below="@+id/textView1" 
     android:isIndicator="false" 
     android:numStars="5" 
     android:stepSize="1" /> 

    <Button 
     android:id="@+id/dropDownButton" 
     android:layout_width="48dip" 
     android:layout_height="48dip" 
     android:layout_alignBottom="@+id/ratingBar1" 
     android:layout_toRightOf="@+id/ratingBar1" 
     android:onClick="dropDown" 
     android:text=">"/> 

    <RelativeLayout 
     android:id="@+id/dropDownLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignTop="@+id/textView2" 
     android:visibility="gone" > 

     <TextView 
      android:id="@+id/testTV" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Testing dropdown" /> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/tipTitle" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#888888" 
     android:layout_below="@+id/quizFragment" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <FrameLayout 
     android:id="@+id/quizFragment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/dropDownButton" /> 

    <TextView 
     android:id="@+id/TextView02" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/people_dining_title" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#888888" 
     android:layout_below="@+id/seekBar3" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:id="@+id/subtotalTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/subtotal" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#888888" 
     android:layout_below="@+id/seekBar2" 
     android:layout_alignLeft="@+id/seekBar2" 
     android:layout_alignStart="@+id/seekBar2" /> 

    <TextView 
     android:id="@+id/totalTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/subtotalText" 
     android:layout_below="@+id/subtotalText" 
     android:layout_marginTop="10dp" 
     android:text="@string/total" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#888888" /> 

    <TextView 
     android:id="@+id/totalText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/subtotalText" 
     android:layout_alignRight="@+id/subtotalText" 
     android:layout_below="@+id/totalTitle" 
     android:focusable="false" 
     android:padding="2dp" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#ffff000c" /> 

    <EditText 
     android:id="@+id/subtotalText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/subtotalTitle" 
     android:ems="10" 
     android:hint="SUBTOTAL" 
     android:inputType="numberDecimal" 
     android:padding="2dp" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#ff0000" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignRight="@+id/seekBar2" 
     android:layout_alignEnd="@+id/seekBar2"> 
    </EditText> 

    <TextView 
     android:id="@+id/eppTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/totalText" 
     android:layout_below="@+id/totalText" 
     android:layout_marginTop="10dp" 
     android:text="@string/epp" 
     android:textColor="#888888" 
     android:textAppearance="?android:textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/eppText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/eppTitle" 
     android:layout_alignRight="@+id/totalText" 
     android:layout_below="@+id/eppTitle" 
     android:focusable="false" 
     android:padding="2dp" 
     android:text="" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#FFFFFF" /> 

    <Button 
     android:id="@+id/buttonDone" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/eppText" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:onClick="done" 
     android:text="@string/done" 
     android:textStyle="bold" /> 

    <SeekBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/seekBar2" 
     android:layout_below="@+id/TextView02" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 

    <SeekBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/seekBar3" 
     android:layout_below="@+id/textView2" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"/> 

</RelativeLayout> 
+0

Это случается со мной иногда и в Eclipse (вы используете это?), И я, как правило, заканчиваю бушует и создаю новый проект с нуля и просто импортирую все файлы .java и .xml. Я комментирую, поэтому я могу посмотреть на это позже, если у кого-то есть решение проблемы. – Dyrborg

+0

Возможный дубликат [«R не может быть разрешен переменной»?] (Http://stackoverflow.com/questions/7824730/r-cannot-be-resolved-to-a-variable) –

ответ

0

Я не могу видеть никаких проблем в этом XML-файле. Можете ли вы также опубликовать код для файла класса, в котором вы его используете, и проверить, не используете ли вы android.r и используете com.yourapp.r. Это может быть так. Не могли бы вы также опубликовать класс

+0

Когда я пошел, чтобы открыть проект и файл класса, чтобы показать вам, я снова попытался импортировать класс R (он даже не появлялся раньше), и он появился, и все кажется исправленным! –

+0

Возможно, он работал с импортом Happy, чтобы помочь;) Mark & ​​upvote, если это было полезно – BackStabber

+0

Случается со мной все время мы копируем Лот: D – BackStabber

Смежные вопросы