i am having problem, failed to instantiate one or more classes.Following classes cannot be instantiate .
android.support.v7.widget.AppCompatTextview
There it is my xml file
<?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="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/iv_comment_owner_display"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/facebook" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tv_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#android:color/black"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text=""
android:textColor="#android:color/black" />
</LinearLayout>
</LinearLayout>
AppCompatTextView was added in appcompat-v7:22.1.0
Please check you appcompat version. You have to update your gradle file with this.
clean/Rebuild project from Android Studio,it might help.
If it doesn't try to invalidate caches and restart android studio.
If you have not done,
Try adding the dependencies in your build.gradle(Module:App)
please check the version according to your app
dependencies {
compile 'com.android.support:design:25.3.1'
}
Try putting this code in your layout
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello world"
android:textSize="18dp"
/>
because i see no AppCompatTextView in your layout.
Related
I am a beginner trying to learn android developement.I try to make a recyclerview using below cardview.But when I try to run It's not working.So,how can I fix it?
The cardview code below:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="10dp"
android:id="#+id/list_layout"
android:background="#color/white"
android:layout_marginBottom="10dp"
>
<LinearLayout
android:layout_width="2000dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ratio_button"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do the work"
android:textSize="20sp"
android:id="#+id/task"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/delete"
android:backgroundTint="#color/red"
android:text="Delete"
android:visibility="invisible"
/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
implementation 'com.android.support:cardview-v7:28.0.0'
After that, Let's try this:
androidx.cardview.widget.CardView
your question is not clear! but after trying your XML file, I believe you're missing material dependencies in your app level Gradle file
implementation 'com.google.android.material:material:1.2.1'
MaterialCardView is part of this library and you should include it in your app's dependencies before using it.
I try to change the button textColor's parameter, but all my efforts below are in vain.
<?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="match_parent"
android:gravity="center_vertical"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:tag="fragment_register">
<TextView
android:id="#+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="#string/title"
android:textColor="#android:color/white"
android:textSize="20sp"/>
<EditText
android:id="#+id/et_first_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#3f3f3f"
android:padding="10dp"
android:ems="17"
android:textColor="#color/colorWhite"
android:hint="#string/hint_enter_password"
android:textColorHint="#696969"/>
<EditText
android:id="#+id/et_first_pass_again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="#3f3f3f"
android:padding="10dp"
android:ems="17"
android:textColor="#color/colorWhite"
android:hint="#string/hint_reenter_password"
android:textColorHint="#696969"/>
<Button
android:id="#+id/reg_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="20dp"
android:background="#494949"
android:text="#string/btn_title_reg"
android:textColor="#color/colorWhite"/>
</LinearLayout>
The color has changed only in Preview Design Layout window, but it doesn't work in launched app.
button.setTextColor(...); It doesn't work as well
Can anybody help me please?
you should use
android:textColor="#FFFFFF"
instead of
tools:textColor="#android:color/white"
or try to set programatically like this
button.setTextColor(ContextCompat.getColor(YourActivity.this,R.color.colorBlack));
Try clear your project before building it
Build -> Clean Project or Build -> Rebuild Project
Sometimes android catch some of the previous build to save build time.
Try this
button.setTextColor(Color.parseColor("#000fff"));
or you can use
button.setTextColor(getResources().getColor(R.color.colorPrimary));
I've not opened this particular project for about 3 months but when I tried to generate a signed .apk file, I get this one error only:
C:\app\src\main\res\layout\fragment_newanswers.xml:57: Error: The id "linearLayout2" is not defined anywhere. [UnknownId]
android:layout_alignTop="#+id/linearLayout2"
Here's my current code in that xml file:
<TextView
android:text="OptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtOptionTitle"
android:textSize="24sp"
android:textAlignment="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtOptionTitle"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="false">
<!--
<TextView
android:text="QuestionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtQuestionTitle"
android:textAlignment="center"
android:textSize="18sp" />
-->
<com.rokonoid.widget.ExpandableTextView
android:id="#+id/txtQuestionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.bozapro.circularsliderrange.CircularSliderRange
android:id="#+id/cirAns"
android:layout_width="wrap_content"
android:layout_height="343dp"
circular:start_angle="270"
circular:end_angle="300"
circular:start_thumb_size="0dp"
android:paddingLeft="75dp"
android:paddingRight="75dp" />
<TextView
android:text="5%"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/linearLayout2"
android:layout_centerHorizontal="true"
android:id="#+id/txtPercent"
android:textAlignment="center"
android:textSize="36sp"
android:layout_marginTop="150dp" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnQnsBack"
android:layout_weight="1" />
<Button
android:text="Next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnQnsNext"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Funny thing is, it worked multiple times previously and I did not make any changes at all. I can also rebuild and clean build it without errors. Oddly, my backup versions which are Identical, generate this ONE same error for my 6 different xml files here:
Error:(5) Error: Suspicious namespace and prefix combination [NamespaceTypo]
It points to this line in each of the 6 files:
xmlns:app="http://schemas.android.com/tools"
My guess is I'm not calling something in the MainActivity (but that would not explain why it has always worked -with fully functioning .apk) Any thoughts?
Thanks heaps!
James
Remove this line
android:layout_alignTop="#+id/linearLayout2"
From
<TextView
android:text="5%"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/linearLayout2"
android:layout_centerHorizontal="true"
android:id="#+id/txtPercent"
android:textAlignment="center"
android:textSize="36sp"
android:layout_marginTop="150dp" />
As i see no layout with id linearLayout2 in your file above. Errors of such kind are not generated in the debug build but in the realease build.
As #Malik Ahhsan said, just remove the android:layout_alignTop="#+id/linearLayout2"
I want to Create a CheckBox, My compile
sdk version is 23,
Target version is 23,
build tool version is 23.0.0,
in gradle I'hv added
compile 'com.android.support:support-v4:23.2.0',
compile 'com.android.support:appcompat-v7:23.2.0'
both and in menifest given the app theme as android:theme="#style/Theme.AppCompat.Light.NoActionBar" and no specific theme to Activity. when I run my code its throwing
InflateException line number #23 at xml file, problem while inflating kind of
Then I decided to convery a simple ChcekBox to android.support.v7.widget.AppCompatCheckBox but on the xml file Preview its showing Rendering Problems The following classes could not be instantiated:
- android.support.v7.widget.AppCompatCheckBox
Exception Details java.lang.ClassNotFoundException: android.support.v4.widget.TintableCompoundButton
and if i try to run it it gives me class file for android.support.v4.widget.TintableCompoundButton not found.
So, Any one faced this issue?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:id="#+id/lnv_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rlv_header"
android:orientation="vertical">
<android.support.v7.widget.AppCompatCheckBox
android:id="#+id/confirmCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:checked="false"
android:gravity="start"
android:text="#string/personal_confirm_text"
android:textColor="#color/black"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/rlv_next"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="40dp"
android:background="#color/crabfx_light_gray"
android:visibility="gone">
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_alignParentTop="true"
android:background="#color/crabfx_green" />
<TextView
android:id="#+id/tv_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:drawablePadding="10dp"
android:drawableRight="#drawable/discloser"
android:gravity="center_vertical"
android:text="#string/lbl_next"
android:textColor="#color/black"
android:textSize="18sp" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:background="#color/crabfx_green" />
</RelativeLayout>
</RelativeLayout>
and below is the theme to Application tag in menifest
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
I know there are a hundred questions here just like mine, but none of them seem to suit my specific problem, so I am asking a new question. Just in case this is a repeat, I'm sorry.
So, I am building an app, and the layout is causing me a few problems.
This is my XML code : (it's not yet complete)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/toosl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:xmlns="http://schemas.android.com/apk/res/android" >
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
The error that I'm getting is in the first line of the code
where it says "error: no resource identifier found for attribute 'xmlns' in package 'android'
I've gone over and over the code, I've tried to refresh/rebuild the project, I tried deleting that particular line, etc.. and nothing seems to solve it.
So, if anyone has some ideas?
Thanks!
Remove
android:xmlns="http://schemas.android.com/apk/res/android"
from your layout,i.e. use your layout as
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/toosl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
Replace it with this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
I found my mistake, it's in the last attribute of my first LinearLayout tag.
I should not have included that line at the bottom.
I removed that line and now its working.
Thank you!
if none of the above worked make sure you add this:
compile 'com.android.support:percent:23.1.1'
to your build.gradle