error: class SplashScreen is public, should be declared in a file named SplashScreen.java public class SplashScreen extends AppCompatActivity

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

error: class SplashScreen is public, should be declared in a file named SplashScreen.java public class SplashScreen extends AppCompatActivity

问题

我正在尝试编写一个程序,但是我遇到了这个编译器错误:

错误:class SplashScreen 是public的,应该在一个名为 SplashScreen.java 的文件中声明
public class SplashScreen extends AppCompatActivity {

这是我的代码:

public class SplashScreen extends AppCompatActivity {
    TextView tvSplash;

我该如何修复这个问题?

英文:

I am trying to write a program, but I'm getting this compiler error:

error: class SplashScreen is public, should be declared in a file named SplashScreen.java
public class SplashScreen extends AppCompatActivity {

here is my code :

public class SplashScreen extends AppCompatActivity {
TextView tvSplash;

How can I fix this?

答案1

得分: 1

如果您在同一个名为 AppCompatActivity.java 的 Java 文件中与 AppCompatActivity 同时有 SplashScreen,则您需要移除 SplashScreen 前面的 public 关键字,以确保它们能在同一个 Java 文件中:

class SplashScreen extends AppCompatActivity { // 在同一个 Java 文件中

否则,如果您仍希保持 public 关键字,您需要创建一个新的 Java 文件,命名为 SplashScreen.java(最好放在相同的包中):

public class SplashScreen extends AppCompatActivity { // 在单独的 Java 文件中
英文:

If you have SplashScree in the same java file with AppCompatActivity called AppCompatActivity.java,then you need to remove public for SplashScree to make sure they can in the same java file

class SplashScreen extends AppCompatActivity {// in the same java file

Otherwise,you need to create a new java file called SplashScreen.java(would be better in the same package) if you still want to keep public key word

 public class SplashScreen extends AppCompatActivity {// in separate java file

huangapple
  • 本文由 发表于 2020年10月7日 10:41:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64236438.html
匿名

发表评论

匿名网友

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

确定