我正在编写一个应用程序,其上有4个视频,当我播放第一个视频时一切正常,但是当我尝试播放第二个视频时,它说应用程序已经意外停止,并且即时使用了一些代码在2个活动中。我没有发现任何错误,是我的第一个程序,非常感谢您提前 我把代码放在下面:
布局Xml:primeraventana.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Escala_Uno" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="254dp" />
<Button
android:id="@+id/boton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Menú_Principal" />
</LinearLayout>
Java类:primeraventana.java
package gabrielrojas.com;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;
import android.net.Uri;
public class primeraventana extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);
VideoView mVideoView = (VideoView) findViewById(R.id.videoView1);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName()
+"/"+R.raw.test));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
mVideoView.isPlaying();
mVideoView.stopPlayback();
mVideoView.clearFocus();
TextView text = (TextView) findViewById(R.id.textview1);
Button boton3 = (Button) findViewById(R.id.boton3);
text.setText(R.string.Escala_Uno);
boton3.setText(R.string.Menú_Principal);
boton3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}}); }}
布局Xml :: segundaventana.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Escala_Dos"/>
<VideoView
android:id="@+id/videoView2"
android:layout_width="match_parent"
android:layout_height="254dp" />
<Button
android:id="@+id/boton4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Menú_Principal"/>
</LinearLayout>
Java Class :: segundaventana.java
package gabrielrojas.com;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;
import android.net.Uri;
public class segundaventana extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);
VideoView mVideoView = (VideoView) findViewById(R.id.videoView2);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName()
+"/"+R.raw.test));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
mVideoView.isPlaying();
mVideoView.stopPlayback();
mVideoView.clearFocus();
TextView text = (TextView) findViewById(R.id.textview2);
Button boton4 = (Button) findViewById(R.id.boton4);
text.setText(R.string.Escala_Dos);
boton4.setText(R.string.Menú_Principal);
boton4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}}); }}
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gabrielrojas.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".PruebaNumero3"
android:label="@string/title_activity_prueba_numero3" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".primeraventana"/>
<activity android:name=".segundaventana" />
<activity android:name=".terceraventana" />
<activity android:name=".cuartaventana" />
<activity android:name=".VideoActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar"
android:noHistory="true"/>
</application>
</manifest>
答案 0 :(得分:0)
你的问题在于:
Setting the layout:
public class segundaventana extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);-------------------------> Here lies your problem
更改为:
public class segundaventana extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.segundaventana);---------------------->this layout contains your videoview2
试试并说..