question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android 'Wrong state class, expecting View State...'

See original GitHub issue

Please, provide the details below:

Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?

Yes

Tell us about the problem

Only in Android, the app crashes when I have 2 different elements (in my case, a MapView which comes from the nativescript-google-maps-sdk plugin, and a ListView) in the same row and column in a Page (A) with a GridLayout, then I navigate to a different Page (B), then I navigate back to A.

Which platform does your issue occur on?

Android, only found on version 4.4.4.

Please provide the following version numbers that your issue occurs with:

Please tell us how to recreate the issue in as much detail as possible.

  1. tns run android using Android 4.4.4 device or emulator.
  2. Tap any list item or tap the Go to detail button.
  3. Navigate back (by pressing the hardware ‘back’ button, or the navigation button).
  4. App crashes. The console outputs nothing, but the ErrorActivity produces this:

An uncaught Exception occurred on “main” thread. java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.AbsListView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view’s id is id/0x2. Make sure other views do not use the same id. at android.view.View.onRestoreInstanceState(View.java:13903)

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

Project is here.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
EricRobertBrewercommented, Feb 17, 2017

I was able to fix this issue (I think) by adding the following:

app/App_Resources/Andorid/values/ids.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="my_list_view" type="id" />
</resources>

map.component.html:

    <ListView row="1" [items]="myItems" (itemTap)="onItemTapped($event)" (loaded)="onListViewLoaded($event)">

map.component.ts:

onListViewLoaded(event) {
    if (event.object.android) {
        event.object.android.setId(org.nativescript.mapview.R.id.my_list_view);
    }
}

The issue could have been caused by this, but I’m not certain:

tns-core-modules/ui/list-view/list-view.android.ts:

public _createNativeView() {
    ...
    if (this._androidViewId < 0) {
        this._androidViewId = android.view.View.generateViewId();
    }
    this._android.setId(this._androidViewId);
    ...
}

So far, I haven’t seen any repercussions from manually setting the id in my project.

Updated project and resolution is here.

0reactions
lock[bot]commented, Aug 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android – Wrong state class, expecting View State but ...
This usually happens when two views of different type have the same id in the same hierarchy. Exactly, there will two different types...
Read more >
Odd error with xamarin forms "Wrong state class, expecting View ...
The full error is: Wrong state class, expecting View State but received class android.widget.ProgressBar$SavedState instead. This usually happens when two ...
Read more >
ViewPager2 is crashing when trying to restore RecyclerView ...
lang.IllegalArgumentException: Wrong state class, expecting View State but received class androidx.recyclerview.widget.RecyclerView$SavedState instead. This ...
Read more >
Wrong state class, expecting View State but ... - CodeAntenna
Wrong state class, expecting View State but received class android.os.Bundle instead. Android 笔记. Caused by: java.lang.IllegalArgumentException: Wrong state ...
Read more >
java.lang.IllegalArgumentException: Wrong state class ... - 简书
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class. 开哥Android开发 关注. IP属地: 北京. 2020.04.20 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found