首页上一页 1 下一页尾页 8 条记录 1/1页
请指教,java中短信猫的使用(仿照java项目开发例题六企业快信)
发表在Java图书答疑
2008-10-11
是否精华
是
否
版块置顶:
是
否
import javax.swing.*;
import BestMail.*;
import java.awt.*;
import java.awt.event.*;
public class Shoujifasong {
public static void main(String[] args) {
Fasong fs=new Fasong();
}
}
class Fasong extends JFrame implements ActionListener{
JTextField fasongHao=new JTextField(10);
JTextField fasongText=new JTextField(10);
JButton fasongButton=new JButton("发送");
smssend smssender=null;
Fasong(){
JPanel Jnorth=new JPanel();
Jnorth.add(new JLabel("手机号码:"));
Jnorth.add(fasongHao);
JPanel Jcenter=new JPanel();
Jcenter.add(new JLabel("发送内容:"));
Jcenter.add(fasongText);
add(Jnorth,BorderLayout.NORTH);
add(Jcenter,BorderLayout.CENTER);
add(fasongButton,BorderLayout.SOUTH);
fasongButton.addActionListener(this);
setSize(200,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(smssender.GSMModemInitNew("COM4", "9600", null, "GSM", true, "YIWU-IJDD-****-****")){
byte[] sendtest=smssender.getUNIByteArray(fasongText.getText());
if(!smssender.GSMModemSMSsend(null, 8, sendtest, fasongHao.getText(), false)){
System.out.println("发送短信失败"+smssender.GSMModemGetErrorMsg());
}
}
}
}
以上是我写的段使用短息猫的代码,BestMail.jar文件我已经加载了,短息猫连接也没问题(利用VB开发的软件使用的非常好,但是在java中就不行了,奇怪!),运行时始终出现如下错误提示,麻烦高人指点:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Fasong.actionPerformed(Shoujifasong.java:33)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
import BestMail.*;
import java.awt.*;
import java.awt.event.*;
public class Shoujifasong {
public static void main(String[] args) {
Fasong fs=new Fasong();
}
}
class Fasong extends JFrame implements ActionListener{
JTextField fasongHao=new JTextField(10);
JTextField fasongText=new JTextField(10);
JButton fasongButton=new JButton("发送");
smssend smssender=null;
Fasong(){
JPanel Jnorth=new JPanel();
Jnorth.add(new JLabel("手机号码:"));
Jnorth.add(fasongHao);
JPanel Jcenter=new JPanel();
Jcenter.add(new JLabel("发送内容:"));
Jcenter.add(fasongText);
add(Jnorth,BorderLayout.NORTH);
add(Jcenter,BorderLayout.CENTER);
add(fasongButton,BorderLayout.SOUTH);
fasongButton.addActionListener(this);
setSize(200,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(smssender.GSMModemInitNew("COM4", "9600", null, "GSM", true, "YIWU-IJDD-****-****")){
byte[] sendtest=smssender.getUNIByteArray(fasongText.getText());
if(!smssender.GSMModemSMSsend(null, 8, sendtest, fasongHao.getText(), false)){
System.out.println("发送短信失败"+smssender.GSMModemGetErrorMsg());
}
}
}
}
以上是我写的段使用短息猫的代码,BestMail.jar文件我已经加载了,短息猫连接也没问题(利用VB开发的软件使用的非常好,但是在java中就不行了,奇怪!),运行时始终出现如下错误提示,麻烦高人指点:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Fasong.actionPerformed(Shoujifasong.java:33)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)