java.lang.RuntimeException:Unable to start activity ComponentInfo{com.meizu.beautify/com.my.viewc.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.meizu.main.ResourcesDetailedActivity: make sure class name exists, is public, and has an empty constructor that is public
Having been developing Android for so long, I still often encounter this problem: after an APP that has been tested by myself and has no problems is launched, users always report that they have encountered bugs. However, for these problems encountered by users, there is no way to find the corresponding logs in the simulation environment. At that time, we didn’t know that Tencent had bugly, a tool specifically designed to monitor Crash, and we couldn’t find users to cooperate in testing, so every time we encountered user feedback issues, we had to work on it for several days. When I'm not lucky, days go by and I still can't find the source of the problem.
Our product has gone through several versions, and this problem has not been improved, which is really frustrating. Adhering to the attitude of quality first, I found Tencent's bugly and connected to the new version of the product as soon as it was released. After the product was released, I checked the reporting records. I was really surprised when I saw it. There are dozens of error logs, which affect users a lot, so we quickly solve them one by one.
For example:
There is a problem that has been reported by many users. Due to the lack of stack and environment information, we have not been able to find the problem. After accessing bugly, I learned that the error line is:
Since it only appeared on some devices and I couldn’t find the corresponding information on Baidu and Google, I always thought it was Android’s own bug.
Later, bugly was used for access, and the reported result was:
java.lang.NoSuchMethodException
<init> []
java.lang.RuntimeException:Unable to start activity ComponentInfo{com.meizu. beautify/com.my.viewc.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.meizu.main.ResourcesDetailedActivity: make sure class name exists, is public, and has an empty constructor that is public
Specific error log:
java.lang.NoSuchMethodException:<init> []
java.lang.Class.getConstructor(Class.java:531)
java.lang.Class. getDeclaredConstructor(Class.java:510)
java.lang.Class.newInstance(Class.java:1561)
android.support.v4.app.Fragment.instantiate(Fragment.java:420)
android .support.v4.app.FragmentState.instantiate(Fragment.java:101)
android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1823)
android.support.v4.app.FragmentActivity .onCreate(FragmentActivity.java:264)
com.my.viewc.MainActivity.onCreate(MainActivity.java:22)
Only then did I realize that it was a problem with FragmentActivity. Looking at the source code through Message, we can see that when using Fragment, you cannot write a constructor with parameters yourself, because the system calls the parameterless constructor by default newResourcesDetailedActivity(String cc);
Otherwise, when creating a Fragment, the system will call the parameterless constructor, and you rewrite the constructor with parameters, causing the system to not be able to find this method, and finally
java.lang.NoSuchMethodException:< init> []
If you can't find the line of code that reported the error, just change it to: newResourcesDetailedActivity();
The exception will no longer occur, and then use other methods to pass parameters or objects, and the problem will be solved.
Finally, I am very grateful to Tencent for BUGLY. This tool is so powerful and is absolutely an indispensable SDK in Android development. Now all services are free, which not only improves product quality, but also reduces product development costs. .