1

My project in Android Studio is running and executing but whenever I click on activity_login.xml I can't see any element but just a basic layout, I couldn't see the text input or even button.

Here is the error that I get when I preview my layout:

Rendering Problems The following classes could not be instantiated:
- android.support.v7.widget.AppCompatTextView 

Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.example.myapp.mealplanner.LoginActivity">

<include
    android:id="@+id/login_toolbar"
    layout="@layout/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:paddingEnd="16dp"
    android:paddingStart="16dp"
    android:text="@string/login_statement"
    android:textColor="@color/black"
    android:textSize="18sp"
    android:textStyle="bold" />


<android.support.design.widget.TextInputLayout
    android:id="@+id/login_email"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:hint="@string/enter_your_email"
        android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/login_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:hint="@string/enter_your_password"
        android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>


<Button
    android:id="@+id/login_login_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="15dp"
    android:text="@string/login" />

</LinearLayout>

Here is my app gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
    applicationId "com.example.myapp.mealplanner"
    minSdkVersion 19
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
productFlavors {
    }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
//compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:appcompat-v7:26.+'
//compile 'com.android.support:design:26.+'
compile 'com.android.support:design:26.1.0'
compile 'com.google.firebase:firebase-database:11.4.2'
compile 'com.google.firebase:firebase-core:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.google.firebase:firebase-storage:11.4.2'
compile 'com.firebaseui:firebase-ui-database:3.0.0'
compile 'com.firebaseui:firebase-ui-auth:3.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
//compile 'com.android.support:recyclerview-v7:26.1.0'
//compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.4.2'
compile 'com.google.firebase:firebase-core:11.4.2'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
}
apply plugin: 'com.google.gms.google-services'

I guess the problem can be came from Gradle, I have tried to update my Android Studio, Invalidate Cache. However, none of these works. Theme can be problem but I want to use "No Action Bar" Theme. This is my style.xml file:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" 
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

How can I solve the issue?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
hjhk19
  • 39
  • 1
  • 2
  • 7
  • Possible duplicate of [The following classes could not be instantiated: - android.support.v7.widget.Toolbar](https://stackoverflow.com/questions/26575815/the-following-classes-could-not-be-instantiated-android-support-v7-widget-too) – Mochammad Irsyad Oct 18 '17 at 02:40

2 Answers2

0

It is a minor bug in appcompat v26.

In your styles.xml use Base.Theme.AppCompat instead of Theme.AppCompat as the parent theme.

Apparently there is no such theme for NoActionBar in Base. So use a theme as below:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
  • Base.Theme.AppCompat will solve the issues. However, I want to use No Action Bar, which Base.Theme.AppCompat.NoActionBar is not exist. – hjhk19 Oct 18 '17 at 03:02
  • When I try to put it in the Android Studio, It said: can not resolve Base.Theme.AppCompat.Light.NoActionBar. with the red color – hjhk19 Oct 18 '17 at 03:12
0

Apparently, the problem was the Theme. After I tried to change it to:

<style name="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style

Which is the new theme with disable Action Bar option. It worked. I found this under the How do I style appcompat-v7 Toolbar like Theme.AppCompat.Light.DarkActionBar?

hjhk19
  • 39
  • 1
  • 2
  • 7