英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论