Android Studio 无法识别 Log.e

Android Studio won't recognize Log.e

我是一名新程序员,我正在学习 java 以进行 android 开发。问题是当我在 Android Studio 中使用 Log.e 时,它说:

can not resolve symbol e

我在程序的第一行写了 import android.util.Log; 但它仍然不起作用。我也试过重新启动 android studio,重新启动 LogCat,创建一个新项目,重新启动系统并启动 android 模拟器然后编码,但它仍然不起作用。

在某个函数内重试。你写在class里,所以Android工作室认为Log.e是类型定义。

您需要将 Log.e() 放在方法中。就目前而言,它只是坐在 class 中。你需要这样的东西。

public class MyClass {
    public void MyMethod(){
        Log.e(...);
    }
}