2012-09-23 20 views
0

我讀了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> 

乾杯。

+0

您可以發佈日誌 –

+0

究竟從哪裏得到這個錯誤?在Eclipse中? – Simon

+0

在日食中。在VideoView video =(VideoView)findViewById(R.id.video);線 – Pariya

回答

0

跑了一點點修改你的代碼運行正常

VideoView video=(VideoView)findViewById(R.id.video); 
    video.setVideoPath("android.resource://org.example.video/raw/learning"); 
    video.start(); 

不要添加文件的擴展名

+0

謝謝回答。我檢查這個,但它仍然給出了同樣的老錯誤。 – Pariya

+0

編輯請 –

+0

請幫助:(我做到了,但我不知道爲什麼R檔已被刪除,方案有4個錯誤,所有的這些都是「R不能解析爲一個變量」。 – Pariya

1

使用維修視頻工具來修復您的視頻文件,先下載試用版,並檢查是否所有您的文件被顯示。如果你對演示版本滿意,那麼你可以切換到完整版本來恢復它們。它是Mac操作系統上最好的fix error of video file軟件之一。希望這個軟件能幫助你理清你的問題。 From here你可以下載該軟件。

相關問題