Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2008

Tip: Looking for answers? Try searching our database.

J2ME Exception - PLEASE HELP

Thread view: 
cpptutor2000@yahoo.com - 15 Feb 2008 00:25 GMT
I am bit of a newbie to J2ME, and I am trying to create a simple
metronome application. I am using Java 1.4.2.16 along with the Sun
WTK.
I am getting an exception as:

java.lang.IllegalArgumentException: type media does not have subtype
Tone
    at com.sun.kvem.warn.DefaultWarnUserPolicy.shouldWarnUser(Unknown
Source)
    at com.sun.kvem.warn.UserWarningManager.warnUser(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.sun.kvem.Lime$Connection.callMethod(Unknown Source)
    at com.sun.kvem.Lime$Connection.processCommand(Unknown Source)
    at com.sun.kvem.Lime$Connection.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:534)

The source code is included below:
import java.util.*;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.Manager;
import javax.microedition.media.control.*;

public class TestMIDlet extends MIDlet implements CommandListener
{
  private boolean started   = false;
  private Thread thread     = null;
  private int timerInterval = 0;
  private Timer timer       = null;
  private TimerTask task    = null;
  private static List theList = null;
 /* private static Vector urls  = null; */
  private Command exitCommand = new Command("Exit", Command.EXIT, 1);
  private Command playCommand = new Command("Play", Command.ITEM, 1);
  private Display display     = null;

  public TestMIDlet ()
  {
    super();
    display  = Display.getDisplay(this);
    initPlayList();
    display.setCurrent(theList);
    String interval = getAppProperty("Timer-Interval");
    timerInterval = 3000;  Integer.parseInt(interval);
    System.out.println("Midlet started ... timer interval is "
+timerInterval);
  }

  public static List getList() {
    return theList;
   }

  protected void startApp()
  {
    if(!started)
    {
      started = true;
      startTimer();
    }
    else
    {
      System.out.println("Eat pussy now ...");
    }

    synchronized(this)
    {

     if(thread == null)
     {

       thread = new Thread()
       {

         public void run()
         {

          System.out.println("Thread started ...");
           while(thread == this)
           {
             try
             {
                 Thread.sleep(5000);
             }
             catch(InterruptedException ie)
             {
             }
           }
           System.out.println("Thread terminating ...");

         }

       };

      }

     };
     thread.start();

   }

   protected void pauseApp()
   {
     System.out.println("pauseApp invoked ...");
     synchronized(this)
     {
      if(thread != null)
      {
       thread = null;
      }
    }
   }

   public void commandAction(Command c, Displayable s)
   {
    if (c == exitCommand)
       {
         try
          {
       destroyApp(true);
       notifyDestroyed();
          }
          catch(MIDletStateChangeException msce)
          {
          }
    }

       else if ((s == theList &&
                c == List.SELECT_COMMAND) ||
        c == playCommand)
       {

       if (theList.getSelectedIndex() == 0)
           { // Simple tone
             for(;;)
             {
        try
               {
         Manager.playTone(90, 200, 90);
        } catch (MediaException ex) {
           System.out.println("can't play tone");
        }
             }
       }
    }
   }

   protected void destroyApp(boolean unconditional) throws
MIDletStateChangeException
   {
     System.out.println("destroyApp called ... unconditional =
"+unconditional);
     if(thread != null)
     {
       Thread bgthread = thread;
       thread = null;
       try
       {
        bgthread.join();
       }
       catch(InterruptedException ie){}
      }
     stopTimer();
     display.setCurrent(null);
   }

  private void stopTimer()
  {
    if(timer != null)
    {
      timer.cancel();
      System.out.println("Timer stopped ...");
    }
  }

  private void startTimer()
  {

    task = new TimerTask(){
      private boolean isPaused = false;
      private int count = 0;

      public void run()
      {
       if(count++ == 4)
       {
        try
        {
          TestMIDlet.this.destroyApp(true);
        }
        catch(MIDletStateChangeException msche)
        {
        }
        TestMIDlet.this.notifyDestroyed();
        return;
       }

      if(isPaused)
      {
        TestMIDlet.this.resumeRequest();
        isPaused = false;
       }

      else
      {
        isPaused = true;
        TestMIDlet.this.pauseApp();
        TestMIDlet.this.notifyPaused();
      }
      /*
      try
      {
        System.out.println("trying to play sound");
        Manager.playTone(60, 200, 90);
      }
      catch(MediaException mex)
      {
        System.out.println("Can't play the fuckin' sound ...");
      }
      */
     }
    };

   timer = new Timer();
   timer.schedule(task, timerInterval, timerInterval);
 }

 private void initPlayList()
 {
       /*urls = new Vector(); */

    theList  = new List("Pussy Milk", Choice.IMPLICIT);
       /*
    for (int n = 1; n < 32; n++)
       {
       String nthURL = "PlayerURL-"+ n;
       String url = getAppProperty(nthURL);
       if (url == null || url.length() == 0) {
        break;
       }
       String nthTitle = "PlayerTitle-" + n;
       String title = getAppProperty(nthTitle);
       if (title == null || title.length() == 0) {
        title = url;
       }
       urls.addElement(url);
       theList.append(title, null);
    }
       */
       theList.append("Play", null);
    theList.addCommand(exitCommand);
    theList.addCommand(playCommand);
    theList.setCommandListener(this);
 }

}

Any hints would be extremely useful. Thanks in advance for your help.
Roedy Green - 15 Feb 2008 07:12 GMT
On Thu, 14 Feb 2008 16:25:50 -0800 (PST), "cpptutor2000@yahoo.com"
<cpptutor2000@yahoo.com> wrote, quoted or indirectly quoted someone
who said :

>Any hints would be extremely useful.

I would clean up the program language before posting. It is not clear
if you are seriously asking for help or just disguising a f.ck you.

--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.