无法实例化以下类:android.support.v7.widget.AppCompatImageView

时间:2016-12-06 07:50:47

标签: android xml

问题:

无法实例化以下类:android.support.v7.widget.AppCompatImageView

这是IDE提供的提示。

 Rendering Problems The following classes could not be instantiated:
- android.support.v7.widget.AppCompatImageView (Open Class, Show Exception, Clear Cache)

 Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.  If this is an unexpected error you can also try to build the project, then manually refresh the layout.  


Tip: Try to refresh the layout.

这是我的fragment_comment_list.xml     

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginTop="18dp"
            android:text="@string/title_best_comments"
            android:textColor="@color/dark_primary"
            android:textSize="14sp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/best_comments_rv"
            android:name="com.opera.android.news.comment.CommentFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="15dp"
            app:layoutManager="LinearLayoutManager"
            tools:context="com.opera.android.news.comment.CommentFragment"
            tools:listitem="@layout/fragment_comment" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginTop="18dp"
            android:text="@string/title_latest_comments"
            android:textColor="@color/dark_primary"
            android:textSize="14sp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/latest_comments_rv"
            android:name="com.opera.android.news.comment.CommentFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            app:layoutManager="LinearLayoutManager"
            tools:context="com.opera.android.news.comment.CommentFragment"
            tools:listitem="@layout/fragment_comment" />

    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

这是我的fragment_comment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/content_rl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/comment_large_head"
            android:layout_width="28dp"
            android:layout_height="28dp"
            app:srcCompat="@drawable/ic_comment_head_large" />

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:layout_toRightOf="@id/comment_large_head"
            android:text="Romain Beaumont" />

        <TextView
            android:id="@+id/comment_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@id/name"
            android:layout_below="@id/name"
            android:text="7h" />

        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignLeft="@id/name"
            android:layout_below="@+id/comment_time"
            android:text="The previous deal was rejected by the Colombian people in a popular vote on 2 October.The previous deal was" />

        <ImageView
            android:id="@+id/comment_like_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            app:srcCompat="@drawable/ic_comment_unlike" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@id/comment_like_iv"
            android:text="32" />
    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/replies"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="5dp"/>
</LinearLayout>

这是跟踪堆栈。

  

异常详细信息java.lang.NullPointerException at   android.content.res.Resources_Delegate.getValue(Resources_Delegate.java:747)   在android.content.res.Resources.getValue(Resources.java:1286)at   android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:234)   在   android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)   在   android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)   在   android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)   在   android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)   在   android.support.v7.widget.AppCompatImageView。(AppCompatImageView.java:66)   在   android.support.v7.widget.AppCompatImageView。(AppCompatImageView.java:56)   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)   在android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)   在   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)   在   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)   在   android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)   在   android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   在android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   在   android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   在   android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)   在   android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   在android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   在   android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   在android.view.LayoutInflater.inflate(LayoutInflater.java:518)at   android.view.LayoutInflater.inflate(LayoutInflater.java:426)at   com.android.layoutlib.bridge.android.support.Adapter.onCreateViewHolder在   android.support.v7.widget.RecyclerView $ Adapter.createViewHolder(RecyclerView.java:6078)at at   android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5248)   在   android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5158)   在   android.support.v7.widget.LinearLayoutManager $ LayoutState.next(LinearLayoutManager.java:2061)   在   android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1445)   在   android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408)   在   android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580)   在   android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3379)   在   android.support.v7.widget.RecyclerView.onMeasure_Original(RecyclerView.java:2906)   在   android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:-1)   在android.view.View.measure(View.java:19731)at   android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)   在   android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)   在   android.widget.LinearLayout.measureVertical(LinearLayout.java:758)   在android.widget.LinearLayout.onMeasure(LinearLayout.java:640)at   android.view.View.measure(View.java:19731)at   android.support.v4.widget.NestedScrollView.measureChildWithMargins(NestedScrollView.java:1420)   在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at   android.support.v4.widget.NestedScrollView.onMeasure_Original(NestedScrollView.java:482)   在   android.support.v4.widget.NestedScrollView.onMeasure(NestedScrollView.java:-1)   在android.view.View.measure(View.java:19731)at   android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)   在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at   android.view.View.measure(View.java:19731)at   android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:715)   在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)   在android.view.View.measure(View.java:19731)将堆栈复制到   剪贴板无法解析资源@ drawable / ic_comment_unlike(23   类似的错误未显示)转换失败   @ drawable / ic_comment_unlike成drawable(详情)(21类似   错误未显示)

1 个答案:

答案 0 :(得分:0)

看起来你还没有初始化ImageView。 或者你能告诉我你的java代码吗?