Несколько выпусков VideoViewAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Несколько выпусков VideoView

Сообщение Anonymous »

У меня есть приложение, содержащее 5 кнопку. Каждая кнопка открывает различные видеовиусы. When I create code I have red mark under (new MediaController(this)) I can't find how to fix it.
After apply changed to: (new MediaController(this)) I get another error
My code:
MultipleButton class:
public class MultipleButton extends Activity {
String night;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void handleClick(View v){
//Create an intent to start the new activity.
Intent intent = new Intent();
intent.setClass(this,My_videos.clpublic class My_videos extends Activity {
private Button button;
private VideoView vid;
String night;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);

initializeVideoViews();
}

private void initializeVideoViews() {
String night = getIntent().getStringExtra("video");

if (night.equalsIgnoreCase("button1")) {
button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
vid = (VideoView) findViewById(R.id.videoView1);
vid.setVideoURI(Uri.parse("android.resource://" +
getPackageName() + "/" + R.raw.a));
vid.setMediaController(new MediaController(My_videos.this));
vid.requestFocus();
vid.start();
}
});
} else if (night.equalsIgnoreCase("button2")) {
button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {

vid = (VideoView) findViewById(R.id.videoView1);
vid.setVideoURI(Uri.parse("android.resource://" +
getPackageName() + "/" + R.raw.b));
vid.setMediaController(new MediaController(My_videos.this));
vid.requestFocus();
}
});
} else if (night.equalsIgnoreCase("button3")) {
button = (Button) findViewById(R.id.button3);

button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
vid = (VideoView) findViewById(R.id.videoView1);
vid.setVideoURI(Uri.parse("android.resource://" +
getPackageName() + "/" + R.raw.c));
vid.setMediaController(new MediaController(My_videos.this));
vid.requestFocus();
}
});
} else if (night.equalsIgnoreCase("button4")) {
button = (Button) findViewById(R.id.button4);

button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
vid = (VideoView) findViewById(R.id.videoView1);
vid.setVideoURI(Uri.parse("android.resource://" +
getPackageName() + "/" + R.raw.d));
vid.setMediaController(new MediaController(My_videos.this));
vid.requestFocus();
}
});
} else if (night.equalsIgnoreCase("button5")) {
button = (Button) findViewById(R.id.button5);

button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
vid = (VideoView) findViewById(R.id.videoView1);
vid.setVideoURI(Uri.parse("android.resource://" +
getPackageName() + "/" + R.raw.e));
vid.setMediaController(new MediaController(My_videos.this));
vid.requestFocus();
}
});
}
}
}

logcat:
I/Process(25196): Sending signal. PID: 25196 SIG: 9
D/AndroidRuntime(25447): Shutting down VM
W/dalvikvm(25447): threadid=1: thread exiting with uncaught exception (group=0x40015578)
E/AndroidRuntime(25447): FATAL EXCEPTION: main
E/AndroidRuntime(25447): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tsn.dr/com.tsn.dr.My_videos}: java.lang.NullPointerException
E/AndroidRuntime(25447):at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:1651)
E/AndroidRuntime(25447):at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:1667)
E/AndroidRuntime(25447):at android.app.ActivityThread.access$1500 (ActivityThread.java:117)
E/AndroidRuntime(25447):at android.app.ActivityThread$H.handleMessage (ActivityThread.java:935)
E/AndroidRuntime(25447):at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(25447):at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(25447):at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(25447):at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(25447):at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(25447):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:842)
E/AndroidRuntime(25447):at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:600)
E/AndroidRuntime(25447):at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(25447): Caused by: java.lang.NullPointerException
E/AndroidRuntime(25447):at com.tsn.dr.My_videos.initializeVideoViews (My_videos.java:31)
E/AndroidRuntime(25447):at com.tsn.dr.My_videos.onCreate(My_videos.java:24)
E/AndroidRuntime(25447):at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1047)
E/AndroidRuntime(25447):at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:1615)
E/AndroidRuntime(25447): ... 11 more
< /code>
manifest.xml:
















< /code>
main.xml:












< /code>
video.xml:






Подробнее здесь: https://stackoverflow.com/questions/120 ... view-issue
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»