首先,我尝试了Stackoverflow
上提出的所有解决方案,但对我不起作用。因此,在使用DataBinding
而不是Base Activity
时遇到问题。我正在
尝试从字段中读取 “com.mobilemovement.bestcoin.databinding.ToolbarLayoutBinding com.mobilemovement.bestcoin.databinding.ActivityHolderBinding.ahToolbarLayout” 在空对象引用上
BaseActivity.java
public abstract class BaseActivity<B extends ViewDataBinding> extends
AppCompatActivity {
protected B dataBinding;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private NavigationView mNavigationView;
private Toolbar mToolbar;
protected void bindView(Toolbar toolbar, DrawerLayout drawerLayout, NavigationView navigationView) {
dataBinding = DataBindingUtil.setContentView(this, setLayoutResourceIdentifier());
mToolbar = toolbar;
setSupportActionBar(toolbar);
mNavigationView = navigationView;
setupDrawerContent();
mDrawerToggle = setupDrawerToggle();
mDrawerLayout = drawerLayout;
mDrawerLayout.addDrawerListener(mDrawerToggle);
}
MainActivity.java
public class HolderActivity extends BaseActivity<ActivityHolderBinding> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bindView(dataBinding.ahToolbarLayout.toolbar,
dataBinding.dlHolderActivity,
dataBinding.nvItemHolder);
}
我可以使用没有BaseActivity的DataBinding,所以我的意思是我的布局和ID是正确的,但是当我切换到BaseActivity时,我收到了错误。