自学内容网 自学内容网

安卓学习中遇到的问题【bug】

安卓学习中遇到的问题

1Gradle下载慢怎么办?

Gradle下载慢怎么办?

distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-7.5-bin.zip

2 Could not resolve all files for configuration ‘:classpath‘. > Could not resolve com.android.tools

Could not resolve all files for configuration ‘:classpath‘. > Could not resolve com.android.tools

https://blog.csdn.net/AgonyAngela/article/details/138075256

在这里插入图片描述

3 sdk下载慢的解决办法

sdk下载慢的解决办法

4 为什么android studio代码提示很慢

为什么android studio代码提示很慢

缓解修复Android Studio卡顿,Kotlin代码提示慢

5 Android Studio开发遇到爆红@layout/activity_main does not contain a declaration with id `xx

Android Studio开发遇到爆红`@layout/activity_main` does not contain a declaration with id `xx

Alt + Enter,选择第二个

× suppress MissingInflatedld with an annotation

6 Android开发中Button背景颜色不能修改问题及解决方法

Android开发中Button背景颜色不能修改问题及解决方法

AndroidStudio无法改变Button背景颜色解决办法

把其中values/themes.xml文件

<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

parent后面的值改为Theme.MaterialComponents.DayNight.NoActionBar.Bridge

    <style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">

在这里插入图片描述

7 Android Studio Error: Activity class {com.example/com.example.MainActivity} does not exist.

Android Studio Error: Activity class {com.example/com.example.MainActivity} does not exist.原因及解决办法

https://blog.csdn.net/qq_43525355/article/details/88057367

8 android 运行时改代码吗,Android Studio 编译运行时安装的是上次打包的代码而不是修改后的代码…

android 运行时改代码吗,Android Studio 编译运行时安装的是上次打包的代码而不是修改后的代码…

https://blog.csdn.net/weixin_39845241/article/details/117551808

https://blog.csdn.net/niubitianping/article/details/117779567

9 FAILURE: Build failed with an exception.

项目目录有中文字符

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘D:\Desktop\���ļ�\HelloWorld\app\build.gradle’ line: 2

  • What went wrong:
    An exception occurred applying plugin request [id: ‘com.android.application’]

Failed to apply plugin ‘com.android.internal.application’.
Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. See http://b.android.com/95744 for details. This warning can be disabled by adding the line ‘android.overridePathCheck=true’ to gradle.properties file in the project directory.

10 Error while waiting for device: Nexus 6 API 34 is already running.

Error while waiting for device: Nexus 6 API 34 is already running. If that is not the case, delete C:\Users\lenovo.android\avd\Nexus_6_API_34.avd*.lock and try again.
远程主机强迫关闭了一个现有的连接。

11 A problem occurred evaluating project ‘:app’.

A problem occurred evaluating project ‘:app’. > Build was configured to prefer settings repositories over project repositories but repository ‘Google’ was added by build file ‘app\build.gradle’

依赖第三方jar包 glide

在这里插入图片描述

setting.grade中已经有了

repositories {
google()
mavenCentral()
}

在这里插入图片描述
只需在build.grade(:app)中配置就好了。

dependencies {
implementation 'com.github.bumptech.glide:glide:4.16.0
}

在这里插入图片描述

12 E/GlideExecutor: Request threw uncaught throwable

E/GlideExecutor: Request threw uncaught throwable
java.lang.SecurityException: Permission denied (missing INTERNET permission?)

没有网络请求的权限

在AndroidManifest.xml加入

 <uses-permission android:name="android.permission.INTERNET"/>

在这里插入图片描述

13 mWvMain.loadUrl(“javascript:alert('hello)”);为什么没弹出

mWvMain.loadUrl(“javascript:alert('hello)”);为什么没弹出

Android webview调用js代码无效 webView.loadUrl(“javascript:alert(‘hello’)”)

14 Android Toast.setGravity()失效,无作用原因及其修改方法!

Android Toast.setGravity()失效,无作用原因及其修改方法!

//在30+的版本不起作用
//E/Toast: setGravity() shouldn’t be called on text toasts, the values won’t be used
toastCenter.setGravity(Gravity.CENTER, 0, 0);

15 为什么没有这个类AlterDialog

import androidx.appcompat.app.AlertDialog;

AlertDialog.Builder builder=new AlertDialog.Builder(DialogActivity.this);

解决Android v4、v7包导入标红问题import android.support.v4.app.ActivityCompat;import android.support.v7.app

16 Installation did not succeed. The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

List of apks:
[0] ‘E:\AndroidStudioProjects\HelloWorld\app\build\intermediates\apk\debug\app-debug.apk’
Installation failed due to: ‘INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl707213382.tmp/base.apk (at Binary XML file line #80): Invalid taskAffinity name asdfghjkdfghj in package com.example.helloworld: must have at least one ‘.’ separator’
Retry
Failed to launch an application on all devices

在这里插入图片描述

17 新版本Fragment的API

这个是新版本的import androidx.fragment.app.Fragment;

import androidx.fragment.app.Fragment;
public class AFragment extends Fragment {
public class BFragment extends Fragment {

getSupportFragmentManager().beginTransaction().replace(R.id.fl_container, bFragment).commit();
getSupportFragmentManager().beginTransaction().add(R.id.fl_container, aFragment).commitAllowingStateLoss();

这个是被废弃的import android.app.Fragment;

import android.app.Fragment;
public class AFragment extends Fragment {
public class BFragment extends Fragment {

getFragmentManager().beginTransaction().replace(R.id.fl_container, bFragment).commit();
getFragmentManager().beginTransaction().add(R.id.fl_container, aFragment).commitAllowingStateLoss();

18 @layout/activity event does not contain a declaration with id btn event

@layout/activity event does not contain a declaration with id btn event

过一会就不报错了

    @SuppressLint("MissingInflatedId")

19 外部文件权限

fileNotfoundException: /storage/enulated/0/skypan/test.txt (pernission denied)

AndroidManifest.xml

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

如果是Android22+,还需要在
MainActivity

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);


原文地址:https://blog.csdn.net/qq_51625007/article/details/139308367

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!