Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Why does my app keeps stopping and shows error

Posted on November 11, 2022 By

Solution 1 :

class MainActivity(val myData: Array<String>) : AppCompatActivity() {

should be :

class MainActivity : AppCompatActivity() {

An activity class cannot have parameters.

Problem :

I tried to create horizontal RecyclerView and bottom Navigation Bar
I made horizontal_card_item.xml, HorizontalView.kt (class), DataSource.kt , and HorizontalViewAdapter File, for recyclerView.

Here’s my code of Main Activity.kt

class MainActivity(val myData: Array<String>) : AppCompatActivity() {

    private lateinit var horizontalViewAdapter: HorizontalViewAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val navView: BottomNavigationView = findViewById(R.id.nav_view)

        val navController = findNavController(R.id.nav_host_fragment)
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        val appBarConfiguration = AppBarConfiguration(setOf(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)

        initRecyclerView()
        addDataSet()
    }

    private fun initRecyclerView(){

        val recycler_view = null
        recycler_view.apply {
            var layoutManager = LinearLayoutManager([email protected])
            val topSpacingDecorator = TopSpacingItemDecoration(30)
            addItemDecoration(topSpacingDecorator)
            horizontalViewAdapter = HorizontalViewAdapter()
            var adapter = horizontalViewAdapter
        }
    }

    private fun addDataSet(){
        val data = DataSource.createDataSet()
        //HorizontalViewAdapter.SubmitList(data)
    }

    private fun addItemDecoration(topSpacingDecorator: TopSpacingItemDecoration) {

    }


}

This is the logcat error that my app is showing

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.riddhi.rift, PID: 9780
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.riddhi.rift/com.riddhi.rift.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.riddhi.rift.MainActivity> has no zero argument constructor
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.InstantiationException: java.lang.Class<com.riddhi.rift.MainActivity> has no zero argument constructor
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 

Comments

Comment posted by Riddhi Dua

But now i recieved an error 2020-06-07 01:22:58.125 10346-10346/com.riddhi.rift E/RecyclerView: No adapter attached; skipping layout 2020-06-07 01:22:58.154 10346-10402/com.riddhi.rift E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1

Comment posted by Abhimanyu

Kindly create a new SO post and comment on the link here. I will check it.

READ  [FIXED] android - How to add a download button or custom layout in center of progress bar?
Powered by Inline Related Posts

Comment posted by stackoverflow.com/questions/62238387/…

stackoverflow.com/questions/62238387/…

Android Tags:android

Post navigation

Previous Post: [FIXED] Android Studios error : Unable to locate adb location
Next Post: [FIXED] android – Here Maps Navigation samples seem to be missing the Navigation Library

Related Posts

[FIXED] c# – await DisplayAlert answer when using OnBackButtonpressed() for user confimation Android
[FIXED] user interface – Android : Change checkbox color (boxbackground and tick mark color) Android
[FIXED] Implementing SpeechSynthesisUtterance() TTS via javascript and android Chrome Android
[FIXED] android – Cache of my application increases due to Firebase UI Android
[FIXED] java – Android LiveData, Cannot create an instance of class viewModel Android
[FIXED] Dagger-Android @ActivityKey not found, how to create Sub components explicitly Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme