Android Studio 无法找到 ArrayList 类。

huangapple go评论75阅读模式
英文:

Android studio can't find ArrayList class

问题

首先,我已经使用Android Studio很多年了,但是以前从未发生过这种情况。

似乎Android Studio内部的ArrayList类突然消失了。我无法使用ArrayList,它总是显示*无法找到符号ArrayList*。

我尝试过清理重建,甚至多次无效地使缓存无效并重新启动,但都没有用。

```java
package dev.moutamid.testapp;

import java.util.ArrayList; //<--- 这里出错了

public class FragmentDashboard extends Fragment {

    private ArrayList<refUser> refUsersList = new ArrayList<>(); //<--- 这一行也是
}

我的Android Studio已经是最新版本。然后,我打开了一个新项目,尝试使用ArrayList,但它仍然没有显示。感觉在Studio中与ArrayList无关的内容都没有了。

昨天我遇到了Windows的蓝屏死机,今天又发生了这种情况。我正在使用Git存储库来备份我的项目。

有什么解决办法吗?我认为Git已经删除了ArrayList类,因为它之前已经损坏了几个文件。幸运的是,由于有备份,我才没有丢失。


<details>
<summary>英文:</summary>

First of all I&#39;ve been using Android studio for quite years but this has never happened before. 

It seems like android studio&#39;s inner ArrayList class has vanished out of a sudden. I can&#39;t use ArrayList. It always says *Can&#39;t find symbol ArrayList* 

I&#39;ve cleaned rebuild and even invalidated caches and restarted several times but all in vain.

package dev.moutamid.testapp;

import java.util.ArrayList; //<--- this gives error

public class FragmentDashboard extends Fragment {

private ArrayList&lt;refUser&gt; refUsersList = new ArrayList&lt;&gt;(); //&lt;--- and this line

}

My android studio is up to date. I then opened a new project and tried to use ArrayList but it was still not showing. Feels like there&#39;s nothing related to ArrayList in studio.

Yesterday I got BSOD (Blue screen of death of Windows) and today it&#39;s happening. I&#39;m using git repository to backup my project.

What could be the solution? 
I think Git has deleted ArrayList class because it already had corrupted several files before. I got luck due to the backups.

</details>


# 答案1
**得分**: 1

这真的很奇怪。建议您尝试以下步骤:
1. 检查Android Studio中的JDK并检查路径。如果您仍然面临这个问题,那么请安装一个从网上下载的新的JDK,并放入新的路径,然后尝试。
2. 如果这个方法也不起作用,备份所有文件并重新安装Android Studio。卸载当前版本,然后安装全新的版本。
3. 由于您之前遇到了蓝屏问题,强烈建议您重新安装Windows。您没有指定您使用的是哪个Windows版本,因此我假设您使用的是Windows 10。
   这个链接可能会对您有所帮助:https://support.microsoft.com/zh-cn/help/4000735/windows-10-reinstall
4. 请定期备份您需要的所有内容。

<details>
<summary>英文:</summary>

Well this is really weird. Would suggest you to try the following:
1. Check the jdk in android studio and check the path. If you still facing this problem then install a fresh jdk which you download online and put in the new path and try.
2. If this is also not working, back up all files and reinstall Android studio. Uninstall the current copy and install a fresh one.
3. Well since you have had a Blue screen issue, would highly recommend to do a fresh install of windows. You haven&#39;t specified which Windows version you using so I am assuming you are using Windows 10. 
This link should help you out for Windows 10 : https://support.microsoft.com/en-in/help/4000735/windows-10-reinstall
4. And please keep taking a backup of whatever you need regularly.

</details>



# 答案2
**得分**: 0

我正在猜测这是否可能:

1. 在 macOS 上,在控制台中输入 java -version 以检查当前安装的 Java 版本。例如,我输出了以下内容:

    ➜ ~ java -version
    java version "1.8.0_212"
    Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
    Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)

2. 检查 Android Studio 中项目结构的 SDK 位置中 JDK 的位置是否正确。例如,我的地址如下:

    /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

3. 或者在 Modules 中选择 app,尝试将属性的源/目标兼容性设置为什么?

希望对你有帮助~

<details>
<summary>英文:</summary>

I am guessing whether this is possible:

1. On macOS, enter java -version in the console to check the currently installed Java version. For example, I output the following:

    ➜ ~ java -version java version &quot;1.8.0_212&quot; Java(TM) SE Runtime
    Environment (build 1.8.0_212-b10) Java HotSpot(TM) 64-Bit Server VM
    (build 25.212-b10, mixed mode)

2. Check whether the JDK location in the SDK Location in Project Struture in Android Studio is correct. For example, my address is as follows:

    /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

3. Or select app in Modules and set the Source/Target Compatibility of Properties to try?

I hope it helps you~

</details>



huangapple
  • 本文由 发表于 2020年8月19日 01:13:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63473519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定