Java 安卓工作室可以';无法识别自定义视图类

Java 安卓工作室可以';无法识别自定义视图类,java,android,xml,android-studio,Java,Android,Xml,Android Studio,我正在使用Android studio进行开发,这是我面临的问题。我尝试了下面显示的提示,但仍然没有任何效果。我得到的唯一错误行是“java.lang.NullPointerException”,除了这个和下面的窗口没有更多的解释 Rendering Problems The following classes could not be instantiated: - com.xxx.xxx.util.CircleImageView (Open Class, Sh

我正在使用Android studio进行开发,这是我面临的问题。我尝试了下面显示的提示,但仍然没有任何效果。我得到的唯一错误行是“java.lang.NullPointerException”,除了这个和下面的窗口没有更多的解释

    Rendering Problems The following classes could not be instantiated:
- com.xxx.xxx.util.CircleImageView 
           (Open Class, Show Exception)
   Tip: Use View.isInEditMode() in your custom views to skip code
      or show sample data when shown in the IDE  Exception Details
      java.lang.NullPointerException 
这是我的XML代码。。。。希望你能帮助大家:/

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <LinearLayout
            android:layout_height="240dp"
            android:layout_width="match_parent"
            android:orientation="vertical">

            <com.xxx.xxx.util.CustomImageButton
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:background="@drawable/ic_launcher" />

            <com.xxx.xxx.util.CircleImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:background="@drawable/ic_plusone_tall_off_client" />
        </LinearLayout>
    </LinearLayout>

</FrameLayout>
使用

在CircleImageView中的init()之前

有很多帖子都在谈论这个问题,比如


编辑:我不确定您是否像这样使用了提示,如果是这样,请提供一个您尝试过的示例。

如果您的问题中也显示了无法实例化的类,这将很有帮助。单击“显示异常”堆栈中唯一的东西是java.lang.NullPointerException它在eclipse中工作得非常好。转移到Android研究是个坏主意。这种方法在我的Android Studio中有效,你有最新版本吗?你能提供一个给你NullPointerException的代码的例子吗?是的,我有最新的版本。如果(!isInEditMode())解决了eclipse中的问题:)那太好了!但我想知道为什么它不起作用。如果这对你有帮助,请不要忘记接受答案,谢谢!在Android Studio 2.1上工作过!
public class CircleImageView extends ImageView {
    // Border & Selector configuration variables
    private boolean hasBorder;
    private boolean hasSelector;
    private boolean isSelected;
    private int borderWidth;
    private int canvasSize;
    private int selectorStrokeWidth;

    // Objects used for the actual drawing
    private BitmapShader shader;
    private Bitmap image;
    private Paint paint;
    private Paint paintBorder;
    private Paint paintSelectorBorder;
    private ColorFilter selectorFilter;

    public CircleImageView(Context context) {
        this(context, null);
    }

    public CircleImageView(Context context, AttributeSet attrs) {
        this(context, attrs, R.attr.CircleImageViewStyle);
    }

    public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context, attrs, defStyle);
    }

    /**
     * Initializes paint objects and sets desired attributes.
     *
     * @param context
     * @param attrs
     * @param defStyle
     */
    private void init(Context context, AttributeSet attrs, int defStyle) {
       ...code
    }

    /**
     * Sets the CircleImageView's border width in pixels.
     *
     * @param borderWidth
     */
    public void setBorderWidth(int borderWidth) {
    ...code
    }

    /**
     * Sets the CircleImageView's basic border color.
     *
     * @param borderColor
     */
    public void setBorderColor(int borderColor) {
    ...code
    }

    /**
     * Sets the color of the selector to be draw over the
     * CircleImageView. Be sure to provide some opacity.
     *
     * @param selectorColor
     */
    public void setSelectorColor(int selectorColor) {
    ...code
    }

    /**
     * Sets the stroke width to be drawn around the CircleImageView
     * during click events when the selector is enabled.
     *
     * @param selectorStrokeWidth
     */
    public void setSelectorStrokeWidth(int selectorStrokeWidth) {
    ...code
    }

    /**
     * Sets the stroke color to be drawn around the CircleImageView
     * during click events when the selector is enabled.
     */
    public void setSelectorStrokeColor(int selectorStrokeColor) {
    ...code
    }

    /**
     * Adds a dark shadow to this CircleImageView.
     */
    public void addShadow() {
    ...code
    }

    @Override
    public void onDraw(Canvas canvas) {
        ...code
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
    ...code
    }

    public void invalidate(Rect dirty) {
    ...code
    }

    public void invalidate(int l, int t, int r, int b) {
    ...code
    }

    @Override
    public void invalidate() {
    ...code
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    ...code
    }

    private int measureWidth(int measureSpec) {
    ...code
    }

    private int measureHeight(int measureSpecHeight) {
    ...code
    }

    /**
     * Convert a drawable object into a Bitmap
     *
     * @param drawable
     * @return
     */
    public Bitmap drawableToBitmap(Drawable drawable) {
    ...code
    }

    /**
     * Reinitializes the shader texture used to fill in
     * the Circle upon drawing.
     */
    public void refreshBitmapShader() {
    ...code
    }

    /**
     * Returns whether or not this view is currently
     * in its selected state.
     */
    public boolean isSelected() {
    ...code
    }

    @Override
    public boolean isInEditMode() {
    ...code
    }
} 
if (!isInEditMode())