需要帮助解决静态方法 [英] Need help Solving static methods

查看:81
本文介绍了需要帮助解决静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:

我需要帮助请我还在学习Java ...

这是我的代码中我遇到问题的一部分。

问题出在public static void main(String [] args){

方法main不能声明为static;静态方法只能在静态或顶级类型中声明。

展开 | 选择 | Wrap < span class =codeDivider> | 行号

解决方案

< blockquote>


大家好:

我需要帮助请我还在学习Java ...

这是部分我遇到问题的代码。

问题出在public static void main(String [] args){

方法main不能声明为static;静态方法只能在静态或顶级类型中声明。鉴于缩进级别,在主要方法定义之前应该是其他代码。

展开 | 选择 | 换行 | 行号


谢谢Jos,我发现了这个错误。

现在我在线程中有一个异常main java.lang.NullPointerException

at company.Employee。< init>(Employee.java:141)

at company.Employee.main(Employee.java:250)


我认为它必须归功于我的arraylist。


第141行

展开 | 选择 | Wrap | 行号


没关系我解决了我做过的问题不需要那个陈述。

但是现在当我运行程序时,我得到了一个

异常的主题" main" java.lang.NullPointerException

at company.Employee.displayMatch(Employee.java:217)

at company.Employee.main(Employee.java:266)< br / >

谢谢

nomad


Hi everyone:
I need help Please I''m still learning Java...
Here is part of my code where I''m having problems.
Problem is at public static void main(String[] args) {
The method main cannot be declared static; static methods can only be declared in a static or top level type..

Expand|Select|Wrap|Line Numbers

解决方案

Hi everyone:
I need help Please I''m still learning Java...
Here is part of my code where I''m having problems.
Problem is at public static void main(String[] args) {
The method main cannot be declared static; static methods can only be declared in a static or top level type. Given the indentation level there should
be some other code before your main method definition.

Expand|Select|Wrap|Line Numbers


Thanks Jos, I found the mistake.
Now I have a Exception in thread "main" java.lang.NullPointerException
at company.Employee.<init>(Employee.java:141)
at company.Employee.main(Employee.java:250)

I think it has to due to my arraylist.

line 141 is

Expand|Select|Wrap|Line Numbers


Never mind I solved that problem I did not need that statement.
But now when I run the program I get a
Exception in thread "main" java.lang.NullPointerException
at company.Employee.displayMatch(Employee.java:217)
at company.Employee.main(Employee.java:266)

thanks
nomad


这篇关于需要帮助解决静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆