Сейчас minSdkVersion 19, я так понял она не тянел Toolbar.Я когда подключаю Toolbar в MainActivity у меня при запуске крашиться приложение, если его закоментирую, то все запускает. Подскажите, что можно сделать что бы при такой же минимальной версии СДК у меня работал Toolbar.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
toolbar = (Toolbar)findViewById(R.id.main_toolbar);
}
// setSupportActionBar(toolbar);
// getSupportActionBar().setTitle("Chatden");
viewPager = (ViewPager) findViewById(R.id.main_tabs_pager);
tabsAccessorAdapter = new TabsAccessorAdapter(getSupportFragmentManager());
viewPager.setAdapter(tabsAccessorAdapter);
tabLayout = (TabLayout) findViewById(R.id.mainTabLayout);
tabLayout.setupWithViewPager(viewPager);
}
Вот логи
11-13 11:19:58.057 16347-16347/com.example.chatden E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chatden, PID: 16347
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chatden/com.example.chatden.MainActivity}: java.lang.ClassCastException: androidx.appcompat.widget.Toolbar cannot be cast to android.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2511)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2571)
at android.app.ActivityThread.access$900(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1409)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:5620)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
Caused by: java.lang.ClassCastException: androidx.appcompat.widget.Toolbar cannot be cast to android.widget.Toolbar
at com.example.chatden.MainActivity.onCreate(MainActivity.java:35)
at android.app.Activity.performCreate(Activity.java:6320)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1121)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2571)
at android.app.ActivityThread.access$900(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1409)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:5620)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)