У меня есть Activity
с Button
, который Intent
относительно того, как был запущен Activity
.Предыдущий Activity
- это ListView
, который передается дополнительно к этому Activity
, чтобы определить другие значения для Button
щелчка Intents
.Пожалуйста, посмотрите на мой код ниже:
public class ContentViewer extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getIntent().getExtras();
int chooser = bundle.getInt("Layout");
switch(chooser) {
case 0:
setContentView(R.layout.about);
break;
case 1:
setContentView(R.layout.contact);
break;
case 2:
setContentView(R.layout.contentviewer);
break;
case 3:
setContentView(R.layout.contact);
break;
case 4:
setContentView(R.layout.contact);
break;
case 5:
setContentView(R.layout.contact);
break;
case 6:
setContentView(R.layout.contact);
break;
case 7:
setContentView(R.layout.contact);
break;
case 8:
setContentView(R.layout.contact);
break;
case 9:
setContentView(R.layout.contact);
break;
}
final int linker = bundle.getInt("Layout");
Button vlink = (Button)findViewById(R.id.videolink);
vlink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(linker) {
case 0:
Intent v0 = new Intent(Intent.ACTION_VIEW,
Uri.parse("vnd.youtube://" + "0lh_UWF9ZP4"));
startActivity(v0);
break;
case 1:
Intent v1 = new Intent(Intent.ACTION_VIEW,
Uri.parse("vnd.youtube://" + "0lh_UWF9ZP4"));
startActivity(v1);
break;
case 2:
Intent v2 = new Intent(Intent.ACTION_VIEW,
Uri.parse("vnd.youtube://" + "0lh_UWF9ZP4"));
startActivity(v2);
break;
}
}
});
}
}
Каждый раз, когда я нажимаю кнопку, приложение закрывается.Я понятия не имею, где мои ошибки могут быть.Вот журнал ошибок;
01-10 00:03:40.895: W/dalvikvm(5759): threadid=1: thread exiting with uncaught exception (group=0x40c271f8)
01-10 00:03:40.900: E/AndroidRuntime(5759): FATAL EXCEPTION: main
01-10 00:03:40.900: E/AndroidRuntime(5759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.borislemke.cookingwithdog/com.borislemke.cookingwithdog.ContentViewer}: java.lang.NullPointerException
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.os.Looper.loop(Looper.java:137)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.ActivityThread.main(ActivityThread.java:4507)
01-10 00:03:40.900: E/AndroidRuntime(5759): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 00:03:40.900: E/AndroidRuntime(5759): at java.lang.reflect.Method.invoke(Method.java:511)
01-10 00:03:40.900: E/AndroidRuntime(5759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
01-10 00:03:40.900: E/AndroidRuntime(5759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
01-10 00:03:40.900: E/AndroidRuntime(5759): at dalvik.system.NativeStart.main(Native Method)
01-10 00:03:40.900: E/AndroidRuntime(5759): Caused by: java.lang.NullPointerException
01-10 00:03:40.900: E/AndroidRuntime(5759): at com.borislemke.cookingwithdog.ContentViewer.onCreate(ContentViewer.java:61)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.Activity.performCreate(Activity.java:4465)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-10 00:03:40.900: E/AndroidRuntime(5759): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
01-10 00:03:40.900: E/AndroidRuntime(5759): ... 11 more