我讀了Hello Android的書。該應用應播放視頻。我將視頻複製到res/raw中。該應用程序不運行。爲什麼?如何解決視頻播放器程序的錯誤?
我得到以下錯誤:
video cannot be resolved or is not a field
Video.java
package org.example.video;
import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;
public class Video extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView video=(VideoView)findViewById(R.id.video);
video.setVideoPath("/raw/VID_20120604_142208.mp4");
video.start();
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/video"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
乾杯。
您可以發佈日誌 –
究竟從哪裏得到這個錯誤?在Eclipse中? – Simon
在日食中。在VideoView video =(VideoView)findViewById(R.id.video);線 – Pariya