0
votes

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

5
can you post your java code along with imports, It seems like you might be missing them.karan
@KaranMer UpdatedKishorsinh Chudasama
What your gradle version and how you add this dependency in your app level gradle file? There is something wrong with that library. you can use this one github.com/jd-alexander/android-flat-buttonShailesh
try adding a new color value in color xml with name as fbutton_default_color and also add fbutton_default_shadow_colorPavneet_Singh

5 Answers

0
votes

May be you didn't add following dependency in app gradle : compile 'info.hoang8f:fbutton:1.0.5'

0
votes

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" />
0
votes

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

0
votes

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

.

0
votes

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.