首页 » android

安卓开发使用androidx 的circleimage 报错: Caused by: java.lang.NoSuchMethodException: androidx.swiperefreshlayout.widget.CircleImageView.<init>

原因是这个类是私有的,只好使用 ,de.hdodenhof:circleimageview
1.加入依赖

api 'de.hdodenhof:circleimageview:2.2.0'

2.使用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
android:id="@+id/parent_layout">
    <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:id="@+id/image"
            android:src="@mipmap/ic_launcher" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Canada"
            android:id="@+id/image_name"
            android:layout_toRightOf="@+id/image"
            android:textColor="#000"
            android:layout_centerVertical="true"
            android:layout_marginLeft="30dp"
            android:textSize="17sp"/>
</RelativeLayout>

完整报错

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.greenhtml.demo, PID: 5645
    android.view.InflateException: Binary XML file line #6 in com.greenhtml.demo:layout/layout_listitem: Binary XML file line #6 in com.greenhtml.demo:layout/layout_listitem: Error inflating class androidx.swiperefreshlayout.widget.CircleImageView
    Caused by: android.view.InflateException: Binary XML file line #6 in com.greenhtml.demo:layout/layout_listitem: Error inflating class androidx.swiperefreshlayout.widget.CircleImageView
    Caused by: java.lang.NoSuchMethodException: androidx.swiperefreshlayout.widget.CircleImageView.<init> [class android.content.Context, interface android.util.AttributeSet]
        at java.lang.Class.getConstructor0(Class.java:2332)
        at java.lang.Class.getConstructor(Class.java:1728)
        at android.view.LayoutInflater.createView(LayoutInflater.java:824)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
        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.greenhtml.demo.adapters.RecyclerAdapter.onCreateViewHolder(RecyclerAdapter.kt:50)
        at com.greenhtml.demo.adapters.RecyclerAdapter.onCreateViewHolder(RecyclerAdapter.kt:20)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6992)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6161)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6044)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6040)
        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:4063)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3780)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4333)
        at android.view.View.layout(View.java:21892)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1193)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:880)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:899)
        at android.view.View.layout(View.java:21892)
        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:21892)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:446)
        at android.view.View.layout(View.java:21892)
        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:21892)
        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:21892)
        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:773)
        at android.view.View.layout(View.java:21892)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3078)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2588)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7595)
        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:7319)
        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:934)

这个是因为没有设置动画,但是设置了transaction导致,按下面改动代码

改动前:

supportFragmentManager
            .beginTransaction()
            .replace(R.id.content, fragment)
            .addToBackStack(fragment.toString())
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
            .commit()

改动后

  supportFragmentManager
            .beginTransaction()
            .replace(R.id.content, fragment)
            .addToBackStack(fragment.toString())
            //.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) //注释掉
            .commit()
E/FragmentManager: No field with the name mListener is found in Animation class
    java.lang.NoSuchFieldException: No field mListener in class Landroid/view/animation/Animation; (declaration of 'android.view.animation.Animation' appears in /system/framework/framework.jar!classes3.dex)
        at java.lang.Class.getDeclaredField(Native Method)
        at androidx.fragment.app.FragmentManagerImpl.getAnimationListener(FragmentManager.java:1301)
        at androidx.fragment.app.FragmentManagerImpl.setHWLayerAnimListenerIfAlpha(FragmentManager.java:1283)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1811)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1425)
        at android.app.Activity.performStart(Activity.java:7806)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3284)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7319)
        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:934)

android kotlin 报错:Failed to transform artifact 'butterknife-runtime.aar,这个是因为kotlin引入butterknife的方式不一样

正确写法

   kapt  'com.jakewharton:butterknife-compiler:10.1.0'

完整报错:

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform artifact 'butterknife-runtime.aar (com.jakewharton:butterknife-runtime:10.1.0)' to match attributes {artifactType=android-dex, dexing-is-debuggable=true, dexing-min-sdk=15}
      > Execution failed for DexingTransform: /home/shenfeng/.gradle/caches/transforms-2/files-2.1/24f8d04ecd88af554a48c2075e2142f3/jars/classes.jar.
         > Error while dexing.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org