我想在一些活动中使用LineEditText。不幸的是,我收到了这个错误

2020-03-07 15:08:31.008 13079-13079/com.example.memos E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.memos, PID: 13079
    android.view.InflateException: Binary XML file line #12 in com.example.memos:layout/activity_memo_content: Binary XML file line #12 in com.example.memos:layout/activity_memo_content: Error inflating class LineEditText
    Caused by: android.view.InflateException: Binary XML file line #12 in com.example.memos:layout/activity_memo_content: Error inflating class LineEditText
    Caused by: java.lang.ClassNotFoundException: android.view.LineEditText
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at android.view.LayoutInflater.createView(LayoutInflater.java:815)
        at android.view.LayoutInflater.createView(LayoutInflater.java:776)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:913)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:930)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:950)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at com.example.memos.adapters.MemoAdapter.onCreateViewHolder(MemoAdapter.java:53)
        at com.example.memos.adapters.MemoAdapter.onCreateViewHolder(MemoAdapter.java:21)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:148)
        at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:43)
        at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1892)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:918)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
2020-03-07 15:08:31.009 13079-13112/com.example.memos D/EGL_emulation: eglCreateContext: 0xe0c1a180: maj 3 min 1 rcv 4
2020-03-07 15:08:31.009 13079-13079/com.example.memos E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:779)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3080)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2590)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:725)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.LineEditText" on path: DexPathList[[zip file "/data/app/com.example.memos-dqkZkFlgi6NL7DedvRqjww==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.memos-dqkZkFlgi6NL7DedvRqjww==/lib/x86, /system/lib, /system/product/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 73 more
2020-03-07 15:08:31.109 13079-13112/com.example.memos D/EGL_emulation: eglMakeCurrent: 0xe0c1a180: ver 3 1 (tinfo 0xe0c0f350)
2020-03-07 15:08:31.112 13079-13112/com.example.memos E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
2020-03-07 15:08:31.113 13079-13112/com.example.memos E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
2020-03-07 15:08:31.121 13079-13079/com.example.memos I/Process: Sending signal. PID: 13079 SIG: 9


LineEditText类

public class LineEditText extends AppCompatEditText  {

Rect mRect;
Paint mPaint;

public LineEditText(Context context, AttributeSet attrs) {
    super(context, attrs);

    mRect = new Rect();
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(2);
    mPaint.setColor(0xFFFFD966);


}

@Override
protected void onDraw(Canvas canvas) {

    int screenHeight = ((View)this.getParent()).getHeight();
    int lineHeight = getLineHeight();
    int numberOfLines = screenHeight / lineHeight;

    Rect rect = new Rect();
    Paint paint = new Paint();

    int baseline = getLineBounds(0, rect);

    for (int i = 0; i < numberOfLines; i++) {
        canvas.drawLine(rect.left, baseline+1, rect.right, baseline+1, paint);
        baseline += lineHeight;
    }
    super.onDraw(canvas);
}


}

备注适配器类

   public class MemoAdapter extends RecyclerView.Adapter<MemoAdapter.MemoViewHolder> {


    private ArrayList<Note> mNotes;
    private OnNoteListener mListener;

    public class MemoViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        TextView title, content, timestamp;
        //TODO initialize rest of TextViews
        public MemoViewHolder(@NonNull final View itemView) {
            super(itemView);
            this.title = (TextView) itemView.findViewById(R.id.title);
            itemView.setOnClickListener(this);

        }

        @Override
        public void onClick(View v) {
            mListener.onMemoClick(getAdapterPosition());
        }
    }


    public MemoAdapter(ArrayList<Note> notes, OnNoteListener listener) {
        this.mNotes = notes;
        this.mListener = listener;
    }

    @NonNull
    @Override
    public MemoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_memo_content, parent, false);
        return new MemoViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MemoViewHolder holder, int position) {
        holder.title.setText(mNotes.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return mNotes.size();
    }

    public interface OnNoteListener{
       void onMemoClick(int position);
    }
}


这有什么问题吗?关于EditText自定义类吗?请给我任何线索。


第12行是指我的xml文件,实际上是LineEditText

android.view.InflateException: Binary XML file line #12 in com.example.memos:layout/activity_memo_content: Binary XML file line #12 in com.example.memos:layout/activity_memo_content: Error inflating class LineEditText



aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

最佳答案

造成原因:java.lang.ClassNotFoundException:android.view.LineEditText


它在LineEditText包内搜索android.view,因为它是SDK的一部分,所以不是放置它的地方。
检查LineEditText的位置,并将xml中的android.view替换为具有LineEditText的软件包。

10-05 17:51