0
在我的應用程序中創建了一個ImageView並希望不斷旋轉它,但是當我嘗試在手機上運行應用程序時,它立即崩潰。這裏是我的代碼:Android應用程序在試圖連續旋轉圖像時崩潰
的Java活動文件:
public class FrontPage extends ActionBarActivity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_front_page);
initialize();
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setInterpolator(new LinearInterpolator());
rotateAnimation1.setDuration(2000);
rotateAnimation1.setRepeatCount(Animation.INFINITE);
iv.startAnimation(rotateAnimation1);
}
private void initialize() {
iv = (ImageView) findViewById(R.id.motorolaLogo);
}
XML文件:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_gravity="center_horizontal"
android:layout_height="150dp"
android:layout_width="150dp"
android:layout_marginTop="30dp"
android:id="@+id/motorolaLogo"
android:src="@drawable/motologo"
/>
</RelativeLayout>
請您詳細說明一下嗎?你的答案很短。 – bjb568
@ bjb568我恭敬地不同意。 user3462023問他爲什麼應用程序崩潰,我回答了原因。 – DigCamara
什麼是空指針異常?我如何避免它?還有什麼我應該知道的?有沒有這方面的文件? – bjb568