How do I get my app to run with navigation view? - android

I am trying to add a navigational menu to my app and I am following the Create a navigation drawer at https://developer.android.com/training/implementing-navigation/nav-drawer
When i try to run the app I get as far as seeing a blank white screen than the app closes.
I don't have any errors in my code or when it gets compiled, it just wont load the main page.
package com.example.troubleshootonly.americanharvest
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.troubleshootonly.americanharvest.R.layout.activity_main
var pass: String = ""
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(activity_main)
//these create buttons with buttF being the name of the button
//everything in brackets is the function, which starts activity
/*
buttF.setOnClickListener {
startActivity(Intent(this, Activity2::class.java))
}
buttE.setOnClickListener {
startActivity(Intent(this, Activity3::class.java))
}
buttC.setOnClickListener {
startActivity(Intent(this, Activity4::class.java))
}
*/
/* admin stuff
admin.setOnClickListener {
val tempPw = adminPass.text.trim().toString()
if (tempPw.equals(pass, true)) {
startActivity(Intent(this, adminPage::class.java))
} else {
startActivity(Intent(this, MainActivity::class.java))
}
}
*/
}
}
this is my main activity page
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/mainPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true" tools:openDrawer="start"
android:visibility="visible">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ahlogo" android:visibility="visible"/>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_gravity="start"
android:layout_height="wrap_content" android:id="#+id/menuMain"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="44dp" android:layout_marginRight="44dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0"
app:menu="#menu/drawer_view" android:fitsSystemWindows="false">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
logcat:
--------- beginning of crash
2019-01-12 20:20:45.486 13641-13641/com.example.troubleshootonly.americanharvest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.troubleshootonly.americanharvest, PID: 13641
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.troubleshootonly.americanharvest/com.example.troubleshootonly.americanharvest.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
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 android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.troubleshootonly.americanharvest.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c0000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2155)
at android.content.res.Resources.getLayout(Resources.java:1155)
2019-01-12 20:20:45.487 13641-13641/com.example.troubleshootonly.americanharvest E/AndroidRuntime: at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:125)
at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:264)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:189)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:104)
... 28 more
--------- beginning of system

The code is unclear and also some line of code is missing. Like i cant see the start of Drawer layout.
Also you have not Declared the Drawer Layout and NavigationView in your MainActivity.java, As you have not provided code clearly. Hence I have provided you the main files needed to implement navigation drawer. Just copy paste as it is (expect package name :p).
MainActivity.java (I named it navBar.java)
public class navBar extends AppCompatActivity {
private DrawerLayout drawerLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nav_bar);
drawerLayout = findViewById(R.id.drawer_layout_tab_bar);
NavigationView navigationView = findViewById(R.id.navigation_view_tab_bar_activity);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
// set item as selected to persist highlight
menuItem.setChecked(true);
// close drawer when item is tapped
drawerLayout.closeDrawers();
// Add code here to update the UI based on the item selected
// For example, swap UI fragments here
return true;
}
});
}
}
activity_main.xml (I named it activity_nav_bar)
public class navBar extends AppCompatActivity {
private DrawerLayout drawerLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nav_bar);
drawerLayout = findViewById(R.id.drawer_layout_tab_bar);
NavigationView navigationView = findViewById(R.id.navigation_view_tab_bar_activity);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
// set item as selected to persist highlight
menuItem.setChecked(true);
// close drawer when item is tapped
drawerLayout.closeDrawers();
// Add code here to update the UI based on the item selected
// For example, swap UI fragments here
return true;
}
});
}
}
Add these to your app gradle file (If not present)
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
Use this as menu file to show content in nav_bar.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_profile"
android:icon="#drawable/ic_baseline_account_circle_24px"
android:title="#string/profile" />
<item
android:id="#+id/nav_templates"
android:icon="#drawable/ic_baseline_create_24px"
android:title="#string/temp" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_baseline_exit_to_app_24px"
android:title="#string/log_out" />
</group>
</menu>
Hope this helps.

Related

How do i fix this error ? android.view.InflateException: Binary XML file line #11

Hello all my activity wont start for some reason and Im having trouble figuring it out, its a simple app it starts and shows this layout, but i keep getting errors everytime i start it and i dont know why
xml code
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".HomeActivity"
tools:showIn="#layout/app_bar_home">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back">
<ImageView
android:id="#+id/btnTraining"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:src="#drawable/play" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal">
<info.hoang8f.widget.FButton
android:id="#+id/btnExercises"
android:text="Exercises"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:textColor="#color/white"
app:buttonColor="#color/colorPrimary"
app:shadowColor="#color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="2dp"
app:shadowHeight="2dp" />
<info.hoang8f.widget.FButton
android:id="#+id/btnSetting"
android:text="Setting"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:textColor="#color/white"
app:buttonColor="#color/colorPrimary"
app:shadowColor="#color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="2dp"
app:shadowHeight="2dp" />
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="#+id/btnCalender"
android:text="Calender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:textColor="#color/white"
app:buttonColor="#color/colorPrimary"
app:shadowColor="#color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="0dp"
app:shadowHeight="2dp" />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Java code
package com.example.kishorsinh.yogaapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class HomeActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
Button btnExercises,btnSetting,btnCalender;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
btnExercises =(Button)findViewById(R.id.btnExercises);
btnExercises.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this,ListExercises.class);
startActivity(intent);
}
});
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_activity, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
//if (id == R.id.action_settings) {
//return true;
// }
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_instructions) {
// Handle the camera action
} else if (id == R.id.nav_benefits) {
}else if (id == R.id.nav_share) {
} else if (id == R.id.nav_about) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.kishorsinh.yogaapp"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Library
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'info.hoang8f:fbutton:1.0.5'
}
Gradle version
3.1.3
Error
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.kishorsinh.yogaapp/com.example.kishorsinh.yogaapp.HomeActivity}:
android.view.InflateException: Binary XML file line #11: Binary XML
file line #36: Error inflating class info.hoang8f.widget.FButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #36: Error inflating class info.hoang8f.widget.FButton
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class info.hoang8f.widget.FButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1011)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1011)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.kishorsinh.yogaapp.HomeActivity.onCreate(HomeActivity.java:26)
at android.app.Activity.performCreate(Activity.java:6956)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
at android.content.res.TypedArray.getColor(TypedArray.java:480)
at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
at info.hoang8f.widget.FButton.(FButton.java:52)
... 37 more
May be you didn't add following dependency in app gradle :
compile 'info.hoang8f:fbutton:1.0.5'
remove this
implementation 'info.hoang8f:fbutton:1.0.5'
<info.hoang8f.widget.FButton
android:id="#+id/btnCalender"
android:text="Calender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:textColor="#color/white"
app:buttonColor="#color/colorPrimary"
app:shadowColor="#color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="0dp"
app:shadowHeight="2dp" />
May Be you're having problem in your color.xml file
From your error log
Caused by: java.lang.UnsupportedOperationException: Can't convert
value at index 1 to color: type=0x5 at
android.content.res.TypedArray.getColor(TypedArray.java:480) at
At first , It seems like your color value is wrong
i solve this errors by changing libraries
implementation 'info.hoang8f:fbutton:1.0.5' to
implementation 'com.github.jd-alexander:android-flat-button:v1.1'
and make changes in xml files
app:buttonColor="#color/colorPrimary"
to app:fButtonColor="#color/colorPrimary" to all projects by
buttonColor
to
fButtonColor
.
I had also a similar error when I deleted an old fragment layout XML file and added a new fragment file but I didn't update the activity_main.xml. The problem was in android: name property of fragment and I updated that and it worked out.

Error inflating class fragment, cannot start the activity, My app starts and stops abruptly

I am new to android, I have been following the lessons by edx. But when I tried to run the code, I am getting the stack trace as,
12 11:47:44.436 2965-2965/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lambda.momaer, PID: 2965
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lambda.momaer/com.example.lambda.momaer.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2730)
at android.app.ActivityThread.access$800(ActivityThread.java:185)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:923)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:808)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:923)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:808)
at android.view.LayoutInflater.inflate(LayoutInflater.java:510)
at android.view.LayoutInflater.inflate(LayoutInflater.java:420)
at android.view.LayoutInflater.inflate(LayoutInflater.java:371)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.deepakchethan.moviemanager.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6117)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2613)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2730) 
at android.app.ActivityThread.access$800(ActivityThread.java:185) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5847) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
Caused by: java.lang.NullPointerException
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:464)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3404)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:739)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:812) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:923) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:808) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:923) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:808) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:510) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:420) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:371) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.deepakchethan.moviemanager.MainActivity.onCreate(MainActivity.java:25) 
at android.app.Activity.performCreate(Activity.java:6117) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2613) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2730) 
at android.app.ActivityThread.access$800(ActivityThread.java:185) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5847) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
And the Main activity looks like,
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
Class frag;
if (id == R.id.nav_upComing) {
frag=upComingFragment.class;
showFragment(frag);
} else if (id == R.id.nav_nowPlaying) {
frag=nowPlayingFragment.class;
showFragment(frag);
} else if (id == R.id.nav_close) {
finish();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void showFragment(Class frag) {
Fragment fragment=null;
try {
fragment= (Fragment) frag.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
FragmentManager fm=getSupportFragmentManager();
fm.beginTransaction().replace(R.id.flip,fragment,null).commit();
}
}
My xml files looks like this,
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.deepakchethan.moviemanager.MainActivity"
tools:showIn="#layout/app_bar_main">
<fragment
android:id="#+id/flip"
android:layout_width="match_parent"
android:layout_height="match_parent"></fragment>
</android.support.constraint.ConstraintLayout>
I searched and found no solution on stackoverflow. I just thought i will ask myself. Please help me.
This question has already been answered several times, you cannot change a statically created fragment. So change the tag from fragment to FrameLayout in your xml file. It should work fine.
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.deepakchethan.moviemanager.MainActivity"
tools:showIn="#layout/app_bar_main">
<FrameLayout
android:id="#+id/flip"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</android.support.constraint.ConstraintLayout>

Go from activity to fragment and to another fragment

I am new at android and I can't seem to understand one thing.
I am trying to jump from MainActivity to MainFragment. In it there is a button. When onClickListener is triggered, it should jump to another ResultFragment. But I can't seem to understand how to do it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.something.MainActivity">
<fragment
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_main" />
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment = new MainFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, null).commit();
}
}
public class MainFragment extends Fragment {
public MainFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
Button button = (Button) rootView.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "iskviesta", Toast.LENGTH_SHORT).show();
getFragmentManager().beginTransaction().replace(R.id.container, new ResultFragment()).commit();
}
});
return rootView;
}
}
public class ResultFragment extends Fragment {
public ResultFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_result, container, false);
return rootView;
}
}
What am I doing wrong? The app doesn't even start.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.something, PID: 14245
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.something/com.something.MainActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class fragment
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: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
Caused by: java.lang.NullPointerException
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:459)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3321)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.something.MainActivity.onCreate(MainActivity.java:12)
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)
In your xml use a FrameLayout instead of Fragment:
<FrameLayout
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Using a fragment tag will not allow you to do fragment transactions on the view.
You should use getSupportFragmentManager() instead of getFragmentManager in your listener :
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "iskviesta", Toast.LENGTH_SHORT).show();
getSupportFragmentManager().beginTransaction().replace(R.id.container, new ResultFragment()).commit();
}
});
And remplace your fragment layout with a FrameLayout in your xml code.
Hope this helps.
Sorry for my english.

Data Binding in an Activity with a MapFragment

I would like to use Data Binding Library in one of my projects but I am getting an error in the activity who has a MapFragment. Not using data binding librery the code works perfectly
My xml main_activity file:
<layout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.project.activities.MainActivity" />
</RelativeLayout>
</layout>
And the baseActivity related
public abstract class BaseActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private Toolbar toolbar;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, getContentView());
setContentView(getContentView());//Crashes
getPresenter();
configureToolbar();
Log.d(Constans.LOG_TAG,"On create");
}
private void configureToolbar() {
toolbar = binding.myToolbar;
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
protected void onStop() {
super.onStop();
Log.d(Constans.LOG_TAG,"On Stop");
}
#Override
protected void onResume() {
super.onResume();
Log.d(Constans.LOG_TAG,"On resume");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
protected abstract int getContentView();
protected abstract void getPresenter();
}
And the error I get is :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.activities.MainActivity}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
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 #18: Binary XML file line #18: Error inflating class fragment
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.project.activities.MainActivity.BaseActivity.onCreate(BaseActivity.java:21)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5461) 
at java.lang.reflect.Method.invoke(Native Method)
The error itself is on onCreate(Bundle savedInstanceState) method on
setContentView(getContentView());
What I am doing wrong?
remove this line
setContentView(getContentView());//Crashes
and pass your layout resource to
binding = DataBindingUtil.setContentView(this, R.id.main_activity);
Your app crashes because you are trying to get the ContentView while it's null.
You will always need to call setContentView in your before trying to call getContentView.
Try:
setContentView(R.id.YOUR_LAYOUT_ID);//Crashes
binding = DataBindingUtil.setContentView(this, getContentView());

Android navigation drawer crashes

I am trying to add a navigation drawer on my app following this google tutorial:
https://codelabs.developers.google.com/codelabs/material-design-style/index.html?index=..%2F..%2Findex#5
I've managed to add FAB button but when I add the navigation drawer my app crashes on my tablet. Why does it crash? This is the second tutorial I try and it also makes it crash.
public class Agenda extends AppCompatActivity
{
private Toolbar toolbar;
private FloatingActionButton fab;
private DrawerLayout mDrawerLayout;
private NavigationView navigationView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
// Create Navigation drawer and inflate layout
navigationView = (NavigationView) findViewById(R.id.nav_view);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
// Adding menu icon to Toolbar
ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
// Set behavior of Navigation drawer
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
// This method will trigger on item Click of navigation menu
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
// Set item in checked state
menuItem.setChecked(true);
// TODO: handle navigation
// Closing drawer on item click
mDrawerLayout.closeDrawers();
return true;
}
});
mDrawerLayout.openDrawer(GravityCompat.START);
}
#Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu,menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == android.R.id.home) {
mDrawerLayout.openDrawer(GravityCompat.START);
}
return super.onOptionsItemSelected(item);
}
}
main 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/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="#drawable/ic_delete_black" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/header"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
drawer xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:icon="#drawable/ic_drafts_black"
android:tint="#color/button_grey"
android:title="One" />
<item
android:icon="#drawable/ic_drafts_black"
android:tint="#color/button_grey"
android:title="Two" />
<item
android:icon="#drawable/ic_drafts_black"
android:tint="#color/button_grey"
android:title="Three" />
</group>
</menu>
header xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/navheader_height"
android:background="?attr/colorPrimaryDark"
android:orientation="vertical"
android:padding="#dimen/md_keylines">
</LinearLayout>
EDIT: This is the crash log:
[ 03-13 19:34:24.460 5057: 5057 E/AndroidRuntime ]
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cohen.agenda/com.cohen.agenda.Agenda}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.cohen.agenda.Agenda.onCreate(Agenda.java:26)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:593)
... 22 more
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.support.design.internal.NavigationMenuPresenter.getMenuView(NavigationMenuPresenter.java:96)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:166)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
... 25 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.internal.NavigationMenuView" on path: /data/app/com.cohen.agenda-15.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:558)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
... 30 more

Categories

Resources