Ich habe mein eigenes TabLayout-Menü (aus einer leeren Aktivität) mit einem modifizierten SectionPagerAdapter aus einem TabActivity-Projekt erstellt. Ich habe nur die Methode getItem() geändert und die Seitentitelmethode entfernt.App stoppt nach dem Setzen des tablayout mit ViewPager
public Fragment getItem(int position) {
switch (position)
{
case 0:
HomeActivity home = new HomeActivity();
return home;
case 1:
PayActivity pay = new PayActivity();
return pay;
case 2:
VideoActivity video = new VideoActivity();
return video;
case 3:
BillActivity bill = new BillActivity();
return bill;
default:
return null;
}
}
}
Und nach der Hinrichtung von
TabLayout tabToolbar = (TabLayout) findViewById(R.id.tabToolbar);
ViewPager viewPager = (ViewPager) findViewById(R.id.container);
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mSectionsPagerAdapter);
tabToolbar.setupWithViewPager(viewPager);
meine App gestoppt wurde.
Wenn ich
tabToolbar.setupWithViewPager(viewPager);
Kommentar als mein Menü funktioniert nicht, aber ich kann innerhalb des ViewPager zwischen meinen Fragmenten streichen.
Ich möchte mit meinem Menü-Taste wischen und mit meinem Mauscursor auch swippen.
Wenn Sie weitere Informationen oder Ressourcen benötigen, lassen Sie es mich wissen.
Edit:
Das Fehlerprotokoll zeigt:
09-08 06:19:05.822 4207-4207/com.example.fdai3744.t_online20 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.fdai3744.t_online20, PID: 4207
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fdai3744.t_online20/com.example.fdai3744.t_online20.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setColorFilter(int, android.graphics.PorterDuff$Mode)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setColorFilter(int, android.graphics.PorterDuff$Mode)' on a null object reference
at com.example.fdai3744.t_online20.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2. edit:
Ich fand heraus, dass mein Adapter keine "öffentliche CharSequence getPageTitle (int position)" Methode hat.
Haben Sie einige Fehler von log? – Dario
Teilen Sie Ihre Log-Katze –
Fertig! Siehe unten meine Frage. –