繁体   English   中英

图片无法解析或不是字段

[英]image cannot be resolved or is not a field

我正在做一个Android项目,使用Eclipse创建动画。 在MainActivity.java上,编译器显示5个皮棉错误,如下所示

-图像无法解析或不是字段-activity_main无法解析或不是字段-translate无法解析或不是字段-rotate无法解析或不是字段-shape无法解析或不是字段

这是我在MainActivity.java中执行的代码

    package ahmed103.appdemo;




    import android.R;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Context;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.animation.Animation.AnimationListener;
    import android.view.animation.*;
    import android.view.animation.AnimationUtils;
    import android.widget.Button;
    import android.widget.ImageView;

    public class MainActivity extends Activity implements AnimationListener {
ImageView image;
Animation animation1;
Animation animation2;
Button rotate, translate;
Context context = this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image = (ImageView) findViewById(R.id.image);
    rotate = (Button) findViewById(R.id.rotate);
    translate = (Button) findViewById(R.id.translate);
    image.setImageResource(R.drawable.shape);
    animation1 = AnimationUtils.loadAnimation(this, R.anim.rotate);
    animation2 = AnimationUtils.loadAnimation(this, R.anim.translate);

    userInputHandler();
}

private void userInputHandler() {
    rotate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            image.startAnimation(animation1);

        }
    });

    translate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            image.startAnimation(animation2);

        }
    });

}

@Override
public void onAnimationEnd(Animation animation) {
    image.setVisibility(View.VISIBLE);
}

@Override
public void onAnimationRepeat(Animation animation) {
    image.setVisibility(View.VISIBLE);
}

@Override
public void onAnimationStart(Animation animation) {
    image.setVisibility(View.VISIBLE);
}

}

这是我的activity_main.xml文件

<html>
<LinearLayout 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:background="#DCDCDC"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context=".MainActivity" >

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="70dp"
    android:minHeight="150dp"
    android:minWidth="150dp" />

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</TableRow>

<Button
    android:id="@+id/rotate"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:layout_weight="1"
    android:text="@string/rotate_text" />

<Button
    android:id="@+id/translate"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:layout_weight="1"
    android:text="@string/translate_text" />

</LinearLayout>
</html>

删除以下导入

import android.R;

你也有

<html> and </html>// should be removed from xml 

进口

import ahmed103.appdemo.R;

并使用

<?xml version="1.0" encoding="utf-8"?>

作为您的activity_main.xml的第一条语句

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM