[Android] The bug I encountered

1. PopupWindow appears Unable to add window-token null is not valid; is your activity running?
Reference 1
PopupWindow appears android.view.WindowManager$BadTokenException: Unable to add window-token null is not valid; is your activity running? Because PopupWindow needs to be attached to a created Activity, then this exception means that your Activity has not been created yet. This situation is likely to be caused by calling in onCreate() or onStart() .

2. Android error: failed linking file resources
(1) Check whether there is a problem in your own XML file. In all likelihood, it is the XML problem.
Generally, the xml file name will not turn red. You must manually click on the recently modified xml file to check if there is any red error.

(2) One or two is a version problem: If you encounter the following content, error: resource android:attr/dialogCornerRadius not found.it may be a version problem,
refer to 1: https://blog.csdn.net/qq_35366269/article/details/89239440
Reference 2: https:// blog.csdn.net/weixin_43465451/article/details/83185112
The statement in reference 1 is: change the targetSdkVersion and compileSdkVersion in the build.gradle file in the current project to 28:
Insert picture description here

3. Android Studio prompt Failed to resolve: com.android.support.constraint:constraint-layout:1.0.2
reference: https://blog.csdn.net/qq_36317441/article/details/77451570

//    compile 'com.android.support.constraint:constraint-layout:1.0.1'
修改为:
    implementation "com.android.support.constraint:constraint-layout:1.1.3"

4.
Error message:

Failed to parse XML in E:\AndroidStudio_Projects\Project5Filed\Field_2019\app\src\main\AndroidManifest.xml
ParseError at [row,col]:[24,5]
Message: expected start or end tag
Affected Modules: app

Solution:
Modify the annotation method:

<!--    //鉴权所需该权限获取进程列表-->

5. Error: package okhttp3 does not exist

Solution:
modify the build.gradle file in the app directory and add the following code to dependencies in the build.gradle file and import this library.

compile 'com.squareup.okhttp3:okhttp:3.4.1'

6. The number of canvas.save (Canvas.ALL_SAVE_FLAG) parameters is incorrect.
Solution:

canvas.save(Canvas.ALL_SAVE_FLAG); 
改为:
canvas.save();

7. Import androidx.fragment.app.Fragment and import android.app.Fragment cannot be converted to each other in fragment.
Solution:

Use androidx.fragment.app.Fragment to switch the interface in Android studio, you may encounter this problem:

Since the Android studio version has been updated from version 2.3 to version 3.5, there have been some problems in using android.support.v4.app.Fragment to achieve layout switching, such as the inability to import Fragment in the v4 package.
Let me share with you. I myself use androidx.fragment.app.Fragment to implement Fragment interface switching.
In fact, the problem lies in the Fragment page loading problem using the FragmentTransaction class.
In the V4 package, the method used to load each Fragment fragment layout is as follows

首先创建一个fragmentManager对象:
private FragmentManager fragmentManager = null; 
this.fragmentManager = getFragmentManager();

然后利用fragmentManager对象创建一个FragmentTransaction对象:
FragmentTransaction transaction = this.fragmentManager.beginTransaction(); 

最后使用FragmentTransaction中的对象进行Fragment页面布局的加载。

In the package supported by androidx: create the FragmentTransaction object directly, and then call the method in the object to load the Fragment page layout

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

8、Location specified by ndk.dir (xxx) did not contain a valid NDK and and couldn’t be used

There are two reasons for the exception:
1: The format of the path is wrong (in fact, I thought of this problem from the beginning, I opened it directly with NotePad++, and there was no error prompt)
2: To be specific to the ndk version

Solution:
Open local.properties and delete the line of ndk path inside.

9、 java.lang.UnsatisfiedLinkError: No implementation found for int com.baidu.mapsdkplatform.comjni.tools.JNITools.initClass(java.lang.Object, int) (tried Java_com_baidu_mapsdkplatform_comjni_tools_JNITools_initClass and Java_com_baidu_mapsdkplatform_comjni_tools_JNITools_initClass__Ljava_lang_Object_2I)

This is a problem with Baidu Maps. Go to the official website and download the latest version of the so library and jar package. The so library is placed in the jniLibs folder, the jar package is placed in the libs folder, and you can run it.

10、

java.lang.RuntimeException: Unable to start activity ComponentInfo
{
    
    com.ding.admin.newfieldtest/com.ding.admin.newfieldtest.MainActivity}: 
android.view.InflateException: 
Binary XML file line #2: 
Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout

Just replace androidx.constraintlayout.ConstraintLayout with LinearLayout

11、

Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class androidx.core.view.ViewPager
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class androidx.core.view.ViewPager
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path: DexPathList[[zip file "/data/app/com.ding.admin.newfieldtest-qqOV5pUaEJpTK0BXHHuxfw==/base.apk"],nativeLibraryDirectories=[/data/app/com.ding.admin.newfieldtest-qqOV5pUaEJpTK0BXHHuxfw==/lib/arm64, /data/app/com.ding.admin.newfieldtest-qqOV5pUaEJpTK0BXHHuxfw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)

Solution:

androidx.core.view.ViewPager
换成:
androidx.viewpager.widget.ViewPager

控件如下就不报错了:

<androidx.viewpager.widget.ViewPager
	    android:id="@+id/viewPager"
	    android:layout_width="match_parent"
	    android:layout_height="match_parent"
	    android:layout_alignParentTop="true"
	    android:layout_above="@id/viewGroup"
	    android:layout_marginBottom="10dp"
	    >

Guess you like

Origin blog.csdn.net/qq_30885821/article/details/109015898