Java:无法访问其他类的方法

时间:2016-08-11 00:38:57

标签: java

第一类:Graph.java

public class prims {

    Graph g=new Graph();

    g.generateGraph(10,20); // Error here

}

第二课:prims.java

[0810/172408:ERROR:process_info.cc(608)] range at 0xf065375000000000, size 0x223 fully unreadable
[0810/172408:ERROR:process_info.cc(608)] range at 0xf06537b600000000, size 0x223 fully unreadable
[0810/172408:ERROR:process_info.cc(608)] range at 0x0, size 0x223 fully unreadable
[0810/172408:WARNING:in_range_cast.h(38)] value 2353380267576 out of range
[0810/172408:WARNING:in_range_cast.h(38)] value 2353380265134 out of range
[0810/172408:WARNING:in_range_cast.h(38)] value 2353380267606 out of range
[0810/172408:WARNING:in_range_cast.h(38)] value 2353380267012 out of range
[0810/172408:WARNING:in_range_cast.h(38)] value 2353381027936 out of range
[0810/172450:ERROR:process_info.cc(608)] range at 0x1d2c375200000000, size 0x190 fully unreadable
[0810/172450:ERROR:process_info.cc(608)] range at 0x1d2c37b800000000, size 0x190 fully unreadable
[0810/172450:ERROR:process_info.cc(608)] range at 0x0, size 0x190 fully unreadable
[0810/172450:WARNING:in_range_cast.h(38)] value 1718476346936 out of range
[0810/172450:WARNING:in_range_cast.h(38)] value 1718476344494 out of range
[0810/172450:WARNING:in_range_cast.h(38)] value 1718476346966 out of range
[0810/172450:WARNING:in_range_cast.h(38)] value 1718476346372 out of range
[0810/172450:WARNING:in_range_cast.h(38)] value 1718477109408 out of range
[0810/172648:ERROR:process_info.cc(608)] range at 0xfe7f375400000000, size 0x1dd fully unreadable
[0810/172648:ERROR:process_info.cc(608)] range at 0xfe7f37ba00000000, size 0x1dd fully unreadable
[0810/172648:ERROR:process_info.cc(608)] range at 0x0, size 0x1dd fully unreadable
[0810/172648:WARNING:in_range_cast.h(38)] value 2052969141816 out of range
[0810/172648:WARNING:in_range_cast.h(38)] value 2052969139374 out of range
[0810/172648:WARNING:in_range_cast.h(38)] value 2052969141846 out of range
[0810/172648:WARNING:in_range_cast.h(38)] value 2052969141252 out of range
[0810/172648:WARNING:in_range_cast.h(38)] value 2052969903328 out of range
[0810/172735:ERROR:process_info.cc(608)] range at 0x82f837bc00000000, size 0x258 fully unreadable
[0810/172735:ERROR:process_info.cc(608)] range at 0x82f8382200000000, size 0x258 fully unreadable
[0810/172735:ERROR:process_info.cc(608)] range at 0x0, size 0x258 fully unreadable
[0810/172735:WARNING:in_range_cast.h(38)] value 2579177674296 out of range
[0810/172735:WARNING:in_range_cast.h(38)] value 2579177671854 out of range
[0810/172735:WARNING:in_range_cast.h(38)] value 2579177674326 out of range
[0810/172735:WARNING:in_range_cast.h(38)] value 2579177673732 out of range
[0810/172735:WARNING:in_range_cast.h(38)] value 2579178437024 out of range

错误显示为:“语法错误,插入”)“完成MethodDeclaration”

为什么我在创建图形实例后无法访问该方法?

1 个答案:

答案 0 :(得分:1)

在Java中,您的代码语句应该是某些方法

的一部分

在你的情况下,至少是main方法,如果那是你的主要类。

代码不能只是在类体内部,在任何块之外

以下代码可能有助于您实现的目标

public class prims {

    public static void main(String args[]) {
        Graph g=new Graph();

        g.generateGraph(10,20); // Error here
    }

}