Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,205,474 members, 7,992,603 topics. Date: Sunday, 03 November 2024 at 11:20 AM |
Nairaland Forum / Science/Technology / Programming / Android Developers Pls Help (1221 Views)
Android Developers, Pls I Need Help / Android Developers Drop Your Published Apps Here / Kotlin For Android Developers By Antonio Leiva" Ebook(pdf). (2) (3) (4)
Android Developers Pls Help by Etinosa1234: 5:13pm On Dec 17, 2020 |
I have a problem with my code.. the app crashes while i want to open it My xml code <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/drawerlayout" tools:context=".MainActivity"> <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.appbar.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar2" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" app:layout_scrollFlags="scroll|enterAlways"/> <com.google.android.material.tabs.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="match_parent"/> <FrameLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/content_frag"/> </com.google.android.material.appbar.AppBarLayout> <androidx.viewpager.widget.ViewPager android:id="@+id/pager" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_width="match_parent" android:layout_height="match_parent" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> <com.google.android.material.navigation.NavigationView android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/nav_view" android:layout_gravity="start" app:menu="@menu/menu_nav" app:headerLayout="@layout/nav_header"/> </androidx.drawerlayout.widget.DrawerLayout> |
Re: Android Developers Pls Help by Etinosa1234: 5:14pm On Dec 17, 2020 |
My logcat error java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hfad.myrevisedlawcoursesapp/com.hfad.myrevisedlawcoursesapp.MainActivity}: android.view.InflateException: Binary XML file line #50: Binary XML file line #50: Error inflating class com.google.android.material.navigation.NavigationView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.view.InflateException: Binary XML file line #50: Binary XML file line #50: Error inflating class com.google.android.material.navigation.NavigationView at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) at com.hfad.myrevisedlawcoursesapp.MainActivity.onCreate(MainActivity.java:31) at android.app.Activity.performCreate(Activity.java:6406) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.view.InflateException: Binary XML file line #50: Error inflating class com.google.android.material.navigation.NavigationView at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) at com.hfad.myrevisedlawcoursesapp.MainActivity.onCreate(MainActivity.java:31) at android.app.Activity.performCreate(Activity.java:6406) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at android.view.LayoutInflater.createView(LayoutInflater.java:619) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) at com.hfad.myrevisedlawcoursesapp.MainActivity.onCreate(MainActivity.java:31) at android.app.Activity.performCreate(Activity.java:6406) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.RuntimeException: Unexpected end of document at androidx.appcompat.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:216) at androidx.appcompat.view.SupportMenuInflater.inflate(SupportMenuInflater.java:129) at com.google.android.material.navigation.NavigationView.inflateMenu(NavigationView.java:367) at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:235) at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:122) |
Re: Android Developers Pls Help by Etinosa1234: 5:16pm On Dec 17, 2020 |
My main activity code... public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { private ShareActionProvider shareActionProvider; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawerlayout); ActionBarDrawerToggle action = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.open_drawer,R.string.close_drawer); drawer.addDrawerListener(action); action.syncState(); SectionPagerAdapter pagerAdapter = new SectionPagerAdapter(getSupportFragmentManager()); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(pagerAdapter); TabLayout tab = (TabLayout) findViewById(R.id.tabs); tab.setupWithViewPager(pager); NavigationView nav = (NavigationView) findViewById(R.id.nav_view); nav.setNavigationItemSelectedListener(this);//register the activity with the navigation view as a listener Fragment fr = new HomeFragment(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.content_frag,fr); ft.commit(); } |
Re: Android Developers Pls Help by Etinosa1234: 5:17pm On Dec 17, 2020 |
Pls help... i have searched stack overflow and no answer works cc: spoilerx parkervero millerules |
Re: Android Developers Pls Help by Millerules(m): 5:36pm On Dec 17, 2020 |
What's on line #50 of your layout XML code? |
Re: Android Developers Pls Help by Etinosa1234: 5:48pm On Dec 17, 2020 |
Millerules: This sir <com.google.android.material.navigation.NavigationView android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/nav_view" android:layout_gravity="start" app:menu="@menu/menu_nav" app:headerLayout="@layout/nav_header"/> Its almost similar to the one I did in my tutorial but my tutorial works but this doesn't |
Re: Android Developers Pls Help by spoilerx: 6:25pm On Dec 17, 2020 |
show the entire xml code |
Re: Android Developers Pls Help by Etinosa1234: 7:11pm On Dec 17, 2020 |
spoilerx: This is it boss... I was just working on the main activity xml and the error occurred Etinosa1234: |
Re: Android Developers Pls Help by hollyfat(m): 7:46pm On Dec 17, 2020 |
Do you have a nav_header.xml in your layout directory? It seems like you are trying to load a file that doesn't exist, hence the crash |
Re: Android Developers Pls Help by Etinosa1234: 7:59pm On Dec 17, 2020 |
hollyfat: Yes.. I created the file already... I've been seeing some possible solutions that entails me using the include tag.. I hope it works tho |
Re: Android Developers Pls Help by nurain150(m): 12:52am On Dec 18, 2020 |
Etinosa1234:Does that class exist |
Re: Android Developers Pls Help by nurain150(m): 12:53am On Dec 18, 2020 |
Delete the xml snippets |
Re: Android Developers Pls Help by Etinosa1234: 1:54am On Dec 18, 2020 |
nurain150: Yes |
Re: Android Developers Pls Help by Etinosa1234: 2:05am On Dec 18, 2020 |
I tested everything thing in the code and apparently the problem is the bolded Etinosa1234: Pls spoilerx, millerules apart from app: menu, what other ways can one use to add options to the navigation view Thanks |
Re: Android Developers Pls Help by MikeMicheal(m): 6:43am On Dec 18, 2020 |
DONT BE A LAZY MAN! DELETE EVERYTHING AND START ALLOVER! 1 Like |
Re: Android Developers Pls Help by Millerules(m): 9:35am On Dec 18, 2020 |
Let's see the menu file you created. And also leave the tutorial for few hours, go learn the AndroidX Navigation Library in detail then come back to your code. Try and use the library's core functions they make things easier. In addition try and learn about View Binding (or better the Data Binding class) it makes your code cleaner. This may be much at first, but if you going to learn, learn the right and modern way bcs lots of updates these days. Etinosa1234: 2 Likes |
Re: Android Developers Pls Help by Etinosa1234: 10:45am On Dec 18, 2020 |
Millerules:this is the menu file <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/nav_home" android:checked="true" android:icon="@android:drawable/ic_menu_info_details" android:title="@string/home"/> <item android:id="@+id/nav_practice" android:icon="@android:drawable/ic_menu_edit" android:title="@string/practice"/> <item android:id="@+id/nav_bookmarks" android:title="@string/bookmark" android:icon="@android:drawable/ic_menu_save"/> </group> <item android:title="@string/prefer"/> <menu> <item android:id="@+id/nav_settings" android:title="@string/settings" android:icon="@android:drawable/ic_menu_help"/> <item android:id="@+id/nav_rate" android:title="@string/rate"/> </menu> </menu> also its my personal project that i am building... I am through with the first page already.. just stuck with the options Thanks boss 1 Like |
Re: Android Developers Pls Help by dirtydaya(m): 11:27am On Dec 18, 2020 |
hello it's spoilerx, my account is blocked from commenting here , am not sure why. go to the style file , change your theme parent from an Appcompat theme to a material component theme. I put the full details last night, not sure y I got banned for it. 2 Likes |
Re: Android Developers Pls Help by dirtydaya(m): 11:27am On Dec 18, 2020 |
MikeMicheal: This is terrible advice |
Re: Android Developers Pls Help by Millerules(m): 12:11pm On Dec 18, 2020 |
Etinosa1234 I think this should be the solution. Nice one bro �� dirtydaya: |
Re: Android Developers Pls Help by parkervero(m): 12:17pm On Dec 18, 2020 |
Etinosa1234: Let me see the fragment class you want to inflate in the main activity. From the fragment, it seems like you didn't properly handle the new instance() method. Better still, did you add design or material design library to your build? |
Re: Android Developers Pls Help by Etinosa1234: 12:28pm On Dec 18, 2020 |
dirtydaya: I have already changed it and it's still the same error... I'll have to look for another way to add menu options to the Navigation view ... Thanks Millerules |
Re: Android Developers Pls Help by Etinosa1234: 12:29pm On Dec 18, 2020 |
parkervero: I've not done anything to the fragment yet |
Re: Android Developers Pls Help by dirtydaya(m): 12:38pm On Dec 18, 2020 |
Etinosa1234: please share the content of your styles xml file |
Re: Android Developers Pls Help by Etinosa1234: 12:55pm On Dec 18, 2020 |
dirtydaya: This is it sir <resources xmlns:tools="http://schemas.android.com/tools"> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <!-- Primary brand color. --> <item name="colorPrimary">@color/purple_200</item> <item name="colorPrimaryVariant">@color/purple_700</item> <item name="colorOnPrimary">@color/white</item> <!-- Secondary brand color. --> <item name="colorSecondary">@color/teal_200</item> <item name="colorSecondaryVariant">@color/teal_700</item> <item name="colorOnSecondary">@color/black</item> <!-- Status bar color. --> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <!-- Customize your theme here. --> </style> </resources> |
Re: Android Developers Pls Help by parkervero(m): 1:07pm On Dec 18, 2020 |
Etinosa1234: Check the build to see if Androidx.material library is added, and if it does not, add it. |
Re: Android Developers Pls Help by etoluw: 1:44pm On Dec 18, 2020 |
Re: Android Developers Pls Help by etoluw: 1:49pm On Dec 18, 2020 |
Etinosa1234: the error is an inflateException which means it has to do with the layout xml
I think this is where the error is change it to "@style/ToolbarTheme" then edit the styles.xml resource <style name="ToolbarTheme" parent="ThemeOverlay.MaterialComonents.Dark.ActionBar"></> |
Re: Android Developers Pls Help by dirtydaya(m): 4:27pm On Dec 18, 2020 |
I wish you could share this project on GitHub, so I can look through it properly or do you have team viewer ? so I can work on your project remotely And android studio doesn't give any error for the layout xml file |
Re: Android Developers Pls Help by Etinosa1234: 5:41pm On Dec 18, 2020 |
dirtydaya: I tried opening a GitHub account but it didn't work.. Besides I used another means to add options to the navigation viewer using Menu menu = nav.getMenu() SubMenu men = menu.add("String".) men.add("Another String".); but it's not responding to clicks |
Want To Learn Data Analysis / Learn HTML - HTML Training & Tutorials For Complete Beginners / ?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64 |