-2
My app is in production and I’m having a problem in a small part of the devices, I haven’t been able to identify the reason or at least reproduce the problem in a test environment, I did some research looking for more information, but without success, I would like the community to direct me to possible situations that may be generating this problem. My app is simple, it’s a news app and when it has new news the app notifies users.
The devices that presented the error:
- Samsung Galaxy A20 (A20), 2816MB RAM, Android 9
- Samsung Galaxy J4 (j4lte), 2048MB RAM, Android 9
- Motorola Moto G (5th Gen) (Cedric), 2048MB RAM, Android 8.1
- Samsung Galaxy J4 Core (j4corelte), 1024MB RAM, Android 8.1
As I don’t know which parts of the code are related to the problem, I didn’t put any specific class, but if anyone wants to just ask in the comments, for example I believe it is related to notification.
The error was captured straight from google play console.
java.lang.Runtimeexception:
at android.app.Activitythread.performLaunchActivity (Activitythread.java:3121) at android.app.Activitythread.handleLaunchActivity (Activitythread.java:3264) 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:1955) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:214) at android.app.Activitythread.main (Activitythread.java:7078) at java.lang.reflect.Method.invoke (Native Method) at com.android.Internal.os.Runtimeinit$Methodandargscaller.run (Runtimeinit.java:494) at com.android.Internal.os.Zygoteinit.main (Zygoteinit.java:965)
Caused by: androidx.fragment.app.Fragment$Instantiationexception:
at androidx.fragment.app.Fragment.instantiate (Fragment.java:538)
at androidx.fragment.app.FragmentContainer.instantiate (Fragmentcontainer.java:57) at androidx.fragment.app.FragmentManagerImpl$6.instantiate (Fragmentmanagerimpl.java:2851) at androidx.fragment.app.FragmentState.instantiate (Fragmentstate.java:85) at androidx.fragment.app.FragmentManagerImpl.restoreSaveState (Fragmentmanagerimpl.java:2488) at androidx.fragment.app.FragmentController.restoreSaveState (Fragmentcontroller.java:195) at androidx.fragment.app.FragmentActivity.onCreate (Fragmentactivity.java:288) at androidx.appcompat.app.AppCompatActivity.onCreate (Appcompatactivity.java:106) at xxx.xxxx.xxxxx.MainActivity.onCreate (Mainactivity.kt:70) at android.app.Activity.performCreate (Activity.java:7339) at android.app.Activity.performCreate (Activity.java:7330) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1275) at android.app.Activitythread.performLaunchActivity (Activitythread.java:3101)Caused by: java.lang.Nosuchmethodexception:
at java.lang.Class.getConstructor0 (Class.java:2328) at java.lang.Class.getConstructor (Class.java:1725) at androidx.fragment.app.Fragment.instantiate (Fragment.java:523)
Part of the class the problem points to
Mainactivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) // Linha 70
setContentView(R.layout.activity_main)
...
}
Other classes that may be related to the problem
Pageradapter.kt
class PagerAdapter(val fragmentActivity: FragmentActivity, private var lista: MutableList<Blog>) : FragmentStateAdapter(fragmentActivity) {
override fun getItemCount(): Int {
return lista.size+1
}
override fun createFragment(position: Int): Fragment {
return if(position<lista.size)
Tab(lista[position])
else
OutraTab() // tab fixa no final
}
}
Tab.kt
class Tab(private val blog: Blog) : Fragment() {
...
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.tab, container, false)
...
}
}
Outratab.kt
class OutraTab : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.tab_outra, container, false)
...
}
}
Obs. Outratab.kt is similar to Tab.kt, only without the parameter blog it contains fixed content.
Your question is very broad, you could discuss something like that at the goal (if I’m not mistaken). Here the questions need to be objective, describing a problem in a way that is answered directly and not argumentatively.
– Brewerton Santos
I understand, I know that the information I have is insufficient to solve, this is perhaps the difficulty to solve this problem, I have not been able to reproduce this error in a test environment, I still do not know what flow generates this error, but I believe that someone here in the community can identify some flow or logic error.. today I will perform new tests and then I will post some snippets of the code
– LSA
All right, we expect details to help you and also, leave useful answers for people who in the future have the same problem.
– Brewerton Santos
The method
androidx.fragment.app.Fragment.instantiate
was depreciated.– Augusto Vasques
@Augustovasques is true I was using in my Pageradapter the deprecated Fragmentstatepageradapter, I switched to Fragmentstateadapter, I also changed Viewpager to Viewpager2 which was also deprecated, Android Studio did not warn me about this, as I can not reproduce the error in the test scenario, I also changed a part of the flow of my app, to see if the error will persist and now I am putting in production and I will observe if the error will continue. Such depreciation may cause the reported error?
– LSA
I think we moved on to this problem, the doubt was also that the problem pointed to line 70 of Mainactivity, line 70 is super.onCreate(savedInstanceState), only until then it had no sense, but now we realized that there was a problem in the interface (Belittled viewpager), usually when there is a problem in the interface that is the line that is pointed out by the error, someone correct me if I’m wrong..
– LSA
@LSA " Can this depreciation cause the reported error?". Do not use depreciated methods. The standard is only one Android, but each manufacturer implements the endpoints of the API according to its hardware and maybe, it may be for some other reason, the manufacturer to save, memory, manpower or time development with obsolete material decides not to implement the depreciated methods in certain versions of the OS and so it happens that the code works in some brands/models and other brands/models does not work.
– Augusto Vasques
Okay, the app is already production, I will wait until the next few days to see if the problem has been solved, if it was I will post here what was done exactly in the code so that I can help other people with the same problem.
– LSA
Class R references are sometimes lost and cause Runtime problems. But seeing the error, it seems to be related to the access data that is instantiating and not being able to display in Activitythread. Tried a new build of the application? Is the application giving error only in these models cited? Uses access API to display news?
– Nellonidas
I thought that replacing the deprecated components the problem would be solved, however the problem continues, in this new version released had a similar error in the device Motorola Moto G (5S) (Montana) android 8.1, however I’m having another question and do not know the side effects of this type of implementation, I’ll have to open another question to take this doubt and then come back here, if you will not run away from the theme. I also noticed that another application that I manage has the same error.
– LSA
@Nellonidas I did a new build, but the error continues, this error it happens from time to time still not able to reproduce in test scenario, I can only see that it has not been fixed with the reports of google failures, probably occurs in other devices too, news is uploaded directly from the websites through the Jsoup library
– LSA
I guess you haven’t solved the problem yet. Do all your fragments have a constructor with 0 arguments (default constructor)? If not, the problem may be this (and then I can draft an answer on)
– Rafael Tavares
@Rafaeltavares, not yet, but I am trying to correct, only the Fragment Outratab that has 0 arguments in the default constructor, I updated the answer and put the classes
– LSA