Data binding “error: cannot find symbol class Models”
First, I need to acknowledge the clearly very similar but not duplicate issue here. None of the proposed solutions in that thread work.
My application file structure is as follows:
app
java
[mydomain].[myapplication]
Models
DataModel.java
MainActivity.java
res
layout
activity_main.xml
content_main.xml
my_inner_layout.xml
My app build.gradle contains
dataBinding {
enabled = true
}
In MainActivity.java I have
import [mydomain].[myapplication].Models.DataModel;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemsSelectedListener {
DataModel dataModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
... <other layout creation template code> ...
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
binding.setValues(dataModel);
}
<navigation and auto-generated methods>
}
My my_inner_layout.xml contains
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
>
<TextView
android:id="@+id/intro_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@{values.valueOne}"/>
<TextView
android:id="@+id/buying_recommendation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/intro_text"
app:layout_constraintTop_toBottomOf="@id/intro_text"
android:text="@{values.valueTwo}"/>
</android.support.constraint.ConstraintLayout>
</layout>
I am passing bind:values="@{values}" through from activity_main to its included app_bar_main to its content_main to its my_inner_layout with that same <data> value in each. Android Studio is telling me "namespace 'bind' is not bound".
If I try to run this, I get "Compilation failed; see the compiler error output for details." Looking in the build output, I see:

In text, the errors are variously error: cannot find symbol class Models and error: package Models does not exist
If I move DataModel.java out of the Models package and directly in to [mydomain].[myapplication], then I get a different result. It does build and run in the emulator, but with much of the layout information failing to appear. No hamburger menu in the top left, no title text in the header, and no settings button in the top right values previously automatically included by the autogenerated code in Android Studio. I am unable to set the title in code using setTitle, either.
Swiping from the left does bring in the navigation drawer however.
I have tried invalidating caches and restarting, cleaning, rebuilding both with the model file in Models and separately.
What I want, chiefly, is to be able to use the project structure I want. To put my models classes in a models sub-package. Once that is complete, I want to make sure the full layout information comes through, including the hamburger menu icon, settings icon, and title. How can I achieve this?
java
add a comment |
First, I need to acknowledge the clearly very similar but not duplicate issue here. None of the proposed solutions in that thread work.
My application file structure is as follows:
app
java
[mydomain].[myapplication]
Models
DataModel.java
MainActivity.java
res
layout
activity_main.xml
content_main.xml
my_inner_layout.xml
My app build.gradle contains
dataBinding {
enabled = true
}
In MainActivity.java I have
import [mydomain].[myapplication].Models.DataModel;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemsSelectedListener {
DataModel dataModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
... <other layout creation template code> ...
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
binding.setValues(dataModel);
}
<navigation and auto-generated methods>
}
My my_inner_layout.xml contains
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
>
<TextView
android:id="@+id/intro_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@{values.valueOne}"/>
<TextView
android:id="@+id/buying_recommendation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/intro_text"
app:layout_constraintTop_toBottomOf="@id/intro_text"
android:text="@{values.valueTwo}"/>
</android.support.constraint.ConstraintLayout>
</layout>
I am passing bind:values="@{values}" through from activity_main to its included app_bar_main to its content_main to its my_inner_layout with that same <data> value in each. Android Studio is telling me "namespace 'bind' is not bound".
If I try to run this, I get "Compilation failed; see the compiler error output for details." Looking in the build output, I see:

In text, the errors are variously error: cannot find symbol class Models and error: package Models does not exist
If I move DataModel.java out of the Models package and directly in to [mydomain].[myapplication], then I get a different result. It does build and run in the emulator, but with much of the layout information failing to appear. No hamburger menu in the top left, no title text in the header, and no settings button in the top right values previously automatically included by the autogenerated code in Android Studio. I am unable to set the title in code using setTitle, either.
Swiping from the left does bring in the navigation drawer however.
I have tried invalidating caches and restarting, cleaning, rebuilding both with the model file in Models and separately.
What I want, chiefly, is to be able to use the project structure I want. To put my models classes in a models sub-package. Once that is complete, I want to make sure the full layout information comes through, including the hamburger menu icon, settings icon, and title. How can I achieve this?
java
add a comment |
First, I need to acknowledge the clearly very similar but not duplicate issue here. None of the proposed solutions in that thread work.
My application file structure is as follows:
app
java
[mydomain].[myapplication]
Models
DataModel.java
MainActivity.java
res
layout
activity_main.xml
content_main.xml
my_inner_layout.xml
My app build.gradle contains
dataBinding {
enabled = true
}
In MainActivity.java I have
import [mydomain].[myapplication].Models.DataModel;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemsSelectedListener {
DataModel dataModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
... <other layout creation template code> ...
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
binding.setValues(dataModel);
}
<navigation and auto-generated methods>
}
My my_inner_layout.xml contains
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
>
<TextView
android:id="@+id/intro_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@{values.valueOne}"/>
<TextView
android:id="@+id/buying_recommendation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/intro_text"
app:layout_constraintTop_toBottomOf="@id/intro_text"
android:text="@{values.valueTwo}"/>
</android.support.constraint.ConstraintLayout>
</layout>
I am passing bind:values="@{values}" through from activity_main to its included app_bar_main to its content_main to its my_inner_layout with that same <data> value in each. Android Studio is telling me "namespace 'bind' is not bound".
If I try to run this, I get "Compilation failed; see the compiler error output for details." Looking in the build output, I see:

In text, the errors are variously error: cannot find symbol class Models and error: package Models does not exist
If I move DataModel.java out of the Models package and directly in to [mydomain].[myapplication], then I get a different result. It does build and run in the emulator, but with much of the layout information failing to appear. No hamburger menu in the top left, no title text in the header, and no settings button in the top right values previously automatically included by the autogenerated code in Android Studio. I am unable to set the title in code using setTitle, either.
Swiping from the left does bring in the navigation drawer however.
I have tried invalidating caches and restarting, cleaning, rebuilding both with the model file in Models and separately.
What I want, chiefly, is to be able to use the project structure I want. To put my models classes in a models sub-package. Once that is complete, I want to make sure the full layout information comes through, including the hamburger menu icon, settings icon, and title. How can I achieve this?
java
First, I need to acknowledge the clearly very similar but not duplicate issue here. None of the proposed solutions in that thread work.
My application file structure is as follows:
app
java
[mydomain].[myapplication]
Models
DataModel.java
MainActivity.java
res
layout
activity_main.xml
content_main.xml
my_inner_layout.xml
My app build.gradle contains
dataBinding {
enabled = true
}
In MainActivity.java I have
import [mydomain].[myapplication].Models.DataModel;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemsSelectedListener {
DataModel dataModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
... <other layout creation template code> ...
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
binding.setValues(dataModel);
}
<navigation and auto-generated methods>
}
My my_inner_layout.xml contains
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
>
<TextView
android:id="@+id/intro_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@{values.valueOne}"/>
<TextView
android:id="@+id/buying_recommendation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/intro_text"
app:layout_constraintTop_toBottomOf="@id/intro_text"
android:text="@{values.valueTwo}"/>
</android.support.constraint.ConstraintLayout>
</layout>
I am passing bind:values="@{values}" through from activity_main to its included app_bar_main to its content_main to its my_inner_layout with that same <data> value in each. Android Studio is telling me "namespace 'bind' is not bound".
If I try to run this, I get "Compilation failed; see the compiler error output for details." Looking in the build output, I see:

In text, the errors are variously error: cannot find symbol class Models and error: package Models does not exist
If I move DataModel.java out of the Models package and directly in to [mydomain].[myapplication], then I get a different result. It does build and run in the emulator, but with much of the layout information failing to appear. No hamburger menu in the top left, no title text in the header, and no settings button in the top right values previously automatically included by the autogenerated code in Android Studio. I am unable to set the title in code using setTitle, either.
Swiping from the left does bring in the navigation drawer however.
I have tried invalidating caches and restarting, cleaning, rebuilding both with the model file in Models and separately.
What I want, chiefly, is to be able to use the project structure I want. To put my models classes in a models sub-package. Once that is complete, I want to make sure the full layout information comes through, including the hamburger menu icon, settings icon, and title. How can I achieve this?
java
java
edited Nov 19 '18 at 11:17
Jim Cullen
asked Nov 15 '18 at 12:23
Jim CullenJim Cullen
85
85
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
In your XML file you have to add full path of Model Class as below,
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
Issue: you have not mentioned full path of model in XML. Forgot to write .Model
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
add a comment |
First try to remove redurant setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
Second add to end of "onCreate" function
binding.included.setValues(dataModel);
binding.executePendingBindings();
if you use include than you may add to your include id for example
<include
android:id="@+id/included"
layout="@layout/content_main"
app:values="@{DataModel}"/>
and use
binding.included.setValues(dataModel);
research about using databinding with included layouts
add a comment |
Okay, I realised where the "class Models does not exist" thing comes from. I don't know whether to blame my own stupidity or the stupidly nitpicky way this binding is implemented on Android. The package needed to be called models with a lower case "m", not Models. The binding auto-name-conversion thing must have thought Models was a class, not a package.
To fix the layout, the onCreate method had to be changed to
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
cycleInformationBinding.setRecommendation(dataModel);
// set toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Drawer layout setting
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Specifically, things had to happen in the order:
setContentViewto the main activity- Set up the data model binding
- Layout concerns like drawer and toolbar.
Any other order would cause either the model binding to fail or the toolbar to not display correctly.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319443%2fdata-binding-error-cannot-find-symbol-class-models%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your XML file you have to add full path of Model Class as below,
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
Issue: you have not mentioned full path of model in XML. Forgot to write .Model
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
add a comment |
In your XML file you have to add full path of Model Class as below,
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
Issue: you have not mentioned full path of model in XML. Forgot to write .Model
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
add a comment |
In your XML file you have to add full path of Model Class as below,
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
Issue: you have not mentioned full path of model in XML. Forgot to write .Model
In your XML file you have to add full path of Model Class as below,
<data>
<variable
name="values"
type="[mydomain].[myapplication].Models.DataModel" />
</data>
Issue: you have not mentioned full path of model in XML. Forgot to write .Model
answered Nov 15 '18 at 12:30
Sagar ZalaSagar Zala
2,37441337
2,37441337
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
add a comment |
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
Ah whoops. That wasn't a problem that exists in my code. It was only a problem with the way I shared my code here. My code did indeed have the .Models.DataModel in the xml files.
– Jim Cullen
Nov 15 '18 at 12:46
add a comment |
First try to remove redurant setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
Second add to end of "onCreate" function
binding.included.setValues(dataModel);
binding.executePendingBindings();
if you use include than you may add to your include id for example
<include
android:id="@+id/included"
layout="@layout/content_main"
app:values="@{DataModel}"/>
and use
binding.included.setValues(dataModel);
research about using databinding with included layouts
add a comment |
First try to remove redurant setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
Second add to end of "onCreate" function
binding.included.setValues(dataModel);
binding.executePendingBindings();
if you use include than you may add to your include id for example
<include
android:id="@+id/included"
layout="@layout/content_main"
app:values="@{DataModel}"/>
and use
binding.included.setValues(dataModel);
research about using databinding with included layouts
add a comment |
First try to remove redurant setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
Second add to end of "onCreate" function
binding.included.setValues(dataModel);
binding.executePendingBindings();
if you use include than you may add to your include id for example
<include
android:id="@+id/included"
layout="@layout/content_main"
app:values="@{DataModel}"/>
and use
binding.included.setValues(dataModel);
research about using databinding with included layouts
First try to remove redurant setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
Second add to end of "onCreate" function
binding.included.setValues(dataModel);
binding.executePendingBindings();
if you use include than you may add to your include id for example
<include
android:id="@+id/included"
layout="@layout/content_main"
app:values="@{DataModel}"/>
and use
binding.included.setValues(dataModel);
research about using databinding with included layouts
edited Nov 15 '18 at 12:56
answered Nov 15 '18 at 12:44
OnixOnix
4578
4578
add a comment |
add a comment |
Okay, I realised where the "class Models does not exist" thing comes from. I don't know whether to blame my own stupidity or the stupidly nitpicky way this binding is implemented on Android. The package needed to be called models with a lower case "m", not Models. The binding auto-name-conversion thing must have thought Models was a class, not a package.
To fix the layout, the onCreate method had to be changed to
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
cycleInformationBinding.setRecommendation(dataModel);
// set toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Drawer layout setting
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Specifically, things had to happen in the order:
setContentViewto the main activity- Set up the data model binding
- Layout concerns like drawer and toolbar.
Any other order would cause either the model binding to fail or the toolbar to not display correctly.
add a comment |
Okay, I realised where the "class Models does not exist" thing comes from. I don't know whether to blame my own stupidity or the stupidly nitpicky way this binding is implemented on Android. The package needed to be called models with a lower case "m", not Models. The binding auto-name-conversion thing must have thought Models was a class, not a package.
To fix the layout, the onCreate method had to be changed to
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
cycleInformationBinding.setRecommendation(dataModel);
// set toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Drawer layout setting
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Specifically, things had to happen in the order:
setContentViewto the main activity- Set up the data model binding
- Layout concerns like drawer and toolbar.
Any other order would cause either the model binding to fail or the toolbar to not display correctly.
add a comment |
Okay, I realised where the "class Models does not exist" thing comes from. I don't know whether to blame my own stupidity or the stupidly nitpicky way this binding is implemented on Android. The package needed to be called models with a lower case "m", not Models. The binding auto-name-conversion thing must have thought Models was a class, not a package.
To fix the layout, the onCreate method had to be changed to
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
cycleInformationBinding.setRecommendation(dataModel);
// set toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Drawer layout setting
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Specifically, things had to happen in the order:
setContentViewto the main activity- Set up the data model binding
- Layout concerns like drawer and toolbar.
Any other order would cause either the model binding to fail or the toolbar to not display correctly.
Okay, I realised where the "class Models does not exist" thing comes from. I don't know whether to blame my own stupidity or the stupidly nitpicky way this binding is implemented on Android. The package needed to be called models with a lower case "m", not Models. The binding auto-name-conversion thing must have thought Models was a class, not a package.
To fix the layout, the onCreate method had to be changed to
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
dataModel = new DataModel();
cycleInformationBinding.setRecommendation(dataModel);
// set toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Drawer layout setting
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Specifically, things had to happen in the order:
setContentViewto the main activity- Set up the data model binding
- Layout concerns like drawer and toolbar.
Any other order would cause either the model binding to fail or the toolbar to not display correctly.
edited Nov 19 '18 at 11:17
answered Nov 15 '18 at 12:49
Jim CullenJim Cullen
85
85
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319443%2fdata-binding-error-cannot-find-symbol-class-models%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown