1

每当我尝试在不同的机器上运行我的应用程序时,我都会收到此错误。我将粘贴堆栈跟踪和我的 java 类文件。我的项目的类路径 jar 中的所有 jar 都没有损坏,我已经从实时服务器机器上复制了它们。

堆栈跟踪:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Priority
    at org.smslib.Service.listSystemInformation(Service.java:113)
    at org.smslib.Service.initializeService(Service.java:103)
    at org.smslib.Service.<init>(Service.java:95)
    at org.smslib.Service.<clinit>(Service.java:90)
    at javaapplication1.GsmModem.doIt(GsmModem.java:59)
    at javaapplication1.GsmModem.Sender(GsmModem.java:40)
    at javaapplication1.Smslive.main(Smslive.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more
C:\Users\s\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

这是我的主要java类

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author s
 */
public class Smslive {


          private static String port = "COM5"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "Qualcomm"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+923455000010"; //Message Center Number e
    public static void main(String[] args) {



 GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
       String num1 = "somenumber";
       String num2 = "somenumber";
String number[] = {num1,num2};      //  Robot r = new Robot();
        //int keyCode = KeyEvent.VK_ENTER; // the A key
              try {


gsmModem.Sender("Mobileno", "String message"); // (tp, msg)
              } catch (Exception ex) {
                  System.out.println("exception"+ex);
              }


    }
}

这是 Gsm Modem.java 类

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;




import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class GsmModem
{
  private static String port;
  private static int bitrate;
  private static String modem;
  private static String modemPin;
  private static String smsc;
  private static String tp;
  private static String msgBody;

  public static void configModem(String p, int b, String m, String pi, String s)
  {
    port = p;
    bitrate = b;
    modem = m;
    modemPin = pi;
    smsc = s;
  }

  public void Sender(String tpnum, String message) throws Exception {
    tp = tpnum;
    msgBody = message;
    doIt();
  }

  public void doIt() throws Exception
  {
    OutboundNotification outboundNotification = new OutboundNotification();
    System.out.println("-----------------------------");
    System.out.println("*** author***");
    System.out.println("author");
    System.out.println("-----------------------------");
    System.out.println("Example: Send message from a serial gsm modem.");
    System.out.println(Library.getLibraryDescription());
    System.out.println("Version: " + Library.getLibraryVersion());
    SerialModemGateway gateway = new SerialModemGateway("modem.com1", port, bitrate, modem, "");
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSimPin(modemPin);

    gateway.setSmscNumber(smsc);
    Service.getInstance().setOutboundMessageNotification(outboundNotification);
    Service.getInstance().addGateway(gateway);
    Service.getInstance().startService();
    System.out.println();
    System.out.println("Modem Information:");
    System.out.println("  Manufacturer: " + gateway.getManufacturer());
    System.out.println("  Model: " + gateway.getModel());
    System.out.println("  Serial No: " + gateway.getSerialNo());
    System.out.println("  SIM IMSI: " + gateway.getImsi());
    System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
    System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
    System.out.println();

    OutboundMessage msg = new OutboundMessage(tp, msgBody);
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);

  //  System.out.println("Now Sleeping - Hit <enter> to terminate.");
   // System.in.read();
    Service.getInstance().stopService();
  }
  public class OutboundNotification implements IOutboundMessageNotification {
    public OutboundNotification() {
    }

    public void process(AGateway gateway, OutboundMessage msg) {
      System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
      System.out.println(msg);
    }
  }
}
4

1 回答 1

0

我通过重新安装 JDK 和重新安装 Netbeans IDE 解决了这个问题。我猜问题出在 JDK 的 LIB 文件夹中。

于 2016-10-03T10:06:07.493 回答