【发布时间】:2014-02-02 08:42:23
【问题描述】:
我正在做一个项目,我在 Intent 中添加了 ProgressBar。 ProgressBar 位于图像之上。
每当我添加以下代码时
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_greet);
pb = (ProgressBar)findViewById(R.id.progressBar1);
pb.getAnimation().setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
});
Intent intent = new Intent(Greet.this, SearchField.class);
startActivity(intent);
}
我收到了nullPointerException
当我删除
pb.getAnimation().setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
});
错误消失了。
我无法弄清楚为什么我会收到 NullPointerException,查看代码,一切似乎都应该是这样。
我觉得我要在这里学习一些新东西,因为我清理了项目,尝试了它,但无论如何都会出现错误......所以我不确定我错过了什么。
编辑:
XML 中的 ActivityGreet
<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:background="#ffffff"
tools:context=".Greet" >
<ImageView
android:id="@+id/fitnessPic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/description"
android:src="@drawable/appleorange"/>
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="64dp" />
</RelativeLayout>
在图像上放置 ProgressBar 是否存在已知问题?
【问题讨论】:
-
底部的建议均无效。
标签: java android animation nullpointerexception progress-bar