Development record of developer who study hard everyday.

레이블이 android error인 게시물을 표시합니다. 모든 게시물 표시
레이블이 android error인 게시물을 표시합니다. 모든 게시물 표시
,

How to solve error: constant expression required

 How to solve error: constant expression required


After I upgrade Gradle version upto 8.0, I encounter "constant expression required" error.

This is because AGP 8.0 doesn't allow reference to resourceID.

In my case, I use below code:

switch(view.id) {

    case sample1: 

    case sample2:

    ......

}


Solution1:

Change switch statement to if-else statement


Solution2:

Add below properties to gradle.properties file

android.nonFinalResIds = false






















Share:
Read More
,

How to solve "Can not find symbol BuildConfig" errorr

 How to solve "Can not find symbol BuildConfig" errorr



android {
    buildFeatures {
        buildConfig = true
    }
}

Put on above code into build.gradle file (app level).

This is because AGP 8.0 sets the default value of android.defaults.buildfeatures.buildconfig to false.












Share:
Read More
, , ,

[Solved] ViewPager.setAdapter throws IllegalArgumentException in Android

 ViewPager.setAdapter throws IllegalArgumentException in Android

안드로이드 개발 블로그

java.lang.IllegalArgumentException

at androidx.core.util.Preconditions.checkArgument(Preconditions.java:38)

at androidx.viewpager2.adapter.FragmentStateAdapter.onAttachedToRecyclerView(FragmentStateAdapter.java:132)

at androidx.recyclerview.widget.RecyclerView.setAdapterInternal(RecyclerView.java:1243)

at androidx.recyclerview.widget.RecyclerView.setAdapter(RecyclerView.java:1194)

at androidx.viewpager2.widget.ViewPager2.setAdapter(ViewPager2.java:461)

at net.twobeone.pink.fragments.MainFragment.activityInit(MainFragment.kt:58)

at net.twobeone.pink.fragments.MainFragment.onViewCreated(MainFragment.kt:49)

at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3128)

at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:552)

at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)

at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1890)

at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1823)

at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1760)

at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:547)

at android.os.Handler.handleCallback(Handler.java:938)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:246)

at android.app.ActivityThread.main(ActivityThread.java:8653)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)


Solution : 

Initialize ViewPagerAdapter in onCreateView.


Wrong Example:

class MainFragment : BaseFragment<FragmentMainBinding>() {

private val viewPagerAdapter : ViewPagerAdapter by lazy { ExampleViewPagerAdapter(this) }
}




vallayoutResID 재정의: Int get() = R.layout.fragment_main
Share:
Read More