Tag Archives: Android

[Solved] Click the play button to display: e/mediaplayer: error (1, – 2147483648)

Problem Description:

Click the play button to display:
e/mediaplayer: error (1, – 2147483648)
e/mediaplayer: error (1, – 2147483648)


Cause analysis:

Although the package service is created and the package name is displayed as follows:


an error will occur if the code is written as follows:

mediaPlayer.setDataSource(context,Uri.parse("android.resource://com.example.homework07.service/" + musics[musicIndex]));

Solution:

Delete the. Service in the code as follows

mediaPlayer.setDataSource(context,Uri.parse("android.resource://com.example.homework07/" + musics[musicIndex]));

Errorjava.lang.NullPointerException(no error message)

Solve the error: error: java.lang.nullpointerexception (no error message)

1、 Analyze the cause

Android studio often has dependencies or configuring related errors, which are generally caused by the conflict between Android gradle plugin version and gradle version and project files.

2、 Solution

Change the appropriate Android gradle plugin version and gradle Version (which version is appropriate may need to be tried)

3、 Specific operation

1. Through file – & gt; Project structure… Enter the project structure interface

2. In the project structure interface, select project, click the lower triangle, and select the program version to be installed

Then click OK, and Android studio will automatically make version changes to Android gradle plugin version and gradle version

Note that : Android gradle plugin version matches gradle version. Refer to the link: https://developer.android.com/studio/releases/gradle-plugin?hl=zh -cn

3. Recompile the program and solve the error

[Solved] Android DataBinding Error: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 fragment Changes to Fragm

Android databinding error: Java. Lang. ArrayIndexOutOfBoundsException: length = 2; Index = 2 replace fragment with fragmentcontainerview

Preface bug replacing fragmentcontainerview

preface

When fixing the bug today, I upgraded the library associated with the project. After upgrading, an error appears in the databinding. Unexpectedly, it is still java.lang.arrayindexoutofboundsexception: length = 2; Index = 2, it’s still a list position error,???Full of question marks

BUG

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx, PID: 27182
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx/com.xxx.activity.main.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3898)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4081)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2462)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8393)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1211)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1268)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1268)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1268)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1268)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:719)
        at com.xxx.databinding.ActivityMainBindingImpl.<init>(ActivityMainBindingImpl.java:28)
        at com.xxx.DataBinderMapperImpl.internalGetViewDataBinding0(DataBinderMapperImpl.java:378)
        at com.xxx.DataBinderMapperImpl.getDataBinder(DataBinderMapperImpl.java:663)
        at androidx.databinding.MergedDataBinderMapper.getDataBinder(MergedDataBinderMapper.java:74)
        at androidx.databinding.DataBindingUtil.bind(DataBindingUtil.java:199)
        at androidx.databinding.DataBindingUtil.bindToAddedViews(DataBindingUtil.java:327)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:306)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
        at com.xxx.activity.main.MainActivity.onCreate(MainActivity.kt:72)
        at android.app.Activity.performCreate(Activity.java:8121)
        at android.app.Activity.performCreate(Activity.java:8109)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3871)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4081) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2462) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:219) 
        at android.app.ActivityThread.main(ActivityThread.java:8393) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) 

After troubleshooting, I suspect that the fragment is used in the page, because the problem will not occur when starting other pages without this data binding;

Click the page layout XML to see the prompt:

replace the & lt; fragment > tag with FragmentContainerView.

Replace fragmentcontainerview

Replace the fragment with fragmentcontainerview according to the prompt, run it again, and no longer report “Java. Lang. ArrayIndexOutOfBoundsException: length = 2; “Index = 2” is wrong, but a new error is reported:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx, PID: 27863
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx/com.xxx.activity.main.MainActivity}: java.lang.IllegalStateException: Activity com.xxx.activity.main.MainActivity@1f5b1e does not have a NavController set on 2131296506
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3898)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4081)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2462)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8393)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
     Caused by: java.lang.IllegalStateException: Activity com.xxx.activity.main.MainActivity@1f5b1e does not have a NavController set on 2131296506
        at androidx.navigation.Navigation.findNavController(Navigation.java:61)
        at com.xxx.activity.main.MainActivity.onCreate(MainActivity.kt:75)
        at android.app.Activity.performCreate(Activity.java:8121)
        at android.app.Activity.performCreate(Activity.java:8109)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3871)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4081) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2462) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:219) 
        at android.app.ActivityThread.main(ActivityThread.java:8393) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) 

This problem is reported in obtaining the navcontroller. After searching the StackOverflow, we found the new method of fragmentcontainerview to obtain the navcontroller

reference resources: https://stackoverflow.com/questions/64170603/replace-the-fragment-tag-with-fragmentcontainerview


// FragmentContainerView
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment
navController = navHostFragment.navController
// Fragment
//navController = Navigation.findNavController(this, R.id.fragment)

// Set the tab bar to bind to the fragment
NavigationUI.setupWithNavController(binding.bottomNavigationView, navController)

confusion

-keepnames class androidx.navigation.fragment.NavHostFragment
-keepnames class com.google.android.gms.maps.SupportMapFragment

Finish

Re-run and solve the problem.

Error resource Android datalogcornerradius not found

Error: resource Android: attr/dialogcornerradius not found

1. Problem description

Running the Android studio program generates an error error error: resource Android: attr/dialogcornerradius not found

2. Analyze the causes

Compilesdkversion, buildtoolsversion and targetsdkversion do not match

3. Solutions

Set compilesdkversion and buildtoolsversion to high version and targetsdkversion to low version

4. Specific operation steps

Step 1: check the version numbers of compile SDK version, build tools version and targetsdkversion

Step 2: in the project structure interface, select modules and modify the version numbers of compile SDK version and build tools version

Requirement: compile SDK version and build tools version should be higher than targetsdkversion

Step3: Step 2 after modifying the version number, Android studio will automatically update. After the update, run the program again to solve the error problem.

Error:Could not create the Java Virtical Machine. Error: A fatal exception has occurred. program

I’m in Android Studio – & gt; help–> After editing cost VM options modifies the configuration (because the word is misspelled), Android studio cannot be opened. It is useless to modify studio64.vmoptions in the bin directory, uninstall and reinstall, There are the following errors when opening the command line:
it is obvious that I misspelled the word class in the process of configuration

actually, it can’t be started because my android studio does not start the Android studio I re downloaded by default, but the residual file of the Android studio with incorrect configuration.
solution: find the directory: ~ /. Config/Google/androidstudio2020.3/studio.vmoptions, Replace the correct configuration and restart it

[Solved] Android 5.1 code compilation error: Unsupported reloc 43

When compiling Android 5.1 code, I encountered the following error

prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: out/host/linux-x86/obj32/SHARED_LIBRARIES/libnativehelper_intermediates/JNIHelp.o: unsupported reloc 43 against global symbol std::string::_Rep::_S_empty_rep_storage
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: out/host/linux-x86/obj32/SHARED_LIBRARIES/libnativehelper_intermediates/JNIHelp.o: unsupported reloc 43 against global symbol std::string::_Rep::_S_empty_rep_storage
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: out/host/linux-x86/obj32/SHARED_LIBRARIES/libnativehelper_intermediates/JNIHelp.o: unsupported reloc 43 against global symbol std::string::_Rep::_S_empty_rep_storage
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:235: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:235: error: unsupported reloc 43
libnativehelper/JNIHelp.cpp:310: error: unsupported reloc 43
libnativehelper/JNIHelp.cpp:311: error: unsupported reloc 43
libnativehelper/JNIHelp.cpp:332: error: unsupported reloc 43
clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target ‘out/host/linux-x86/obj32/lib/libnativehelper.so’ failed
make: *** [out/host/linux-x86/obj32/lib/libnativehelper.so] Error 1
make: *** Waiting for unfinished jobs…

According to the error message above, we can see that the root cause is due to the ld error

prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld

Solution:

cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld

[Solved] Android Studio Run Error: Error while executing: am start -n

Error details, problem causes and Solutions

Error reporting details

08/19 09:54:18: Launching app
$ adb install-multiple -r -t D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_4.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_9.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_3.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_8.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_6.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_5.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\dep\dependencies.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_7.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_2.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_1.apk D:\work\self\CallAutoRecord\app\build\intermediates\resources\instant-run\debug\resources-debug.apk D:\work\self\CallAutoRecord\app\build\intermediates\split-apk\debug\slices\slice_0.apk D:\work\self\CallAutoRecord\app\build\intermediates\instant-run-apk\debug\app-debug.apk 
Split APKs installed in 10 s 564 ms
$ adb shell am start -n "com.guoqi.callautorecord/com.guoqi.callautorecord.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Error while executing: am start -n "com.guoqi.callautorecord/com.guoqi.callautorecord.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.guoqi.callautorecord/.MainActivity }
Error type 3
Error: Activity class {com.guoqi.callautorecord/com.guoqi.callautorecord.MainActivity} does not exist.

Error while Launching activity

Cause of problem

The mobile phone system bug did not uninstall the app completely, resulting in installation failure and failure to run.

Solution

First go to the SDK \ platform tools path and find the ADB command
. Then, in the current directory, open the command line window and enter ADB devices .

Confirm that the mobile phone is connected, then use ADB to uninstall, enter the command, ADB uninstall com.guoqi.callautorecord ( com.guoqi.callautorecord is my own package name, and I want to change it to my own)
is installed successfully, as shown in the figure below

[Gradle is Stucked in Building Runing] log Error: Timeout waiting to lock journal cache

Recently, gradle often uses the card build running
the Mac computer can see similar errors printed on the console. The win10 system doesn’t tell you and gets stuck silently.

* What went wrong:
Gradle could not start your build.
> Cannot create service of type BuildTreeActionExecutor using method LauncherServices$ToolingBuildTreeScopeServices.createActionExecutor() as there is a problem with parameter #1 of type List<BuildActionRunner>.
   > Could not create service of type FileAccessTimeJournal using GradleUserHomeScopeServices.createFileAccessTimeJournal().
      > Timeout waiting to lock journal cache (C:\Users\XXX\.gradle\caches\journal-1). It is currently in use by another Gradle instance.
        Owner PID: 8128
        Our PID: 14108
        Owner Operation: 
        Our operation: 
        Lock file: C:\Users\XXX\.gradle\caches\journal-1\journal-1.lock

The log can be seen under the. Gradle/daemon directory of win10. By the way, gradle also dumps the memory. The MAC is not very large. It is estimated that the C disk will be full in a few days

check the 8128 process and find that it is a java program

reset gradle JDK version 11.0.11 in project structure
no jamming exception is found after reset.

[Solved] Invalid Gradle JDK configuration found. Open Gradle Settings Change JDK location

The project was fine before it was opened for a period of time, and then an error was suddenly reported after it was opened. After understanding it, it is found that deleting the gradle.xml file in the. Idea file and then rebuilding it can be generated automatically;

After comparing the previous documents, it is found that a label is missing in the document:

<option name="gradleJvm" value="11" />

The value values of different JDK versions are different, so to be on the safe side, do not modify or add the values inside. Just delete the file and regenerate it;

Android 8.1 compilation error Jack server problem

Compile Android 8.1 and report errors related to Jack server
Jack server is an Android source code compilation tool. Used in Android 6.0 ~ Android 8.1 source code. Later versions are obsolete.

Error type 1:
communication error with Jack server (58), try ‘Jack diagnosis’ or see Jack server log
failed to contact Jack server: problem reading/home/user3 /. Jack server/client.pem. Try’ Jack diagnosis’

Error type 2:
Jack server failed to (RE) start, try ‘Jack diagnose’ or see Jack server log

Solution 1:

Open ~ /. Jack settings and ~ /. Jcak server/config.properties to change to other port numbers. Like 8976/8977
note that the two corresponding port numbers in the two files should be consistent


idea 2:
delete ~ /. Jack settings and ~ /. Jcak server/config.properties and recompile

Idea 3: JDK version problem
in my practice, openjdk1.8.0.292 will report that the port is occupied
the test method runs./prebuilds/SDK/tools/Jack diagnosis
printing the log will prompt that the port is occupied. For other unused ports, this is still the case
the solution is to use the JDK provided with the Android source code. Path: prebuilds/JDK/
you can also download other versions of openjdk, such as 1.8.0.141
uninstall the server JDK,
remove the openjdk (if installed). First, check which openjdk package is installed.

dpkg –list | grep -i jdk

To remove the openjdk package:

apt-get purge openjdk*

Check that all openjdk packages have been uninstalled:

dpkg –list | grep -i jdk

Configure the Android directory JDK to ~ /. Bashrc

export JAVA_ Home = {absolute path of your own Android source code} prebuilds/JDK/jdk8/Linux x86
export JRE_ HOME=

J

A

V

A

H

O

M

E

/

j

r

e

e

x

p

o

r

t

C

L

A

S

S

P

A

T

H

=

.

:

{JAVA_ HOME}/jre export CLASSPATH=.:

JAVAH​OME/jreexportCLASSPATH=.:{JAVA_ HOME}/lib:

J

R

E

H

O

M

E

/

l

i

b

e

x

p

o

r

t

P

A

T

H

=

.

:

{JRE_ HOME}/lib export PATH=.:

JREH​OME/libexportPATH=.:{JAVA_ HOME}/bin:$PATH

Effective changes:
source ~ /. Bashrc
recompile.

View the error report after Android APK confusion

It is not convenient for APK to view the log after confusion, and the class and method names are shortened
you can view the corresponding class names and method names before and after confusion in the mapping.txt file generated during confusion
you can also use the retract in the SDK \ tools \ Proguard \ bin path to recover the original class name and method name. First copy the error log to a TXT file, such as log.txt. You can then use the command:

Trace mapping file path log file path, such as

retrace D:\mapping.txt D:\log.txt

Before treatment

After treatment