我是靠谱客的博主 害羞中心,最近开发中收集的这篇文章主要介绍android 找不到布局id,为什么给layout加上id,ButterKnife就找不到资源了?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

报错

Caused by: java.lang.RuntimeException: Unable to bind views for cc.haoduoyu.umaru.ui.activities.ChatActivity

at butterknife.ButterKnife.bind(ButterKnife.java:322)

at butterknife.ButterKnife.bind(ButterKnife.java:237)

at cc.haoduoyu.umaru.base.ToolbarActivity.onCreate(ToolbarActivity.java:42)

at cc.haoduoyu.umaru.ui.activities.ChatActivity.onCreate(ChatActivity.java:81)

at android.app.Activity.performCreate(Activity.java:6285)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)

at android.app.ActivityThread.-wrap11(ActivityThread.java)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:148)

at android.app.ActivityThread.main(ActivityThread.java:5417)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Caused by: java.lang.IllegalStateException: Required view 'app_bar_layout' with ID 2131691083 for field 'mAppBar' was not found. If this view is optional add '@Nullable' annotation.

at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140)

activity.xml

android:id="@+id/toolbarLayout"//加上这行就报错

layout="@layout/view_toolbar">

view_toolbar.xml

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/app_bar_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:elevation="0dp">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="?attr/colorPrimary"

android:fitsSystemWindows="true"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

activity

public abstract class Activity extends BaseActivity {

abstract protected int provideContentViewId();

public void onToolbarClick() {

}

@Bind(R.id.app_bar_layout)

protected AppBarLayout mAppBar;

@Bind(R.id.toolbar)

protected Toolbar mToolbar;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(provideContentViewId());

ButterKnife.bind(this);

}

}

最后

以上就是害羞中心为你收集整理的android 找不到布局id,为什么给layout加上id,ButterKnife就找不到资源了?的全部内容,希望文章能够帮你解决android 找不到布局id,为什么给layout加上id,ButterKnife就找不到资源了?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部