2010-07-22 2 views
0

Если я не импортировать R, я получаю «идентификатор не может быть разрешен или не поле»Android - Ошибка, если я не импортирую R и еще одну ошибку, если я это сделаю?

(R.id.mainanim); 

И если я импортировать R, ушел ошибка идентификатор, но я получаю «основной и mainanim не может быть разрешенным или не является полем ». Это мои .xml-файлы.

Вот мой код ... может быть, есть ошибка, которую я не видел?

package com.example.carrottest2; 

import android.app.Activity; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.widget.ImageView; 
import android.R; 

public class Carrottest2 extends Activity { 
/** Called when the activity is first created. */ 

AnimationDrawable mainanimation; 

public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 

    ImageView mainimage = (ImageView) findViewById(R.id.mainanim); 
    mainimage.setBackgroundResource(R.anim.mainanim); 
    mainanimation = (AnimationDrawable) mainimage.getBackground(); 

main.xml:

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

Mainanim.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"  android:oneshot="false"> 
<item android:drawable="@drawable/carrotsmile" android:duration="2000" /> 
<item android:drawable="@drawable/carrotblink" android:duration="2000" /> 
</animation-list>  
+2

удалить: import android.R; и сделать чистый проект в Eclipse> Меню проекта – Sephy

ответ

2

Mainanim.xml является расположение, а не идентификатор. Чтобы сделать анимацию в своем макете, вам нужно ImageView, чтобы установить AnimationDrawable в качестве фона.

+0

Идентификатор будет выглядеть как TextView в вашем Main.xml. Это объект внутри xml-файла. Однако, чтобы «получить» идентификатор, вы должны установить его, поэтому ваш TextView в xml будет иметь Aurora

0

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