[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1773
  • Last Modified:

Problem -- 'No main classes found' error trying to run program

Hi,

I was trying to, hoping to, test out a small program and while it compiles and builds okay, I cannot run it. When I try to run it, a dialog box pops up saying "No main classes found", and I am suppose to select a class from the list, but the list is empty.

I'm using the NetBeans 5.0 IDE
class name is SNMPTest
filename is SNMPTest.java

While searching for a solution on the web, I found a Sun tech note that discussed this and described how to set a main class through the project properties. I tried that, I receive an error stating it cannot find the class.

Being new to Java I must have something boned up in my code, but I can't find it.

I have successfully compiled and run a number of programs in the NetBeans IDE, and I stared and compared those that worked with this, and really can't find any major differences.

I would appreciate it if anyone could help me resolve this. - code below

Thanks,
Jeff

package SNMPTest.snmp4j.org;
import java.io.IOException;
import java.util.Vector;
import org.snmp4j.*;
import org.snmp4j.mp.*;
import org.snmp4j.security.*;
import org.snmp4j.smi.*;
import org.snmp4j.transport.*;
import org.snmp4j.util.*;
import org.snmp4j.event.ResponseEvent;
import java.util.StringTokenizer;
import org.snmp4j.log.LogFactory;
import org.snmp4j.log.Log4jLogFactory;
import org.snmp4j.asn1.BER;

/**
 *
 * @author
 */
public class SNMPTest {
    CommunityTarget     target = new CommunityTarget();
    Address             address = GenericAddress.parse("105.37.49.14/161");
    OctetString         community = new OctetString("public");
    PDU                 pdu = new PDU();
    int                 version = SnmpConstants.version2c;
    int                 retries = 1;
    int                 timeout = 3000;
    int                 pduType = PDU.GET;
    int                 maxRepitions = 10;
    int                 nonRepeaters = 0;
   
       
    /** Creates a new instance of SNMPTest */
    public SNMPTest() {
        TransportMapping    transport;
        Snmp                snmp;
       

        setTarget();
        setPDU();        
       
        try{
            transport = new DefaultUdpTransportMapping();
            snmp = new Snmp(transport);
            snmp.listen();
            ResponseEvent response = snmp.send(pdu, target);
            PDU responsePDU = response.getResponse();
            Address peerAddress = response.getPeerAddress();
            System.out.println(responsePDU);
        }
        catch (IOException e){
            System.out.println(e.getMessage());
        }
    }
   
    public void setTarget(){
        //setup the target
        target.setVersion(SnmpConstants.version2c);
        target.setAddress(address);
        target.setRetries(1);
        target.setTimeout(3000);        
    }
   
    public void setPDU(){
        //setup the PDU ==> the payload
        pdu.setType(PDU.GET);
        pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
        pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.1.0")));
       
    }
   
    public static void main() {
        SNMPTest    snmptest = new SNMPTest();
     }
       
}
0
jpetter
Asked:
jpetter
  • 2
  • 2
  • 2
  • +2
3 Solutions
 
StillUnAwareCommented:
change

public static void main() {

to

public static void main(String[] args) {
0
 
appxpeteCommented:
I think the main() method needs to have a String[] as an argument.

Like this:

public static void main(String[] args)
0
 
CEHJCommented:
>>

public static void main() {
        SNMPTest    snmptest = new SNMPTest();
     }
       
>>


should be

public static void main(String[] args) {
        SNMPTest    snmptest = new SNMPTest();
     }
       
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CEHJCommented:
Sorry - didn't refresh
0
 
jpetterAuthor Commented:
Many thanks to all....that worked like a charm.

Thanks again,
Jeff
0
 
haggersrCommented:
I am now receiving the same error. I am using v6.5.1 with jdk1.6 on xpsp3. The code was working fine and then next day when running the debugger got same message. Snippet is attached. I am new to netbeans (using for 3 months) but not IDE's or Java. There is definetly something funky going on here.
package com.utc.pw.z515;
 
/**
 * Declare Main class
 *
 * This main class entry point is just an unobfuscated proxy
 */
public class Main
{
 
  /**
   * Main Method
   *
   * @param args Command line arguments
   * @throws java.lang.Throwable
   */
  public static void main(String[] args) throws Throwable
  {
    com.utc.pw.z515.core.Nexus.main(args);
  }
}

Open in new window

0
 
StillUnAwareCommented:
I can only guess, but can it be that the class com.utc.pw.z515.core.Nexus has no method declared as
  public static void main(String[] ...)

and can You post an exact exception text You are getting?
0
 
haggersrCommented:
Solution is incorrect. NetBeans has a bug in it the appears sporadically. I founf a quick woraround. If you create a new project from a sample for instance. build and run it and it works.
It will "automagically" correct your faulty project. Netbeans developers should detrmine the root cause for the bug becuase it is real and apparently elusive (or hard to repeat). My code is proprietary so they will nee to look elsewhere as to how the error gets induced. Perhaps by understnding how creating a new project in the IDE corrects the faulty project they can work in reverse.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now