Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NullPointerException导致android动画崩溃_Android_Animation_Crash - Fatal编程技术网

NullPointerException导致android动画崩溃

NullPointerException导致android动画崩溃,android,animation,crash,Android,Animation,Crash,我一直在尝试运行一个动画,但它崩溃的某些原因,我不明白。 它在日志cat中写入,因为nullpointerexception。但我不明白 我应该怎么做\改变它。 我怎样才能解决这个问题?塔克斯 主要活动: package nir.rauch.again; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.animation.Animation;

我一直在尝试运行一个动画,但它崩溃的某些原因,我不明白。 它在日志cat中写入,因为nullpointerexception。但我不明白 我应该怎么做\改变它。 我怎样才能解决这个问题?塔克斯

主要活动:

package nir.rauch.again;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Animation anim = AnimationUtils.loadAnimation(getBaseContext(),
                R.anim.correctanim);
        ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);
        duck.startAnimation(anim);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
it的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="155dp"
        android:contentDescription="Duck Animation"
        android:src="@drawable/duckwithswaves" />

</RelativeLayout>
试试这个

findViewById应包含ImageView的id

改变这个

ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);


在您的图像视图中,您使用R.drawable引用了您的图像视图,而它应该是R.id

换线

 ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);
 ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);
详情如下:

ImageView duck = (ImageView) findViewById(R.id.yourimageid);
换线

 ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);
 ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);


正在使用Getter setter方法。已检查但未执行任何操作。。HashSet使用karay-ne防止重复值mate??为什么不在SO中发布一个问题?因为即使没有我也无法指导你正确的方法。没有存储HashMap Arraylist。
 ImageView duck = (ImageView) findViewById(R.drawable.duckwithswaves);
 ImageView duck = (ImageView) findViewById(R.id.imageView1);