java - My Android App Keeps Crashing When Opening A New Activity From My Navigation Drawer -


i new coding in android studio , have been trying make application school. have made navigation drawer launches few new activities. right now, launches 2 activities settings activity (which has nothing in yet) , basketball tutorial home page activity. whenever launch settings activity, activity shows , application not crash. however, when click on basketball tutorial home page activity, app crashes reason. activity contains beginning of youtube structure, once click on buttons, sends video. have splash screen launches main activity. please in anyway can. not letting me add imports java file onto forum, have let them out, public class....extends....as not working. whole file comes no errors.

android manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.jehan.sportstutorials" >      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="sports tutorials"         android:theme="@style/apptheme" >         <activity android:name=".splash" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity             android:name=".mainactivity"             android:label="sports tutorials" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.default" />             </intent-filter>         </activity>         <activity             android:name=".settingsactivity"             android:label="settings"             android:parentactivityname=".mainactivity" >         </activity>         <activity             android:name=".basketball_tutorial_home_page"             android:label="basketball tutorials"             android:parentactivityname=".mainactivity">         </activity>     </application>  </manifest> 

main activity xml:

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/navigation_drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitssystemwindows="@bool/fitssystemwindows">      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">          <framelayout             android:layout_width="match_parent"             android:layout_height="@dimen/status_bar_kitkat_height"             android:background="?colorprimary"/>          <framelayout             android:layout_width="match_parent"             android:layout_height="0dp"             android:background="?colorprimarydark"/>      </linearlayout>      <framelayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margintop="0dp">          <textview             android:id="@+id/textview"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:text="welcome sports tutorials!"             android:textappearance="@style/textappearance.appcompat.display1"             android:textcolor="@color/md_text"             android:singleline="false"             android:padding="20dp"             android:gravity="center"             android:textstyle="bold"             android:textisselectable="false" />          <textview             android:id="@+id/textview2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center|bottom"             android:text="just swipe left started!"             android:textappearance="@style/textappearance.appcompat.display1"             android:textcolor="@color/md_text"             android:singleline="false"             android:padding="20dp"             android:gravity="center"             android:textsize="20sp"             android:textstyle="italic"             android:layout_marginbottom="30dp"/>          <android.support.v7.widget.toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?actionbarsize"             android:minheight="?attr/actionbarsize"             android:background="@drawable/action_bar_color"             android:elevation="4dp"             app:popuptheme="@style/themeoverlay.appcompat.light"             app:theme="@style/toolbartheme" />      </framelayout>      <android.support.design.widget.navigationview         android:id="@+id/navigation_view"         android:layout_width="wrap_content"         android:layout_height="match_parent"         android:layout_gravity="start"         android:fitssystemwindows="@bool/fitssystemwindows"         app:headerlayout="@layout/navigation_drawer_header"         app:menu="@menu/navigation_drawer_menu"         app:theme="@style/navigationviewtheme" />  </android.support.v4.widget.drawerlayout> 

main activity java:

drawerlayout drawerlayout; toolbar toolbar; actionbar actionbar; textview textview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      actionbar = getsupportactionbar();     actionbar.sethomeasupindicator(r.drawable.ic_menu_white_24dp);     actionbar.setdisplayhomeasupenabled(true);       drawerlayout = (drawerlayout)        findviewbyid(r.id.navigation_drawer_layout);      navigationview navigationview = (navigationview) findviewbyid(r.id.navigation_view);     if (navigationview != null) {         setupnavigationdrawercontent(navigationview);     }      setupnavigationdrawercontent(navigationview);  }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_main, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {         case android.r.id.home:             drawerlayout.opendrawer(gravitycompat.start);             return true;     }     return super.onoptionsitemselected(item); }  private void setupnavigationdrawercontent(navigationview navigationview) {     navigationview.setnavigationitemselectedlistener(             new navigationview.onnavigationitemselectedlistener() {                 @override                 public boolean onnavigationitemselected(menuitem menuitem) {                     textview = (textview) findviewbyid(r.id.textview);                     switch (menuitem.getitemid()) {                         case r.id.item_navigation_drawer_basketball:                             menuitem.setchecked(true);                             textview.settext(menuitem.gettitle());                             drawerlayout.closedrawer(gravitycompat.start);                             intent = new intent(mainactivity.this, basketball_tutorial_home_page.class);                             startactivity(i);                             return true;                         case r.id.item_navigation_drawer_starred:                             menuitem.setchecked(true);                             textview.settext(menuitem.gettitle());                             drawerlayout.closedrawer(gravitycompat.start);                             return true;                         case r.id.item_navigation_drawer_sent_mail:                             menuitem.setchecked(true);                             textview.settext(menuitem.gettitle());                             drawerlayout.closedrawer(gravitycompat.start);                             return true;                         case r.id.item_navigation_drawer_drafts:                             menuitem.setchecked(true);                             textview.settext(menuitem.gettitle());                             drawerlayout.closedrawer(gravitycompat.start);                             return true;                         case r.id.item_navigation_drawer_settings:                             menuitem.setchecked(true);                             textview.settext(menuitem.gettitle());                             drawerlayout.closedrawer(gravitycompat.start);                             intent intent1 = new intent(mainactivity.this, settingsactivity.class);                             startactivity(intent1);                             return true;                         case r.id.item_navigation_drawer_help:                             menuitem.setchecked(true);                             toast.maketext(mainactivity.this, menuitem.gettitle().tostring(), toast.length_short).show();                             drawerlayout.closedrawer(gravitycompat.start);                             return true;                     }                     return true;                 }             }); } 

basketball tutorial home page xml:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@color/md_divider">      <framelayout         android:layout_width="match_parent"         android:layout_height="0dp"         android:background="?colorprimary"/>      <android.support.v7.widget.toolbar         android:layout_margintop="0dp"         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?actionbarsize"         android:background="@drawable/action_bar_color"         android:elevation="4dp"         app:popuptheme="@style/themeoverlay.appcompat.light"         app:theme="@style/toolbartheme" />      <linearlayout         android:orientation="vertical"         android:layout_width="match_parent"         android:layout_height="509dp"         android:layout_gravity="bottom"         android:background="@color/md_divider"         android:padding="7dp">          <linearlayout             android:orientation="horizontal"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="#00ff00"             android:elevation="4dp">              <imagebutton                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/imagebutton1"                 android:scaletype="fitstart"                 android:background="#00ff00"                 android:layout_gravity="center"                 android:elevation="2dp"                 android:src="@drawable/icon_shooting_tutorial"/>              <linearlayout                 android:orientation="vertical"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:background="#00ff00">                  <button                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     android:text="basketball shooting tutorial"                     android:id="@+id/button1"                     android:layout_gravity="center"                     android:padding="5dp"                     android:layout_weight="1"                     android:theme="@style/textappearance.appcompat.body2"                     android:textsize="14sp"                     android:gravity="start|bottom"                     android:background="#00ff00"                     android:inputtype="text" />                  <button                     android:layout_width="fill_parent"                     android:layout_height="fill_parent"                     android:text="length: 04:43"                     android:id="@+id/button2"                     android:layout_gravity="center"                     android:layout_weight="2"                     android:theme="@style/textappearance.appcompat.body1"                     android:gravity="start"                     android:textsize="12sp"                     android:textstyle="italic"                     android:paddingleft="5dp"                     android:paddingright="5dp"                     android:paddingbottom="5dp"                     android:background="#00ff00"                     android:inputtype="time"/>             </linearlayout>          </linearlayout>     </linearlayout>   </framelayout> 

basketball tutorial java:

toolbar toolbar;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_basketball_tutorial_home_page);      toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);     getsupportactionbar().setdisplayhomeasupenabled(true);      typedvalue typedvaluecolorprimarydark = new typedvalue();     basketball_tutorial_home_page.this.gettheme().resolveattribute(r.attr.colorprimarydark, typedvaluecolorprimarydark, true);     final int colorprimarydark = typedvaluecolorprimarydark.data;     if (build.version.sdk_int >= 21) {         getwindow().setstatusbarcolor(colorprimarydark);     } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_basketball_tutorial_home_page, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_bar) {         return true;     }      return super.onoptionsitemselected(item); } 

navigation drawer menu:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android">      <group android:checkablebehavior="single">         <item             android:checked="true"             android:id="@+id/item_navigation_drawer_basketball"             android:icon="@drawable/basketball_drawer"             android:title="basketball" />         <item             android:id="@+id/item_navigation_drawer_starred"             android:icon="@drawable/ic_action_toggle_star"             android:title="starred" />         <item             android:id="@+id/item_navigation_drawer_sent_mail"             android:icon="@drawable/ic_action_content_send"             android:title="sent mail" />         <item             android:id="@+id/item_navigation_drawer_drafts"             android:icon="@drawable/ic_action_content_drafts"             android:title="drafts" />     </group>      <item android:title="more">         <menu>             <item                 android:id="@+id/item_navigation_drawer_settings"                 android:icon="@drawable/ic_action_action_settings"                 android:title="settings" />             <item                 android:id="@+id/item_navigation_drawer_help"                 android:icon="@drawable/ic_action_action_help"                 android:title="help" />         </menu>     </item>  </menu> 

here log of app:

07-13 12:30:34.823    1011-1018/com.jehan.sportstutorials w/art﹕ suspending threads took: 8.605ms 07-13 12:30:34.896    1011-1023/com.jehan.sportstutorials i/art﹕ background sticky concurrent mark sweep gc freed 3067(319kb) allocspace objects, 0(0b) los objects, 0% free, 1511kb/1511kb, paused 23.822ms total 134.618ms 07-13 12:30:34.922    1011-1023/com.jehan.sportstutorials w/art﹕ suspending threads took: 25.693ms 07-13 12:30:35.187    1011-1023/com.jehan.sportstutorials i/art﹕ background partial concurrent mark sweep gc freed 349(33kb) allocspace objects, 0(0b) los objects, 40% free, 1477kb/2mb, paused 3.349ms total 132.790ms 07-13 12:30:35.201    1011-1018/com.jehan.sportstutorials w/art﹕ suspending threads took: 5.092ms 07-13 12:30:38.036    1011-1011/com.jehan.sportstutorials i/process﹕ sending signal. pid: 1011 sig: 9 07-13 12:30:52.636    1153-1173/com.jehan.sportstutorials d/openglrenderer﹕ render dirty regions requested: true 07-13 12:30:52.644    1153-1153/com.jehan.sportstutorials d/﹕ hostconnection::get() new host connection established 0xae0c9580, tid 1153 07-13 12:30:52.724    1153-1153/com.jehan.sportstutorials d/atlas﹕ validating map... 07-13 12:30:52.972    1153-1173/com.jehan.sportstutorials d/﹕ hostconnection::get() new host connection established 0xae0c9e70, tid 1173 07-13 12:30:52.983    1153-1173/com.jehan.sportstutorials i/openglrenderer﹕ initialized egl, version 1.4 07-13 12:30:53.003    1153-1173/com.jehan.sportstutorials d/openglrenderer﹕ enabling debug mode 0 07-13 12:30:53.035    1153-1173/com.jehan.sportstutorials w/egl_emulation﹕ eglsurfaceattrib not implemented 07-13 12:30:53.035    1153-1173/com.jehan.sportstutorials w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xa6c4c640, error=egl_success 07-13 12:30:53.630    1153-1172/com.jehan.sportstutorials i/system.out﹕ 888.0 07-13 12:30:54.639    1153-1172/com.jehan.sportstutorials i/system.out﹕ 1073.4697 07-13 12:30:55.660    1153-1172/com.jehan.sportstutorials i/system.out﹕ 1252.9235 07-13 12:30:56.680    1153-1172/com.jehan.sportstutorials i/system.out﹕ 1437.9651 07-13 12:30:57.704    1153-1153/com.jehan.sportstutorials i/appcompatviewinflater﹕ app:theme deprecated. please move using android:theme instead. 07-13 12:30:57.731    1153-1153/com.jehan.sportstutorials i/appcompatviewinflater﹕ app:theme deprecated. please move using android:theme instead. 07-13 12:30:57.935    1153-1173/com.jehan.sportstutorials w/egl_emulation﹕ eglsurfaceattrib not implemented 07-13 12:30:57.935    1153-1173/com.jehan.sportstutorials w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xa6c4c660, error=egl_success 07-13 12:30:59.594    1153-1153/com.jehan.sportstutorials i/choreographer﹕ skipped 94 frames!  application may doing work on main thread. 07-13 12:31:03.214    1153-1153/com.jehan.sportstutorials i/appcompatviewinflater﹕ app:theme deprecated. please move using android:theme instead. 07-13 12:31:03.237    1153-1153/com.jehan.sportstutorials w/resourcetype﹕ many attribute references, stopped at: 0x01010099 07-13 12:31:03.238    1153-1153/com.jehan.sportstutorials w/resourcetype﹕ many attribute references, stopped at: 0x0101009a 07-13 12:31:03.238    1153-1153/com.jehan.sportstutorials w/resourcetype﹕ many attribute references, stopped at: 0x0101009b 07-13 12:31:03.255    1153-1153/com.jehan.sportstutorials d/androidruntime﹕ shutting down vm 07-13 12:31:03.259    1153-1153/com.jehan.sportstutorials e/androidruntime﹕ fatal exception: main process: com.jehan.sportstutorials, pid: 1153 java.lang.runtimeexception: unable start activity componentinfo{com.jehan.sportstutorials/com.jehan.sportstutorials.basketballtutorial}: android.view.inflateexception: binary xml file line #53: error inflating class button @ android.app.activitythread.performlaunchactivity(activitythread.java:2298) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2360) @ android.app.activitythread.access$800(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1278) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)  caused by: android.view.inflateexception: binary xml file line #53: error inflating class button @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:763) @ android.view.layoutinflater.rinflate(layoutinflater.java:806) @ android.view.layoutinflater.rinflate(layoutinflater.java:809) @ android.view.layoutinflater.rinflate(layoutinflater.java:809) @ android.view.layoutinflater.rinflate(layoutinflater.java:809) @ android.view.layoutinflater.inflate(layoutinflater.java:504) @ android.view.layoutinflater.inflate(layoutinflater.java:414) @ android.view.layoutinflater.inflate(layoutinflater.java:365) @ android.support.v7.app.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:249) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:106) @ com.jehan.sportstutorials.basketballtutorial.oncreate(basketballtutorial.java:18) @ android.app.activity.performcreate(activity.java:5937) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1105) @ android.app.activitythread.performlaunchactivity(activitythread.java:2251) 

    

at android.app.activitythread.handlelaunchactivity(activitythread.java:2360) @ android.app.activitythread.access$800(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1278) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694) caused by: java.lang.runtimeexception: failed resolve attribute @ index 24 @ android.content.res.typedarray.getcolor(typedarray.java:401) @ android.widget.textview.<init>(textview.java:692) @ android.widget.button.<init>(button.java:111) @ android.widget.button.<init>(button.java:107) @ android.support.v7.widget.appcompatbutton.<init>(appcompatbutton.java:63) @ android.support.v7.widget.appcompatbutton.<init>(appcompatbutton.java:59) @ android.support.v7.internal.app.appcompatviewinflater.createview(appcompatviewinflater.java:101) @ android.support.v7.app.appcompatdelegateimplv7.createview(appcompatdelegateimplv7.java:802) @ android.support.v7.app.appcompatdelegateimplv7.oncreateview(appcompatdelegateimplv7.java:832) @ android.support.v4.view.layoutinflatercompathc$factorywrapperhc.oncreateview(layoutinflatercompathc.java:44) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:725) @ android.view.layoutinflater.rinflate(layoutinflater.java:806) @ android.view.layoutinflater.rinflate(layoutinflater.java:809) @ android.view.layoutinflater.rinflate(layoutinflater.java:809) @ android.view.layoutinflater.rinflate(layoutinflater.java:809) @ android.view.layoutinflater.inflate(layoutinflater.java:504) @ android.view.layoutinflater.inflate(layoutinflater.java:414) @ android.view.layoutinflater.inflate(layoutinflater.java:365) @ android.support.v7.app.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:249) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:106) @ com.jehan.sportstutorials.basketballtutorial.oncreate(basketballtutorial.java:18) @ android.app.activity.performcreate(activity.java:5937) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1105) @ android.app.activitythread.performlaunchactivity(activitythread.java:2251) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2360) @ android.app.activitythread.access$800(activitythread.java:144) @ android.app.activitythread$h.handlemessage(activitythread.java:1278) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694) 

please try solve problem quickly, project due in week. in advance!

in android manifest declare activity named basketball_tutorial_home_page here:

<activity     android:name=".basketball_tutorial_home_page"     android:label="basketball tutorials"     android:parentactivityname=".mainactivity"> </activity> 

while didn't specify name of basketball tutorial's activity class is, i'm going assume followed standards , activity class name uppercamelcase (something basketballtutorial), whereas layout xml file snake_case (something basketball_tutorial_home_page.xml).

if case, problem not using right name in manifest. android:name attribute needs refer java class, not layout xml file. attribute should more android:name=".basketballtutorial".

additionally, looks have odd attributes in basketball tutorial xml, may causing error seeing in logcat.

  • you using android:theme="@style/textappearance.appcompat.body2", overriding entire theme buttons. want override text appearance using android:textappearance="@style/textappearance.appcompat.body2". overriding whole theme result in odd attributes
  • android:inputtype isn't needed buttons- since can't input text button, setting input type won't anything.
  • when using android:layout_weight, should set either android:layout_height or android:layout_width 0dp specify whether want width or height stretch.

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -