NullPointerException导致android动画崩溃
我一直在尝试运行一个动画,但它崩溃的某些原因,我不明白。 它在日志cat中写入,因为nullpointerexception。但我不明白 我应该怎么做\改变它。 我怎样才能解决这个问题?塔克斯 主要活动: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;
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);