Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchElementException in Anvil.render() #119

Closed
danhawkes opened this issue Jun 20, 2017 · 3 comments
Closed

NoSuchElementException in Anvil.render() #119

danhawkes opened this issue Jun 20, 2017 · 3 comments

Comments

@danhawkes
Copy link

Running version 0.5.2:

java.util.NoSuchElementException
    at java.util.ArrayDeque.removeFirst(ArrayDeque.java:263)
    at java.util.ArrayDeque.pop(ArrayDeque.java:498)
    at trikita.anvil.Anvil$Mount$Iterator.end(Anvil.java:319)
    at trikita.anvil.Anvil.render(Anvil.java:228)
    at trikita.anvil.Anvil.render(Anvil.java:142)
    at trikita.anvil.BaseDSL$ItemSelectedWrapper.onItemSelected(BaseDSL.java:482)
    at android.widget.AdapterView.fireOnSelected(AdapterView.java:931)
    at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:920)
    at android.widget.AdapterView.-wrap1(AdapterView.java)
    at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:890)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6126)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
@zserge
Copy link
Collaborator

zserge commented Jun 20, 2017

@danhawkes Can you please provide a bit more context? What kind of layout is causing this?

@danhawkes
Copy link
Author

danhawkes commented Jun 20, 2017

It's a two-way bound spinner field, something like this:

<T> void twoWayBoundSpinner(TypedAdapter<T> adapter, @Nullable T item, Action1<T> onChangedListener) {

  spinner(() -> {
      init(() -> {
          adapter(adapter);
          onItemSelected((adapterView, view, i, l) -> onChangedListener.call(adapter.getItem(i)));
      });
      int index = item != null ? adapter.getItems().indexOf(item) : -1;
      selection(index);
  });
}

I believe it's caused by a race condition, as I can select an item from the spinner successfully several times, but occasionally the error occurs. Note all calls to render are happening on the main thread.

@niltonvasques
Copy link

niltonvasques commented Aug 28, 2017

I got the same error here when I use Anvil.render(this) inside my onStateChanged method from a RenderableView with a recycler view.

class CustomView(context: Context : RenderableView(context)) {
  fun onStateChanged(state: AppState) {
    state = state
    Anvil.render(this)
  }

  override fun view() {
       RecyclerViewDSL7.recyclerView {
          init { 
               // setup adapters 
          }
        }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants