Error:(3) error: not well-formed (invalid token) - android

I am working on my application, but I ran into an error. I have uploaded all the pictures into the drawable folder.
Error:(3) error: not well-formed (invalid token).
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/Profile"android:title="Profile" android:icon="#drawable/ic_person_black_24dp" />
<item android:id="#+id/TradingHistory"android:title="TradingHistory" android:icon="#drawable/ic_history_black_24dp" />
<item android:id="#+id/News"android:title="News" android:icon="#drawable/ic_view_list_black_24dp" />
</menu>
What does it mean and how can I solve it?

The error means that the 3rd line is not well-formed: you need a (blank space) between android:id value and android:title key.
This is the correct XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/Profile" android:title="Profile" android:icon="#drawable/ic_person_black_24dp" />
<item android:id="#+id/TradingHistory" android:title="TradingHistory" android:icon="#drawable/ic_history_black_24dp" />
<item android:id="#+id/News" android:title="News" android:icon="#drawable/ic_view_list_black_24dp" />
</menu>

Go to code in the toolbar and click on reformat code.

Related

Creating a menu layout in XML android studio

I am getting an unknown class error while creating a menu layout.XMl in android studio. Might someone please help me to solve this issues?
The compiler does not recognize the attribute "item".
<item android:id=”#+id/about”
android:title=”About” />
<item android:id=”#+id/help”
android:title=”Help” />
You need to add a menu before them and put in this directory res/menu/
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/about"
android:icon="#drawable/ic_about"
android:title="about" />
<item android:id="#+id/help"
android:icon="#drawable/ic_ help"
android:title="help"/>
</menu>

Change Android CheckBox icon check/unchecked

I am new at Android. I am trying to change the icon of the CheckBox.
Here is my code, where star_checked and start_unchecked are .png file in my drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="=#drawable/star_checked" android:state_checked="true"/>
<item android:drawable="#drawable/star_unchecked" android:state_checked="false" />
</selector>
I am getting the following error:
C:...\app\src\main\res\drawable\selector_priority.xml:3: AAPT: error: '=#drawable/star_checked' is incompatible with attribute drawable (attr) reference.
Any idea of what the issue could be?
Thanks in advance
It's due to syntax error you are using an extra equal sign in android:drawable="=#drawable/star_checked" this line.
Use this code.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#drawable/star_checked" />
<item android:state_checked="false"
android:drawable="#drawable/star_unchecked" />
</selector>

Android Studio: Bottom Navigation View - AAPT: error: ' ' is incompatible with attribute drawable (attr) reference

I have added BottomNavigationView in my application like.
main.xml
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="56dp"
app:itemBackground="#drawable/nav_bgcolor"
app:itemIconSize="50dp"
app:itemIconTint="#color/nav_item_colors"
app:itemTextColor="#color/nav_item_colors"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/nav_items">
</com.google.android.material.bottomnavigation.BottomNavigationView>
menu/nav_items.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_home"
android:icon="#drawable/home_white"
android:title="#string/nav_home" />
<item
android:id="#+id/nav_market"
android:icon="#drawable/market_white"
android:title="#string/nav_market" />
<item
android:id="#+id/nav_news"
android:icon="#drawable/news_white"
android:title="#string/nav_news" />
<item
android:id="#+id/nav_account"
android:icon="#drawable/account_white"
android:title="#string/nav_account" />
</menu>
drawable/nav_bgcolor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#FF9800" android:state_checked="true" />
<item android:drawable="#FFFFFF" android:state_checked="false" />
</selector>
color/nav_item_colors.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFFFFF" android:state_checked="true"/>
<item android:color="#727272"/>
</selector>
this is the preview in the android studio
https://drive.google.com/file/d/1yICxFcTbSxYpILDtxg75Z4x-2Y1UaPM_/view?usp=sharing
it is actually displaying the design that i want to happen.
there is no error or something but when i run the app there are errors in drawable/nav_bgcolor.xml
C:\Users\[PCNAME]\AndroidStudioProjects\[APPNAME]\app\src\main\res\drawable\nav_bgcolor.xml:3: AAPT: error: '#FF9800' is incompatible with attribute drawable (attr) reference.
C:\Users\[PCNAME]\AndroidStudioProjects\[APPNAME]\app\src\main\res\drawable\nav_bgcolor.xml:4: AAPT: error: '#ffffff' is incompatible with attribute drawable (attr) reference.
the error happened after i added app:itemBackground="#drawable/nav_bgcolor" in the main.xml
I have searched the internet but no luck in getting any solution.
In your selector you are using
<selector>
<item android:drawable="#FF9800" android:state_checked="true" />
You can't use a color (#FF9800) where you should define an android:drawable.
Use
<menu>
<item
android:id="#+id/nav_home"
android:icon="#drawable/icon_add"
android:title="#string/nav_home" />
...
</menu>
where icon_add is a simple drawable.
And in your BottomNavigationView:
<com.google.android.material.bottomnavigation.BottomNavigationView
app:itemIconTint="#color/nav_item_colors"
../>
replace android:drawable with android:color in drawable/nav_bgcolor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FF9800" android:state_checked="true" />
<item android:color="#FFFFFF" android:state_checked="false" />
</selector>

Rendering problems while creating a menu in Android Studio

I wanted to create a simple menu for an app. Here is the XML code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<item android:id="#+id/new_game"
android:icon="#drawable/magnify"
android:title="New Game"
android:showAsAction="ifRoom"
android:layout_height="wrap_content"/>
<item android:id="#+id/help"
android:icon="#drawable/magnify"
android:title="Help" />
</menu>
But when I click on the design Tab, it gives an error saying that
"Rendering Problems
The following classes cannot be found
-item(Fix build path, Edit in XML)
-menu(Fix build path, Edit in XML)"
What should I do?
Thanks in advance
It looks you have some attributes in your menu that aren't valid - they're layout attributes, not menu attributes.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:icon="#drawable/magnify"
android:title="New Game"
android:showAsAction="ifRoom"
/>
<item android:id="#+id/help"
android:icon="#drawable/magnify"
android:title="Help"
android:showAsAction="ifRoom"
/>
</menu>

error with Submenu in XML file

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<item
android:id="#+id/item1"
android:title="Main Menu"
/>
<item
android:id="#+id/takesurvey"
android:title="Take Survey"
/>
<item
android:id="#+id/viewstats"
android:title="View Statistics"
/>
<item
android:id="#+id/changesort"
android:title="Change Sorting Order "
<menu>
<item
android:id="#+id/create_new"
android:title="#string/create_new" />
<item
android:id="#+id/open"
android:title="#string/open" />
</menu>
/>
<item
android:id="#+id/menuexit"
android:title="Exit from program "
/>
</item>
Hello , this seems to be a simple problem.I am trying to create a submenu ( for the change sort option ) in my XML file for android. However , I am geting an error :Element type "item" must be followed by either attribute specifications, ">" or "/>". Any ideas?
Your XML is a mess
You've got this open tag, with no closing tag:
<item >
You then have this, which is a partial tag:
<item
android:id="#+id/changesort"
android:title="Change Sorting Order "
I suggest you reformat your XML to indent every sub-tag, and make sure every tag either ends with /> or a closing tag pair.

Categories

Resources