2016-12-06 52 views
0

問題:以下類不能被實例化:android.support.v7.widget.AppCompatImageView

以下類不能被實例化: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在 android.content.res.Resources_Delegate.getValue(Resources_Delegate.java:747) 在android.content.res.Resources.getValue(Resources.java:1286)在 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) at 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) 在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.cre ateViewFromTag(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) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) 在在 在 android.view.LayoutInflater.inflate(LayoutInflater.java:426) android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 在android.view.LayoutInflater.inflate(LayoutInflater.java:518) com.android.layoutlib.bridge.android.support.Adapter.onCreateViewHolder at android.support.v7.widget.RecyclerView $ Adapter.createViewHolder(RecyclerView.java:6078)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) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3379) at android.support.v7.widget.RecyclerView.onMeasure_Original(RecyclerView.java:2906) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:-1) at android.view.View。測量(View.java:19731)在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 在 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 在 android.widget.LinearLayout。 measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)at android.view.View.measure(View.java:19731)at android.support.v4.widget。 NestedScrollVi ew.measureChildWithMargins(NestedScrollView.java:1420) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)在 android.support.v4.widget.NestedScrollView.onMeasure_Original(NestedScrollView.java:482) 在 機器人在Android.view.View.measure(View.java:19731)在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120).support.v4.widget.NestedScrollView.onMeasure(NestedScrollView.java:-1) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)在 android.view.View.measure(View.java:19731)在 android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:715) 在android.widget.RelativeLayout.onMeasure(RELA tiveLayout.java:461) at android.view.View.measure(View.java:19731)將堆棧複製到 剪貼板無法解析resource @ drawable/ic_comment_unlike(23 類似的錯誤未顯示)未能轉換 @drawable/ic_comment_unlike成繪製(詳細信息)(未21個類似 錯誤所示)

回答

0

它好像你還沒有初始化ImageView的。 或者你可以讓我看看你的java代碼。?

+0

我現在得到這個錯誤,不是運行時錯誤,是佈局編輯器中顯示的android studio錯誤消息。 – Pablo

相關問題