catalogue

  • 1.1 Java. Lang. ClassNotFoundException class can’t find abnormal
  • 1.2 Java. Util. Concurrent. TimeoutException connection timeout to collapse
  • 1.3 Java. Lang. A NumberFormatException format conversion errors
  • 1.4 Java. Lang. An IllegalStateException: fragments not attached to the Activity
  • 1.5 ArrayIndexOutOfBoundsException Angle of the cross-border anomalies
  • 1.6 Constructor permission exception in IllegalAccessException method
  • Android 1.7. View. WindowManager $BadTokenException, dialog window abnormal
  • 1.8 Java. Lang. NoClassDefFoundError couldn’t find the abnormal class
  • 1.9 Android appears: Your Project path contains non-ASCII characters

Good news

  • Summary of blog notes [March 2016 to present], including Java basic and in-depth knowledge points, Android technology blog, Python learning notes, etc., including the summary of bugs encountered in daily development, of course, I also collected a lot of interview questions in my spare time, updated, maintained and corrected for a long time, and continued to improve… Open source files are in Markdown format! Also open source life blog, since 2012, accumulated a total of 47 articles [nearly 200,000 words], reprint please indicate the source, thank you!
  • Link address:Github.com/yangchong21…
  • If you feel good, you can star, thank you! Of course, also welcome to put forward suggestions, everything starts from small, quantitative change causes qualitative change!

1.1 Java. Lang. ClassNotFoundException class can’t find abnormal

  • A. Detailed crash log information
    Didn't find class "om.scwang.smartrefresh.layout.SmartRefreshLayout" on path: DexPathList[[zip file "/data/app/com.paidian.hwmc-EsIbVq6e0mFwE0-rPanqdg==/base.apk", zip file "/data/app/com.paidian.hwmc-EsIbVq6e0mFwE0-rPanqdg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.paidian.hwmc-EsIbVq6e0mFwE0-rPanqdg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.paidian.hwmc-EsIbVq6e0mFwE0-rPanqdg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.paidian.hwmc-EsIbVq6e0mFwE0-rPanqdg==/split_lib_s
    com.paidian.hwmc.goods.activity.GoodsDetailsActivity.onCreate(GoodsDetailsActivity.java:209)
    Copy the code
  • B. View crash information
    • Raised when an application tries to load a class with a string name: but cannot find the definition of the class with the specified name. Starting with version 1.4, this exception has been modified to conform to the common exception link mechanism. The “optional exception thrown when loading a class” provided at build time and accessed through the {@link#getException()} method is now called the cause and can be accessed through the {@link Throwable#getCace()} method as well as the “legacy method” mentioned earlier.
    public class ClassNotFoundException extends ReflectiveOperationException {
        private static final long serialVersionUID = 9176873029745254542L;
        private Throwable ex;
        public ClassNotFoundException() {
            super((Throwable)null);  // Disallow initCause
        }
        public ClassNotFoundException(String s) {
            super(s, null);  //  Disallow initCause
        }
        public ClassNotFoundException(String s, Throwable ex) {
            super(s, null);  //  Disallow initCause
            this.ex = ex;
        }
        public Throwable getException() {
            return ex;
        }
        public Throwable getCause() {
            returnex; }}Copy the code
  • C. Anomaly analysis in the project
    • This exception indicates that the specified class cannot be found under the path, usually due to build path problems.
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • The Class name is identified as a string, which has low reliability. An error will be reported if the Class name cannot be found when methods such as class.forname (“”), class.findSystemClass (“”), or class.loadClass (“”) are called. If the Class cannot be found is the system Class, it may be the system version compatible, manufacturer Rom compatible problem, find the corresponding device to try to reproduce, the solution can be considered to change the Api, or use their own implementation of the Class instead.
    • If the missing Class is an application-free Class (including a third-party SDK Class), you can use a decompiler to check whether the corresponding APK is missing the Class, and then locate the Class. This usually occurs in:
      • 1. The Class you are looking for is confused and exists with a different name.
      • 2. The desired Class is not inserted into Dex and does not exist. It may be due to negligence or compiler environment conflict.
      • 3. The Class you are looking for does exist, but your Classlorder cannot find it, often because the Classloder is your own implementation (common in plug-in applications).
  • G. Other extensions

1.2 Java. Util. Concurrent. TimeoutException connection timeout to collapse

  • A. Detailed crash log information
    java.util.concurrent.TimeoutException: android.view.ThreadedRenderer.finalize() timed out after 10 seconds at android.view.ThreadedRenderer.nDeleteProxy(Native  Method) at android.view.ThreadedRenderer.finalize(ThreadedRenderer.java:423)Copy the code
  • B. View crash information
    • An exception thrown when a blocking operation times out. Blocking operations that specify a timeout require a way to indicate that a timeout has occurred. For many of these operations, you can return a value indicating a timeout; If this is not possible or unnecessary, declare and throw {@code TimeoutException}.
    public class TimeoutException extends Exception {
        private static final long serialVersionUID = 1900926677490660714L;
        public TimeoutException() {} public TimeoutException(String message) { super(message); }}Copy the code
  • C. Anomaly analysis in the project
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • Generally, the system calls finalize object timeout during GC. Solution:
    • 1. Check and analyze why the implementation of Finalize is time-consuming and repair it;
    • 2. Check logs to check whether GC times out frequently, reducing content overhead and preventing memory leaks.
  • G. Other extensions

1.3 Java. Lang. A NumberFormatException format conversion errors

  • A. Detailed crash log information
    Exception in thread "main" java.lang.NumberFormatException: For input string: "100"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:458)
        at java.lang.Integer.parseInt(Integer.java:499)
    Copy the code
  • B. View crash information
    • Thrown to indicate that the application is trying to convert a string to one of the numeric types, but that the string does not have the proper format.
    public class NumberFormatException extends IllegalArgumentException {
        static final long serialVersionUID = -2848938806368998894L;
    
        public NumberFormatException () {
            super();
        }
    
        public NumberFormatException (String s) {
            super (s);
        }
    
        static NumberFormatException forInputString(String s) {
            return new NumberFormatException("For input string: \"" + s + "\" "); }}Copy the code
  • C. Anomaly analysis in the project
    • Keyword Java errors. Lang. A NumberFormatException explicitly told us that this sentence is number format is unusual, then behind the For input string: “100 “prompt, which tells us that there was an error trying to convert “100” to a number, which is pretty sure.
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • The solution is simple: change to integer.parseint (str.trim()). Note that when converting a string to an Integer, you need to trim it.
  • G. Other extensions

1.4 Java. Lang. An IllegalStateException: fragments not attached to the Activity

  • A. Detailed crash log information
    java.lang.IllegalStateException: Fragment not attached to Activity
    Copy the code
  • B. View crash information
  • C. Anomaly analysis in the project
    • This exception occurs because the Fragment called a function such as getResource() that requires context Content before attaching the Activity.
    • This exception occurs because the Fragment calls a function such as getResource() that requires a Context before attaching the Activity. The solution is to wait until the calling code is written in OnStart().
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • Run the called code within the Fragment Attached life cycle.
    • Before calling a function that requires Context, add a judgment isAdded().
    if(isAdded()){// The isAdded method is provided by the Android system and is returned only after the Fragment has been added to the Activity to which it belongstrueactivity.getResourses().getString(...) ; }Copy the code
    • Second: as shown below
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (MainActivity) context;
    }
    
    @Override
    public void onDetach() {
        super.onDetach();
        if (activity != null) {
            activity = null;
        }
    }
    Copy the code
  • G. Other extensions
    • What happens: This error usually occurs when a time-consuming operation is performed in a fragment thread, and the thread calls getResources to update the UI after the execution. If the thread operation is not complete, then getActivity().concrete () is called to reload the activity or rotate the screen, and an error Fragment not attached to the activity is presented

1.5 ArrayIndexOutOfBoundsException Angle of the cross-border anomalies

  • A. Detailed crash log information
    • This exception indicates that the array is out of bounds
    java.lang.ArrayIndexOutOfBoundsException: 0
    	at com.example.mytest.CityAdapter.setDataNotify(CityAdapter.java:183)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    Copy the code
  • B. View crash information
    • Raises to indicate that an array has been accessed using an illegal index. The index is either negative or greater than or equal to the size of the array.
    public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
        private static final long serialVersionUID = -5116101128118950844L;
        public ArrayIndexOutOfBoundsException() {
            super();
        }
        public ArrayIndexOutOfBoundsException(int index) {
            super("Array index out of range: " + index);
        }
        public ArrayIndexOutOfBoundsException(String s) {
            super(s);
        }
        public ArrayIndexOutOfBoundsException(int sourceLength, int index) {
            super("length=" + sourceLength + "; index=" + index);
        }
        public ArrayIndexOutOfBoundsException(int sourceLength, int offset,
                int count) {
            super("length=" + sourceLength + "; regionStart=" + offset
                    + "; regionLength="+ count); }}Copy the code
  • C. Anomaly analysis in the project
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • In this case, the length should be judged before the array loop. If the index exceeds the upper and lower limits of length, an error will be reported. For example, int test[N] contains N elements from test[0] to test[n-1]. It is recommended not to exceed the length of the array (array.length) when reading.
    • A common situation in Android is that the header will also be used as the 0th position of the ListView in a pull-up refresh, which can easily be crossed if misjudged.
  • G. Other extensions

1.6 Constructor permission exception in IllegalAccessException method

  • A. Detailed crash log information
    Unable to instantiate application com.pedaily.yc.meblurry.App: java.lang.IllegalAccessException
    Copy the code
  • B. View crash information
    • An IllegalAccessException is thrown when an application attempts to reflectively create an instance (other than an array), set or get a field, or call a method, but the currently executing method cannot access the definition of the specified class, field, method, or constructor.
    public class IllegalAccessException extends ReflectiveOperationException {
        private static final long serialVersionUID = 6616958222490762034L;
        public IllegalAccessException() { super(); } public IllegalAccessException(String s) { super(s); }}Copy the code
  • C. Anomaly analysis in the project
    • The error message is that the constructor has the wrong permissions
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • There is a parameterless constructor that is designed to be private. Change it to public.
  • G. Other extensions
    • Android BroadcastReceiver in Java. Lang. IllegalAccessException solution, the reason for the error is mainly elsewhere in the app calls the default constructor, must increase the default constructor and access to public

Android 1.7. View. WindowManager $BadTokenException, dialog window abnormal

  • A. Detailed crash log information
    Unable to add window -- token android.os.BinderProxy@9a57804 is not valid; is your activity running?
    android.view.ViewRootImpl.setView(ViewRootImpl.java:907)
    Copy the code
  • B. View crash information
    • You can find this exception class in WindowManager and it is thrown when you try to add a view
    public static class BadTokenException extends RuntimeException {
        public BadTokenException() { } public BadTokenException(String name) { super(name); }}Copy the code
  • C. Anomaly analysis in the project
    • This exception indicates that a window cannot be added, usually because the view to which it is attached no longer exists.
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • There was a custom popover in the previous project, occasionally this error was reported. The solution is shown in the code below
    • The main logic is that in the popup of show or dismiss, the logical judgment is added to determine the existence of the host activity.
    */ public static void show(context context, @param isCancel) boolean isCancel) {if(context == null){
            return;
        }
        if (context instanceof Activity) {
            if (((Activity) context).isFinishing()) {
                return; }}if(loadDialog ! = null && loadDialog.isShowing()) {return; } loadDialog = new LoadLayoutDialog(context, isCancel); loadDialog.show(); } @param context */ public static void dismiss(context context) {if(context == null){
            return;
        }
        try {
            if (context instanceof Activity) {
                if (((Activity) context).isFinishing()) {
                    loadDialog = null;
                    return; }}if(loadDialog ! = null && loadDialog.isShowing()) { Context loadContext = loadDialog.getContext();if (loadContext instanceof Activity) {
                    if (((Activity) loadContext).isFinishing()) {
                        loadDialog = null;
                        return; } } loadDialog.dismiss(); loadDialog = null; } } catch (Exception e) { e.printStackTrace(); loadDialog = null; }}Copy the code
  • G. Other extensions
    • This exception is often reported when Dialog&AlertDialog, Toast, and WindowManager are not used correctly. The reasons are as follows:
      • 1. When the previous page did not destroy, the previous Activity received a broadcast. If the previous Activity performs uI-level operations, it will crash. Note the timing of UI refresh. It is recommended to use set_result instead of broadcast to refresh the UI, which is not intuitive and error-prone.
      • 2.Dialog pops up after Actitivty exits. When a Dialog calls the show method to display, it must have an Activity as the window carrier. If the Activity is destroyed, the Dialog window carrier will not be found. It is recommended to determine whether the Activity has been destroyed before the Dialog calls the show method.
      • The window type is not set to TYPE_SYSTEM_ALERT when the Service&Application dialog box is displayed or the WindowManager view is added. Before need dialog. The call show () method to add dialog. The getWindow () SetType (WindowManager. LayoutParams. TYPE_SYSTEM_ALERT).
      • On System 4.6.0, this issue will pop up if no suspension window permission is granted. Use Settings. CanDrawOverlays to determine whether you have this permission.
      • 5. Permissions caused by some unstable MIUI system bug, Toast is also treated as a system-level popup. The system Dialog popup on Android6.0 requires user manual authorization, and this error will be reported if the APP does not add SYSTEM_ALERT_WINDOW permission. It is necessary to add the system Dialog pop-up permission to app and dynamically apply for permission. If the first item is not met, there will be no permission and blink back; if the second item is not met, there will be no Toast.

1.8 Java. Lang. NoClassDefFoundError couldn’t find the abnormal class

  • A. Detailed crash log information
  • B. View crash information
    • If the Java VIRTUAL machine orClassLoaderAn instance attempts to load the definition of a class (as part of or for use in a normal method call)The newExpression to create part of a new instance), throws the definition of the class. A search class definition existed when compiling the currently executing class, but it could not be found again.
    public class NoClassDefFoundError extends LinkageError {
        private static final long serialVersionUID = 9095859863287012458L;
        public NoClassDefFoundError() { super(); } public NoClassDefFoundError(String s) { super(s); } private NoClassDefFoundError(String detailMessage, Throwable throwable) { super(detailMessage, throwable); }}Copy the code
  • C. Anomaly analysis in the project
    • The main cause of the problem: the number of methods is 65536 limit. Due to the changing requirements in actual development, there are more and more open source frameworks, most of which use third-party SDKS, resulting in the number of methods easily exceeding the 65536 limit. There is an error in Java. Lang. NoClassDefFoundError
  • D. Analysis of the process that causes crash logs
    • This error is caused by the total method limit for Android applications. Dalvik, a Java virtual machine on the Android platform, uses the native type short to index methods in the DEX file when executing Java applications in DEX format. This means that the total number of methods that can be referenced by a single DEX file is limited to 65536. APK usually contains a classes.dex file, so the total number of methods in an Android application can’t exceed that, which includes the Android framework, class libraries, and your own code. Android 5.0 and later use a runtime called ART, which natively supports loading multiple DEX files from APK files. When the application is installed, it precompiles, scans classes(.. The N).dex file is then compiled into a single.oat file for execution. Generally speaking, it is subcontracting.
  • F. Solutions
    • 64K solution
  • G. Other extensions
    • This exception represents an error thrown when a JVM or ClassLoader instance tries to load the class definition (usually as part of a method call or new expression to create an instance) and the class definition is not found.
    • [Solution] : The NoClassDefFoundError exception usually occurs when the compile environment and the runtime environment are inconsistent, which means that the Classpath or JAR package may have changed after the compile so that the JVM or ClassLoader cannot find the class definition during the runtime.
      • 1. Program by dex package. If the dependent DEX package deletes the specified class, an error will be reported when the initialization method is executed.
      • 2. When using third-party SDK or plug-in programming, an error will be reported if the class fails to be dynamically loaded or instantiated;
      • 3. When system resources are limited, when a large number of classes need to be loaded into memory, they are in competition, and some CalSS fail to compete, leading to failure of loading.
      • 4. Load and initialize a class failed (such as a static block behind Java. Lang. ExceptionInInitializerError exception), and then reference once again that this would prompt NoClassDefFoundErr error;
      • 5. The mobile phone system version or hardware device does not match (for example, the BLE device only supports SDK 18 or higher). The class referenced by the program does not exist in the earlier version, resulting in a NoClassDefFoundErr error.
      • Armeabi-v7a: armeabi-v7a: armeabi-v7a: armeabi-v7A: armeabi-v7A: armeabi-v7A: armeabi-v7A: armeabi-v7a: Armeabi-v7a: Armeabi-v7a

1.9 Android appears: Your Project path contains non-ASCII characters

  • A. Detailed crash log information
  • B. View crash information
  • C. Anomaly analysis in the project
  • D. Analysis of the process that causes crash logs
  • F. Solutions
    • Easy to solve, that is, your project path or project name contains Chinese, change the relevant name is good
  • G. Other extensions

About other content introduction

01. About blog summary links

  • 1. Tech blog round-up
  • 2. Open source project summary
  • 3. Life Blog Summary
  • 4. Himalayan audio summary
  • 5. Other summaries

02. About my blog

  • My personal website: www.yczbj.org, www.ycbjie.cn
  • Github:github.com/yangchong21…
  • Zhihu: www.zhihu.com/people/yang…
  • Jane: www.jianshu.com/u/b7b2c6ed9…
  • csdn:my.csdn.net/m0_37700275
  • The Himalayan listening: www.ximalaya.com/zhubo/71989…
  • Source: China my.oschina.net/zbj1618/blo…
  • Soak in the days of online: www.jcodecraeer.com/member/cont.
  • Email address: [email protected]
  • Blog: ali cloud yq.aliyun.com/users/artic… 239.headeruserinfo.3.dT4bcV
  • Segmentfault headline: segmentfault.com/u/xiangjian…