我刚开始使用Android开发搞乱,我想简单地播放视频文件在网络上的某个地方。我main.xml中看起来是这样的:应用程序试图在崩溃时使用VideoView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:layout_height="wrap_content" android:id="@+id/button1" android:layout_width="wrap_content" android:text="@string/buttonText" android:onClick="clickHandler"></Button>
<VideoView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/MyVideoView"></VideoView>
</LinearLayout>
和我的java文件看起来像这样: 包com.dop.videoTest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class VideoTest extends Activity {
private String path = "http://commonsware.com/misc/test2.3gp";
private VideoView mVideoView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void clickHandler(View view)
{
mVideoView = (VideoView) findViewById(R.id.MyVideoView);
if (path == "") {
Toast.makeText(
VideoTest.this,
"Please edit VideoViewDemo Activity, and set path"
+ " variable to your media file URL/path",
Toast.LENGTH_LONG).show();
} else {
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
}
所以当我点击我的按钮,它只是说“应用视频测试已意外停止,请重试。”
有什么想法吗?
比较字符串使用等号('path.equals( “”)'),而不是'路径== “”' – MByD 2011-05-03 21:45:28
请加一个logcat的日志 – MByD 2011-05-03 21:51:55
做==工作正常。此外,这不会解决问题 – Ronnie 2011-05-03 22:05:37