java - 构造函数问题: Actual and formal list differ in length

标签 java

我的问题是我有两个类,第一个是实现Runnable的实现类,第二个是扩展frameview的interfaceView

但是当我尝试在实现类中创建一个interfaceView对象时 例如

interfaceview check1 ;
check1.get_sms_validation();

它给了我

java.lang.IllegalArgumentException: null application

异常

实现类的代码为

但是当我这样做时

interfaceview check1 = new interfaceview () ;
  check1.get_sms_validation();

它告诉我在 InterfaceView 类中创建一个构造函数,当我这样做时,它会给我一个错误

Actual and formal list differ in length.

我的实现类的代码是

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package smsapp;
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import org.smslib.GatewayException;
import org.smslib.TimeoutException;
import org.smslib.modem.*;
import org.smslib.InboundMessage;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Random;
import org.jdesktop.application.SingleFrameApplication;
/**
 *
 * @author ist
 */
public class Implementation implements Runnable {


    private boolean login;
    public static Service srv;
    public static OutboundMessage outMsg;
    public static String defaultPort="COM7";
    public static ArrayList<OutboundMessage> queuedMessages = new ArrayList<OutboundMessage>();
    static QueueSendingNotification queueSendingNotification = new QueueSendingNotification();
    private boolean phoneConnected;
    Thread t;
    String msg ="1";
    public String Data_For_File ;
    public  String messageFor_File = null;
    public int check = 0;
    Random generator;
    public String message;
    private SingleFrameApplication SingleFrameApplication;
   // private String messageFor_File1;
    public String messageFor_File1 = null;
//   public InterfaceView = new InterfaceView ();

    Implementation()
    {
        phoneConnected = false;
    }

    public boolean connectPhone(String comPort)
    {
        try
        {

            srv = new Service();
            SerialModemGateway gateway = new SerialModemGateway("Modem 0", comPort, 9600, "", "");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            gateway.setSimPin("0000");
            srv.addGateway(gateway);

        }
        catch(Exception e)
        {
             System.out.println("Could Not connect to the Modem. Please try again.\n");

        }
        this.phoneConnected = true;
        return true;
    }

    public boolean startService()
    {
        try
        {
            if(phoneConnected)
            {
                srv.startService();
                t = new Thread(this);
                t.start();
                generator  = new Random( 19580427 );
            }
            else
            {
                return false;
            }
        }
        catch(Exception e)
        {
             try
             {
                 System.out.println("Service Start Error ");
                 e.printStackTrace();
                 srv.stopService();
                 return false;
             }catch(Exception ee)
             {
                 System.out.println("Service Stop Error");
                 e.printStackTrace();
                return false;

             }
        }
        srv.setOutboundNotification(queueSendingNotification);
//        myTimer = new Timer (10000,runProcess);
//        myTimer.setInitialDelay(0);
//        myTimer.start();
        return true;
    }

    public boolean stopService()
    {
        try
        {
            srv.stopService();
            t.stop();
        }catch(Exception e)
        {
            System.out.println("There was an error in disconnecting.");
            e.printStackTrace();
            return false;
        }
        return true; 
    }

    public void run()
    {
       // processOutMessage("1");
      //  processOutMessage();

        while (true)
        {
//            System.out.println(alpha++);
            InterfaceView.statusMessageLabel.setText("Checking inbound messages");
            try {
                //            System.out.println("Checking inbound messages");
                            readMessages();



            } catch (FileNotFoundException ex) {
                Logger.getLogger(Implementation.class.getName()).log(Level.SEVERE, null, ex);
            }
            InterfaceView.statusMessageLabel.setText("Processing messages");
//            System.out.println("Checking outbound messages");
        //    processMessages();
            InterfaceView.statusMessageLabel.setText("Checking outbound messages");
//            System.out.println("Checking outbound messages");
          //  sendMessages();
            InterfaceView.statusMessageLabel.setText("Waiting ... ");
            try {
                readMessages();
            } catch (FileNotFoundException ex) {

                Logger.getLogger(Implementation.class.getName()).log(Level.SEVERE, null, ex);
            }
            try
            {
                t.sleep(5000);
            } catch (InterruptedException e) {System.out.println("Thread Pause Exception");}
        }
    }

    static class QueueSendingNotification implements org.smslib.IOutboundMessageNotification
    {

        public void process(String gtwId, OutboundMessage msg)
        {
            try {
                System.out.println("Sent Message from: " + gtwId + " , " + msg.getId());
                queuedMessages.remove(msg);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }

    public void readMessages() throws FileNotFoundException
    {
        int check_Lenght = 0;

        if (srv.getServiceStatus() == Service.ServiceStatus.STARTED)
        {
            try{
                System.out.print ("\n\n\n\n\n" + "in the print block of above the interfaceview declaration");
                 InterfaceView check1 = new InterfaceView(SingleFrameApplication);
                InboundMessage msg = null;
                java.util.LinkedList<InboundMessage> list = new java.util.LinkedList<InboundMessage>();
                srv.readMessages(list, InboundMessage.MessageClasses.UNREAD);
                for (int i = 0; i < list.size(); i++)
                {

                    msg = list.get(i);

                    //TODO: submit the incoming messages to the database from this point. 
                    System.out.println("New incoming message from: " + msg.getOriginator() +" : \t" + msg.getText() + "\n");
                    saveSMS(msg.getOriginator(),msg.getText());
                    messageFor_File = msg.getText();

                    // Concatination of data
                    if (! messageFor_File.equals("Y"))     {           
                      Data_For_File = messageFor_File +  Data_For_File ;
                      check_Lenght = Data_For_File.length();
                     System.out.print("The Value for Data For File" + messageFor_File );

                          if (check_Lenght >= check){
                              System.out.println("\n\n\n" + "I am in x " );
                              DataPacketing call = new DataPacketing();
                              call.Write_To_File(Data_For_File);
                             }
                                 //put the message into database.
                               srv.deleteMessage(msg);

                    }
                    else 
                    {

                    messageFor_File1 = messageFor_File;
                    srv.deleteMessage(msg);
                    Read_Message_Notification ();



                    }
                }

            }

            catch(Exception e)

            {
                e.printStackTrace();
            }



        }

    }

    private void saveSMS(String originator, String text)
    {

        try
        {


        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public void processOutMessage(String sms)
    {
        try
        {
          // outMsg = new OutboundMessage ("03456305252", sms);
           // outMsg = new OutboundMessage ("03219409778", sms);
            outMsg = new OutboundMessage ("03456305252", sms);
            outMsg.setId("1");
            queuedMessages.add(outMsg);
            srv.queueMessage(outMsg);

            msg=msg+1;
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

public String Read_Message_Notification () throws TimeoutException {

 // int check_Lenght;
 //String messageFor_File1 = "";



   System.out.println(messageFor_File1);

return   messageFor_File1;
}

}

我的 InterfaceView 类的代码是

/*
 * InterfaceView.java
 */

package smsapp;

import java.io.IOException;
import java.util.logging.Level;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import org.smslib.InboundMessage;
import org.smslib.TimeoutException;
import org.smslib.helper.*;


/**
 * The application's main frame.
 */

public class InterfaceView extends FrameView {



     private final String s = null;
    public String fileName;
    public String filePath;
    public float fileLength;
    public int No_Of_SMS;
    public String check = "N";
    public  DataPacketing [] Packets_Array  = null;
    public  DataPacketing start  = new DataPacketing ();
    public SingleFrameApplication app1 = new SingleFrameApplication ()
          {

       @Override
       protected void startup() {
           throw new UnsupportedOperationException("Not supported yet.");
       }
   };


    private void customizations()
    {


    private void botton_startServiceMouseClicked(java.awt.event.MouseEvent evt) {                                                 
        if (!this.botton_startService.isEnabled())
            return;
        javax.swing.JInternalFrame j = new javax.swing.JInternalFrame();
            JOptionPane.showMessageDialog(j ,
                    "Please wait while the service is being connected.",
                    "Starting Server!",
                    JOptionPane.PLAIN_MESSAGE);
        if (instance.startService()) {
            j = new javax.swing.JInternalFrame();
            JOptionPane.showMessageDialog(j ,
                    "Service Started Successfully.",
                    "Service Started",
                    JOptionPane.INFORMATION_MESSAGE);
            this.botton_startService.setEnabled(false);
            this.botton_connectPhone.setEnabled(false);
            this.botton_stopService.setEnabled(true);
        } else {
            j = new javax.swing.JInternalFrame();
            JOptionPane.showMessageDialog(j ,
                    "Service could not be started. Please connect the phone and try again.",
                    "Service Start Error",
                    JOptionPane.ERROR_MESSAGE);
            this.botton_connectPhone.setEnabled(true);
        }
    }                                                

    private void botton_connectPhoneMouseClicked(java.awt.event.MouseEvent evt) {                                                 
        if (!this.botton_connectPhone.isEnabled())
            return;
        if (!(instance.connectPhone(this.comPorts.getSelectedItem().toString()))) {
            javax.swing.JInternalFrame j = new javax.swing.JInternalFrame();
            JOptionPane.showMessageDialog(j ,
                    "Phone could not be connected. Please check the ports and try again.",
                    "Phone Connection Error",
                    JOptionPane.ERROR_MESSAGE);
        }
        //this.botton_connectPhone.setEnabled(false);


    }                                                

    private void formPropertyChange(java.beans.PropertyChangeEvent evt) {                                    
        if (!(instance.connectPhone(instance.defaultPort) && (instance.startService())))
        {
            this.botton_connectPhone.setEnabled(true);
            this.botton_startService.setEnabled(true);
            this.botton_stopService.setEnabled(false);         

        }      

    }                                   

    private void SelectFileActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
        fileName = f.getName();
        filePath = f.getPath();
        fileLength = f.length();
       // System.out.println("You have chosen: " + fileName+"\n from the path: "+filePath+"\n of the length: "+fileLength+" KB");         

        //------------------------------------- Calculating the Number Of SMS Required from the File Size

        float temp = fileLength/120;
        No_Of_SMS = (int) Math.ceil(temp);

        String SMS = " "+No_Of_SMS+" SMS";         
        SmsRequired.setText(SMS);
        String size2 = " "+fileLength+" KB";       
        FileName.setText(fileName);
        FileSize.setText(size2);

        this.FileName.setVisible(true);
        this.FileSize.setVisible(true);
        this.SmsRequired.setVisible(true);       
        this.jLabel3.setVisible(true);
        this.jLabel4.setVisible(true);
        this.jLabel6.setVisible(true);
        DataPackets.setText(" InterKnot:\\"+filePath);

        try {
            Packets_Array  =   start.Driver(fileName,filePath,fileLength,No_Of_SMS);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(InterfaceView.class.getName()).log(Level.SEVERE, null, ex);
        }       
        this.DataPackets.setVisible(true);

      //  DataPacketing setFile = new DataPacketing();
      //setFile.File_Name_Path(fileName, filePath);


}                                          

    private void FileNameActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
}                                        

    private void FileNameKeyPressed(java.awt.event.KeyEvent evt) {                                    
        // TODO add your handling code here:
}                                   

    private void ReadandSendFileActionPerformed(java.awt.event.ActionEvent evt) {                                                
        // TODO add your handling code here:

     //  DataPacketing [] Packets_Array  = null;
      // DataPacketing start  = new DataPacketing ();
         System.out.println("I am not yet in if");
        String s = null; 
         if(check.equals("N")){
        System.out.println("Do i Come here ????");
             try {
        //InboundMessage userNo = null;
            //String info = "User: " +  "wants to share file :"+ FileName+ " of size: "+FileSize+ "with you.To allow Reply Y";
                 String newInfo = "User Wants to share a file with you. To allow reply Y";
                System.out.println("\n\n\n\n\n" + newInfo);
                message1.processOutMessage(newInfo);

                         System.out.print("\n\n\n\n\n\n" + "I am In try to check for the read notification message");

                          }catch (Throwable t) {
                               System.out.println("The Exception" + t);

                  }

             Implementation check1 = new Implementation ();
            try {


                check = check1.Read_Message_Notification();


            } catch (TimeoutException ex) {

                java.util.logging.Logger.getLogger(InterfaceView.class.getName()).log(Level.SEVERE, null, ex);
            }



        if (check.equals("Y")){


        //  --------------------------------------------converting String Array into String


        StringBuffer result = new StringBuffer();

        //  -------------------------------------------- LOOP to send WHOLE file 

        for(int i=0; i<Packets_Array.length; i++)
        { 

                String s1 = Packets_Array[i].Data_Segment;
                System.out.println(s1);
                message1.processOutMessage(s1);
        }                

        //  -------------------------------------------- To send First Packet of file

        }


         }


        else
        {

        System.out.println("The User Refused to Allow the Transfer");

        }
    }                                               

    private void FileSizeActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void FileSizeKeyPressed(java.awt.event.KeyEvent evt) {                                    
        // TODO add your handling code here:
    }                                   

    private void SmsRequiredActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void SmsRequiredKeyPressed(java.awt.event.KeyEvent evt) {                                       
        // TODO add your handling code here:
    }                                      

    private void DataPacketsActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void DataPacketsKeyPressed(java.awt.event.KeyEvent evt) {                                       
        // TODO add your handling code here:
    }                                      

    // Variables declaration - do not modify                     
    private javax.swing.JTextField DataPackets;
    private javax.swing.JTextField FileName;
    private javax.swing.JTextField FileSize;
    private javax.swing.JLabel PicGlobe;
    private javax.swing.JButton ReadandSendFile;
    private javax.swing.JButton SelectFile;
    private javax.swing.JTextField SmsRequired;
    private javax.swing.JButton botton_connectPhone;
    private javax.swing.JButton botton_startService;
    private javax.swing.JButton botton_stopService;
    public static javax.swing.JComboBox comPorts;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    public static javax.swing.JLabel statusMessageLabel;
    public static javax.swing.JLabel statusMessageLabel1;
    private javax.swing.JPanel tab_settings;
    // End of variables declaration                   
    Object table_keywords_columns[] = { "Keyword",  "Reply Text"};
    Object table_outgoingSMS_columns[] = { "Number",  "Text", "Time"};
    Object table_incomingSMS_columns[] = { "Number",  "Text", "Time", "Auto-Reply Keyword"};
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private Implementation instance; 
    private JDialog aboutBox;
    public Implementation message1 = new Implementation();
    JProgressBar progressBar;

   void messagecheck(){
   System.out.print ("\n\n\n\n\n\n\n" + "I am in the message code of the interfaceview class");



   }


}

要做什么?

最佳答案

您的第一个示例失败,因为您没有为变量分配任何内容,因此它为 null 并且您得到一个 NullPointerException

您的第二个示例失败,因为构造函数需要参数,而您没有提供它们。您需要查看 interfaceview 类的构造函数并提供相关参数。

例如,如果interfaceview的唯一构造函数如下所示:

public interfaceview(String foo) {
   // ...
}

...然后要创建它,您必须提供一个字符串:

interfaceview check1 = new interfaceview("Some string here");
<小时/>

我认为退后一步并学习一些 Java 教程(不乏此类教程)可能会很有用。另外,就其值(value)而言,通常在 Java 中接口(interface)和类都是以首字母大写的驼峰命名法编写的,例如InterfaceView 而不是 interfaceview。如果您愿意,可以忽略该约定,但遵循它可以使代码对其他人来说更加清晰。

关于java - 构造函数问题: Actual and formal list differ in length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10427846/

相关文章:

java - 每次部署时都将图像、CSS 文件等包含在 WAR 文件中吗?

java - 当返回json响应但正确返回xml响应时, Jersey 返回404未找到

java - 如何正确从通用链表中删除一个节点?

java - 我怎样才能绕过这个无效的类加载器层次结构?

java - Sonar ANT 任务集成错误

java - Spring @Autowire 与 getBean(className) 的性能比较

java - 调度程序可以挂起一个线程并执行另一个线程/工作吗?

java - 通过支持 bean 的数据表行选择单一设置无法正常工作

java - 从 main 中的另一个类方法调用数组

java - JPA 2.1/hibernate 5 : Search on inner type of Composite User Type with criteria API