2

I am writing Android application using DataBinding by referencing https://developer.android.com/topic/libraries/data-binding/index.html.

But while building my project, It is showing an error in generated class as

> '/databinding/DataBinderMapper.java:10: error: constant expression
> required.'

This error is happening in switch statement inside generated class DataBinderMapper.java (This file is an auto generated file for databinding)

Any one knows the reason for this java switch case error happening in Auto generated buld file?

Edits: I found the reason for this issue is, layout reference created in R.java file is not final for this case. For example, in my case layout reference in R.java is

public static int activity_main=0x7f04001c;

Actually it should be

public static final int activity_main=0x7f04001b;

But I don't know the reason for this happened and how to change it to final.

2
  • Did you try a clean build? Commented Sep 13, 2017 at 22:41
  • Yeh, But same error Commented Sep 14, 2017 at 4:33

2 Answers 2

1

Probably your model that you are binding against has final modifiers in its variables.

Sign up to request clarification or add additional context in comments.

Comments

1

This error happens when your project has dependency with library or external plugin apart from application. The reason for this issue is, the ids generated might clash when you have dependency with multiple library/ plugins.

1 Comment

In my case, there were two plugins applied for my project. Removing this corrected the issue. But in my project, I must apply this plugin to work with other dependencies. Do you have any idea to correct this issue without removing these plugins?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.