Question

I have tried for two days to write a code that dial a phone number , but I failed

I have written a midlet and a form called main as a Displayable the form contains a textfield and

command .

When the application starts up the form should appears and calls the dialed number written in

textField when the command pressed.

the dialing process didn't work with me .

import javax.microedition.io.ConnectionNotFoundException;

import javax.microedition.lcdui.Command; 

import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Displayable.*;
import javax.microedition.lcdui.Form.*;
 import javax.microedition.midlet.MIDlet;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.MIDlet;

public class DiallNumber extends MIDlet implements CommandListener
 {
    String num;
 private  Form main;
 private Command call,dial;
 private TextField phoneField;

 Display display;

 public DiallNumber()
    {


 main = new Form("main");
phoneField = new TextField("label","",10,phoneField.PHONENUMBER);
call = new Command("call",call.OK,0);
    main.append(phoneField);
    main.addCommand(call);
    num=this.phoneField.getString().trim();
main.setCommandListener(this);
 }

/**}
 * From MIDlet. Called when the MIDlet is started.
 */
 public void startApp()
 {

 // The initial display is the first form

display = Display.getDisplay(this);
   display.setCurrent(main);





     }

public void call( String number) {
 try {
 platformRequest("tel:"+number);
 } catch (ConnectionNotFoundException ex) {
 // TODO: Exception handling
 }
 }
 public void commandAction(Command c, Displayable d){
     if(d==main)
     {
         if(c==call)

              call(""+num);
     }

 }


 public void pauseApp()
 {
 // No implementation required
 }



/*


 * /
 */


/**
 * From MIDlet. Called to signal the MIDlet to terminate.
 *
* @param unconditional
 * whether the MIDlet has to be unconditionally terminated
 */
 public void destroyApp(boolean unconditional)
 {
 // No implementation required
 }

/**
 * From CommandListener. Called by the system to indicate that a command has
 * been invoked on a particular displayable.
 *
* @param command
 * the command that was invoked
 * @param displayable
 * the displayable where the command was invoked
 */



       }

My log trace

Copying 1 file to C:\Users\ELHADI\Documents\NetBeansProjects\DiallNumber2\dist\nbrun5217990045006831680
Copying 1 file to C:\Users\ELHADI\Documents\NetBeansProjects\DiallNumber2\dist\nbrun5217990045006831680
Jad URL for OTA execution: http://localhost:8082/servlet/org.netbeans.modules.mobility.project.jam.JAMServlet/C%3A/Users/ELHADI/Documents/NetBeansProjects/DiallNumber2/dist//DiallNumber2.jad
Starting emulator in execution mode
Installing suite from: http://127.0.0.1:49320/DiallNumber2.jad
[WARN] [rms     ] javacall_file_open: _wopen failed for: C:\Users\ELHADI\javame-sdk\3.0\work\0\appdb\_delete_notify.dat
Was it helpful?

Solution

I have solved the problem

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Displayable.*;
import javax.microedition.lcdui.Form.*;
 import javax.microedition.midlet.MIDlet;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.MIDlet;

public class DiallNumber extends MIDlet  
 {




    private  Display display;
 private MIDlet midlet;


Form f = new form("f");






/**}
 * From MIDlet. Called when the MIDlet is started.
 */
 public void startApp()
 {


display = Display.getDisplay(this);
  display.setCurrent(f);
}










 public void pauseApp()
 {
 // No implementation required
 }



/*


 * /
 */


/**
 * From MIDlet. Called to signal the MIDlet to terminate.
 *
* @param unconditional
 * whether the MIDlet has to be unconditionally terminated
 */
 public void destroyApp(boolean unconditional)
 {
 // No implementation required
 }
   class form extends   Form  implements CommandListener

           {
           private  Command call;

            private TextField phoneField;
           private String n;
   public form(String title )
       {
       super(title);

       call =new Command("call",call.OK,0);
       this.phoneField =new TextField("number","",20,phoneField.PHONENUMBER);


   addCommand(call);
   append(this.phoneField);

   this.setCommandListener(this);
      }

        public void commandAction(Command c,Displayable  d)
       {

   if(c==call)
   {


   try
   {
       n=phoneField.getString().trim();
      platformRequest("tel:"+n);


   }
  catch(javax.microedition.io.ConnectionNotFoundException e)
  {e.printStackTrace();}
   }


   }

   }




       }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top