My first Java application only works on emulator

I've been programming (just for fun) for many years now, and a couple of days ago I got interested in writing software for my cellphone (a SE k500i). Now I've managed to create my first program. It works great when being run inside an emulator-window but not on my cellphone. I guess it crashes directly because I don't get any error messages or anything.
I've been developing it using netbeans and I'm using a "TableItem" to display searches (my program searches a huge list of swedish words (only the CRC32 of the words are stored in a file called "ord") to see if an inputted word is valid when playing Scrabble). Is it wrong to use the tableItem maybe?
Screenshot: http://home.no/filipsprogram/DUMP/Shot0001.JPG
I have attached the full source code for my program, if someone could take a look at it I would be very greatful:
(oh, one more thing, in netbeans, how do you delete autogenerated code? I added some commands in the "Screen Design"-er and deleted them right away but the code is still there...)
* AlfapetSok.java
* Created on den 29 juni 2006, 10:39
package AlfapetSok;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import java.io.*;
import org.netbeans.microedition.lcdui.TableModel;
* @author filip ([email protected])
public class AlfapetSok extends MIDlet implements CommandListener, ItemCommandListener {
     * Creates a new instance of AlfapetSok
    public AlfapetSok() {
    private Form mainForm;
    private Command exitCommand;
    private TextField textField1;
    private Command okCommand1;
    private org.netbeans.microedition.lcdui.SimpleTableModel simpleTableModel1;
    private org.netbeans.microedition.lcdui.SimpleTableModel simpleTableModel2;
    private Spacer spacer1;
    private org.netbeans.microedition.lcdui.TableItem tableItem1;
    private Command screenCommand1;
    private Command screenCommand2;
    private int NumWords = 5;
    private String[][] Words = new String[NumWords][2];
    private int NumSearches=0;
    private int polynomial = 0xEDB88320;
    int[] ord = createFromFile("/AlfapetSok/ord");
private int CRC32Value(int i) {
int crc = i;
for (int j = 8; j > 0; j--) {
if ((crc & 1) == 1)
crc = (crc >>> 1) ^ polynomial;
else
crc >>>= 1;
return crc;
public int calculateCRC32(byte[] buffer) {
    int crc=0;
        for (int i = 0; i <  buffer.length; i++) {
            int tmp1 = (crc >>> 8) & 0x00FFFFFF;
            int tmp2 = CRC32Value(((int) crc ^ buffer) & 0xff);
crc = tmp1 ^ tmp2;
return crc;//((crc % 0xFFFFFF) & 0xFFFFFF); //24-bit CRC :-)
public static int[] createFromFile(String aFilename) {       
try {
InputStream is = aFilename.getClass().getResourceAsStream(aFilename);
DataInputStream d = new DataInputStream(is);
int antalord = 89361;
int[] array = new int[antalord];
for(int i = 0; i < antalord; i++){
array[i] = d.readInt();
return array;
} catch (Exception e) {
System.out.println("FEEEEEEL!!!!: "+e.toString());
return null;
public int search(int[] buffer,int target){
int low=0;
int high = buffer.length-1;
int mid;
while (low <= high)
mid= (low + high) / 2;
if (target == buffer[mid])
return mid;
if (target < buffer[mid])
high = mid - 1;
else
low = mid + 1;
return -1;
public org.netbeans.microedition.lcdui.SimpleTableModel getModel(int Num) {
if (simpleTableModel1 == null)
simpleTableModel1 = new org.netbeans.microedition.lcdui.SimpleTableModel();
String[][] WordsTemp = new String[Num][2];
for (int i=0;i < Num;i++)
WordsTemp[i][0] = Words[i][0];
WordsTemp[i][1] = Words[i][1];
simpleTableModel1.setValues(WordsTemp);
simpleTableModel1.setColumnNames(new String[] {"Ord","Finns?"});
return simpleTableModel1;
/** Called by the system to indicate that a command has been invoked on a particular item.
* @param command the Command that ws invoked
* @param item the Item on which the command was invoked
public void commandAction(Command command, Item item) {
// Insert global pre-action code here
if (item == textField1) {
if (command == okCommand1) {
// Do nothing
String s = textField1.getString();
String s2= s.toLowerCase();
int i = calculateCRC32(s2.getBytes());
String t = "ja";
if(-1 == search(ord,i))
t = "nej";
for (i = NumWords-1 ;i > 0;i--)
Words[i][0] = Words[i-1][0];
Words[i][1] = Words[i-1][1];
Words[0][0] = s;
Words[0][1] = t;
if (NumSearches++ >= NumWords)
NumSearches = NumWords;
tableItem1.setModel(getModel(NumSearches));
textField1.setString("");
// Insert global post-action code here
/** This method initializes UI of the application.
private void initialize() {
// Insert pre-init code here
getDisplay().setCurrent(get_mainForm());
// Insert post-init code here
/** Called by the system to indicate that a command has been invoked on a particular displayable.
* @param command the Command that ws invoked
* @param displayable the Displayable on which the command was invoked
public void commandAction(Command command, Displayable displayable) {
// Insert global pre-action code here
if (displayable == mainForm) {
if (command == exitCommand) {
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
// Insert global post-action code here
* This method should return an instance of the display.
public Display getDisplay() {                        
return Display.getDisplay(this);
* This method should exit the midlet.
public void exitMIDlet() {                        
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
/** This method returns instance for mainForm component and should be called instead of accessing mainForm field directly.
* @return Instance for mainForm component
public Form get_mainForm() {
if (mainForm == null) {
// Insert pre-init code here
mainForm = new Form(null, new Item[] {
get_textField1(),
get_spacer1(),
get_tableItem1()
mainForm.addCommand(get_exitCommand());
mainForm.setCommandListener(this);
// Insert post-init code here
return mainForm;
/** This method returns instance for exitCommand component and should be called instead of accessing exitCommand field directly.
* @return Instance for exitCommand component
public Command get_exitCommand() {
if (exitCommand == null) {
// Insert pre-init code here
exitCommand = new Command("Avsluta", Command.EXIT, 1);
// Insert post-init code here
return exitCommand;
/** This method returns instance for textField1 component and should be called instead of accessing textField1 field directly.
* @return Instance for textField1 component
public TextField get_textField1() {
if (textField1 == null) {
// Insert pre-init code here
textField1 = new TextField("Filips AlfapetS\u00F6k", "", 120, TextField.ANY);
textField1.addCommand(get_okCommand1());
textField1.setItemCommandListener(this);
textField1.setDefaultCommand(get_okCommand1());
// Insert post-init code here
return textField1;
/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.
* @return Instance for okCommand1 component
public Command get_okCommand1() {
if (okCommand1 == null) {
// Insert pre-init code here
okCommand1 = new Command("S\u00F6k", Command.OK, 1);
// Insert post-init code here
return okCommand1;
/** This method returns instance for simpleTableModel1 component and should be called instead of accessing simpleTableModel1 field directly.
* @return Instance for simpleTableModel1 component
public org.netbeans.microedition.lcdui.SimpleTableModel get_simpleTableModel1() {
if (simpleTableModel1 == null) {
// Insert pre-ire
simpleTableModel1 = new org.netbeans.microedition.lcdui.SimpleTableModel();
simpleTableModel1.setValues(new String[][] {
new String[] {
new String[] {
null,
new String[] {
null,
null,
new String[] {
null,
null,
new String[] {
null,
null,
new String[] {
null,
null,
simpleTableModel1.setColumnNames(null);
// Insert post-init code here
return simpleTableModel1;
/** This method returns instance for simpleTableModel2 component and should be called instead of accessing simpleTableModel2 field directly.
* @return Instance for simpleTableModel2 component
public org.netbeans.microedition.lcdui.SimpleTableModel get_simpleTableModel2() {
if (simpleTableModel2 == null) {
// Insert pre-init code here
simpleTableModel2 = new org.netbeans.microedition.lcdui.SimpleTableModel();
simpleTableModel2.setValues(new String[][] {
new String[] {
simpleTableModel2.setColumnNames(new String[] {
"Ord",
"Finns?",
// Insert post-init code here
return simpleTableModel2;
/** This method returns instance for spacer1 component and should be called instead of accessing spacer1 field directly.
* @return Instance for spacer1 component
public Spacer get_spacer1() {
if (spacer1 == null) {
// Insert pre-init code here
spacer1 = new Spacer(1000, 1);
// Insert post-init code here
return spacer1;
/** This method returns instance for tableItem1 component and should be called instead of accessing tableItem1 field directly.
* @return Instance for tableItem1 component
public org.netbeans.microedition.lcdui.TableItem get_tableItem1() {
if (tableItem1 == null) {
// Insert pre-init code here
tableItem1 = new org.netbeans.microedition.lcdui.TableItem(getDisplay(), "S\u00F6kningar", get_simpleTableModel2());
// Insert post-init code here
return tableItem1;
/** This method returns instance for screenCommand1 component and should be called instead of accessing screenCommand1 field directly.
* @return Instance for screenCommand1 component
public Command get_screenCommand1() {
if (screenCommand1 == null) {
// Insert pre-init code here
screenCommand1 = new Command("Screen", Command.SCREEN, 1);
// Insert post-init code here
return screenCommand1;
/** This method returns instance for screenCommand2 component and should be called instead of accessing screenCommand2 field directly.
* @return Instance for screenCommand2 component
public Command get_screenCommand2() {
if (screenCommand2 == null) {
// Insert pre-init code here
screenCommand2 = new Command("Screen", Command.SCREEN, 1);
// Insert post-init code here
return screenCommand2;
public void startApp() {
initialize();
public void pauseApp() {
public void destroyApp(boolean unconditional) {

I still haven't heard anything from the guy at Sun, so today when I got an infrared device I did some debugging on my own directly on the phone. I managed to trace the error (by alot of System.out.println("I'm here!")) to TableItem.java in the function setModel.
     public void setModel(TableModel model) throws IllegalArgumentException {
             if (this.model != null) {
               this.model.removeTableModelListener(this);
             if (model == null) throw new IllegalArgumentException("model parameter cannot be null");
          if (model != null) {
               if (model.getRowCount() < 0) throw new IllegalArgumentException("model cannot have negative number of rows");
               if (model.getColumnCount() < 0) throw new IllegalArgumentException("model cannot have negative number of cols");
               model.addTableModelListener(this);
          this.model = model;
                recomputeModelValues();
                invalidate();       
     }The last line there, Invalidate();, is causing the crash; by commenting that line out the program will run :-) Unfortunately the tableItem will not work correctly without it. I'm not skilled enough to continue debugging, maybe someone else can take over from here?

Similar Messages

  • Just finished my first Java application. What's next?

    Thanks to the kind help from everyone on this forum and some intensive labor for the last couple of months, I've finally given birth to my first Java application. I used Netbeans as my IDE of choice. During the development stages I would run my project directly from the IDE. In the project folder, a total of five folders were created: build, dist, nbproject, src, and test as well as two files build.xml and manifest.mf.
    Being a newbie in this field, I was wondering about the remaining steps needed to distribute the application. Here are some questions that come to mind:
    1) I know I can simply just double-click the project's *.jar* file to get it work. Is that the norm with Java applications or do I need to create a different file? I'm used to seeing *.exe* files. I'm also used to seeing an installation process, which brings me to my next question.
    2) Do you simply just zip the entire project folder and allow people to download it on their computer hoping they know how to access the *.jar* file?
    3) Seeing that I've only been testing the application in Netbeans, will there be file path or classpath problems if I run it on other computers? Are there necessary steps I need to follow to avoid such problems?
    4) Do you take any precautionary steps to protect your code? Do you lock the folders?
    5) In the future, if I decide to add a small fee to download the application, how hard would it be to add a password activation feature? (I know this could get pretty complex)
    Thanks in advance for all your suggestions.

    mohogany wrote:
    Thanks to the kind help from everyone on this forum and some intensive labor for the last couple of months, I've finally given birth to my first Java application. I used Netbeans as my IDE of choice. During the development stages I would run my project directly from the IDE. In the project folder, a total of five folders were created: build, dist, nbproject, src, and test as well as two files build.xml and manifest.mf.
    Being a newbie in this field, I was wondering about the remaining steps needed to distribute the application. Here are some questions that come to mind:
    1) I know I can simply just double-click the project's *.jar* file to get it work. Is that the norm with Java applications or do I need to create a different file? I'm used to seeing *.exe* files. I'm also used to seeing an installation process, which brings me to my next question.It's quite common to provide a shell script (batch file, etc) to launch the app.
    2) Do you simply just zip the entire project folder and allow people to download it on their computer hoping they know how to access the *.jar* file?You can do. There are also installation utilities around. InstallAnywhere is the only one I've ever used, but others do exist.
    3) Seeing that I've only been testing the application in Netbeans, will there be file path or classpath problems if I run it on other computers? Are there necessary steps I need to follow to avoid such problems?Probably. The best way to avoid them is to test them, and to not ever depend on the CLASSPATH environment variable. That's a portability nightmare.
    4) Do you take any precautionary steps to protect your code? Do you lock the folders? Nope.
    5) In the future, if I decide to add a small fee to download the application, how hard would it be to add a password activation feature? (I know this could get pretty complex) Don't bother. Unless you've got something amazing, in which case you'll be needing lawyers, it's not worth the trouble of charging for it. No offence, but your first Java app is hardly going to set the world on fire anyway.
    No matter what you try and do to stop people stealing your code, they'll manage it. Or, alternatively, just steal your idea instead.

  • Why does Java Application not working with Macromedia Flash 5 or MX?

    Why does Java Application not working with Macromedia Flash 5 or MX?

    Who says they don't?
    Although I don't know much about those I'd think they should be able to talk to Java Aps using Sockets or request Servlets ...
    Spieler

  • Adobe Air Application only works using Super Administrator account on Windows XP

    Good day
    i really need some help. I developed air application that uses remote service, sql lite etc. It is working on my computer WIndows XP sp2. To test, i even created a guest account and it works fine. But when i deployed it to our client, the application doest work. Only the login page appears. I ask the it personnel there and ask if there are any restriction on the account of the user and said there is none because they are using Domain account. But when the super administrator is logged in, it works
    Your help will greatly apprciated

    Your help me, I iwill greatly apprciated
    HELP MALAYSIA
    Date: Thu, 21 Oct 2010 20:54:19 -0600
    From: [email protected]
    To: [email protected]
    Subject: Adobe Air Application only works using Super Administrator account on Windows XP
    Good day
    i really need some help. I developed air application that uses remote service, sql lite etc. It is working on my computer WIndows XP sp2. To test, i even created a guest account and it works fine. But when i deployed it to our client, the application doest work. Only the login page appears. I ask the it personnel there and ask if there are any restriction on the account of the user and said there is none because they are using Domain account. But when the super administrator is logged in, it works
    Your help will greatly apprciated
    >

  • CS6 applications only work in admin accounts

    iMacs, OS X 10.6.8, 4gb of ram:
    Our district has a volume license of CS 6 Master collection. I recently started upgrading the iMacs in our computer labs to CS6, but the applications only work on the admin account. When I try to run the applications from a managed account, I get the user permission prompt stating that the user does not have permission to run the application.
    If I select always allow, the application does not open.
    If I click allow once, the application opens, but more permissions prompts come up for the applications specific components that have to run.
    For Photoshop, for example, the user does not have permission for adobe_licutil, for AE, the mercury render engine, etc.
    The application opens, but freezes (see error code below).
    What I've done so far:
    Ensured that the applications are checked off in the preferences so that the account has permission to run them, however, it appears that the user does not have permission for additional components which are not listed in system preferences and therefore cannot be checked off in system preferences. This did not work. The account has permission to run the apps but the same problems (1 & 2 above) persist.
    Selected all of the application folders and changed the permissions in the terminal (chmod -rf 777 on all folders). The account has permission for all files/components.This did not work.
    Changed the managed account to an admin account (allow user to adminster computer in system preferences) and all problems are fixed. All applications then open/run.
    Solves the problem and all CS 6 apps run, however, we cannot have students use an account with admin privileges.
    Changed the account back to a managed one, selected all CS 6 applications and utilities in the user account preferences, but the problems returned.
    Any ideas on how this can be fixed?
    All CS 6 applications result in the following error (the errors are essential identical, only the name of the application and reference to application specific components are different, not the entire log):
    Process:    
    Adobe Premiere Pro CS6 [246]
    Path:       
    /Applications/Adobe Premiere Pro CS6/Adobe Premiere Pro CS6.app/Contents/MacOS/Adobe Premiere Pro CS6
    Identifier: 
    Adobe Premiere Pro CS6
    Version:    
    Code Type:  
    X86-64 (Native)
    Parent Process:  Adobe Premiere Pro CS6 [229]
    Date/Time:  
    2012-06-08 11:58:03.976 -0400
    OS Version: 
    Mac OS X 10.6.8 (10K549)
    Report Version:  6
    Exception Type:  EXC_BREAKPOINT (SIGTRAP)
    Exception Codes: 0x0000000000000002, 0x0000000000000000
    Crashed Thread:  0  Dispatch queue: com.apple.main-thread
    Application Specific Information:
    *** multi-threaded process forked ***
    *** NSTask: Task create for path '/Applications/Adobe Premiere Pro CS6/Adobe Premiere Pro CS6.app/Contents/Frameworks/AdobeCrashReporter.framework/Required/AdobeCrashDaemon.app/Co ntents/MacOS/AdobeCrashDaemon' failed: 22, "Invalid argument".  Terminating temporary process.
    Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
    0   com.apple.Foundation     
    0x00007fff896dd646 ___NEW_PROCESS_COULD_NOT_BE_EXECD___ + 5
    1   com.apple.Foundation     
    0x00007fff89611f04 -[NSConcreteTask launchWithDictionary:] + 3506
    2   com.apple.Foundation     
    0x00007fff8961aa33 +[NSTask launchedTaskWithLaunchPath:arguments:] + 215
    3   com.adobe.AdobeCrashReporter 
    0x000000010000a251 AdobeCrashReporterInitialize + 2880
    4   com.adobe.AdobePremierePro
    0x00000001000036c4 main + 148
    5   com.adobe.AdobePremierePro
    0x000000010000361c start + 52
    Thread 0 crashed with X86 Thread State (64-bit):
      rax: 0x0000000000000001  rbx: 0x000000010dfaa6b0  rcx: 0x00007fffffe000c0  rdx: 0x00007fff70c72340
      rdi: 0x000000010e1c8a00  rsi: 0x000000010e1c8a00  rbp: 0x00007fff5fbff410  rsp: 0x00007fff5fbff410
       r8: 0x0000000000000001   r9: 0x000000010dfaa980  r10: 0x0000000000000000  r11: 0x000000000000003f
      r12: 0x00007fff710b9498  r13: 0x0000000000001300  r14: 0x0000000000000000  r15: 0x0000000000000000
      rip: 0x00007fff896dd646  rfl: 0x0000000000000202  cr2: 0x000000010def7000
    Binary Images:
    0x100000000 -   
    0x100003ff7 +com.adobe.AdobePremierePro 6.0.1 (6.0.1) <235A9737-DBF6-33F7-E3C0-BE780C209731> /Applications/Adobe Premiere Pro CS6/Adobe Premiere Pro CS6.app/Contents/MacOS/Adobe Premiere Pro CS6
    0x100008000 -   
    0x10000cff7 +com.adobe.AdobeCrashReporter 6.0 (6.0.20120201) <A6B1F3BD-5DB0-FEE5-708A-B54E5CA80481> /Applications/Adobe Premiere Pro CS6/Adobe Premiere Pro CS6.app/Contents/Frameworks/AdobeCrashReporter.framework/Versions/A/AdobeCrashReporter
    Thanks

    "If you checked  "allow users to manage this computer" in system preferences it is not a managed account. Trying to set this up locally does not work."
    Not true.  OD or AD accounts are Managed, but may also be admins. But this is not the case in my Mac labs. I am doing this via the local machine.
    "So (and I'm doing some educated guessing here), you might remove the settings in Workgroup Manager for that user or group, and then logon and execute the apps.  Then restore the settings."
    Just set the radio button (in Workgroup Manager, Applications) to "Never," save, and then start over using my method.
    "I will have to confess that in this context, I don't know what whitelist means.  But if it means that everyone has access to these folders, then it defeats the purpose that I am using it for. I did get Workgroup Manager to work, but unlike PC which allows you to OK a child app, WGM requires you to find the child app that fails and add it to the allowed application list."
    You people are making things hard on yourselves here.
    It is all very simple. One more time, just allow following:
    /Library/
    /Applications/
    Then just disallow any applications that you want.
    The problem described here is that non-admin users cannot run Adobe Creative Suite 6, correct? So, if the users are not admins, then they cannot copy anything to those folders. Hence, there is no issue. They cannot run applications from any other folder, either. Test it.
    Clear as mud?

  • Java application not working

    Running Win98. I somehow removed the Java application from my computer, and am unable to open any java appelets or javascript. Where can I download the JVM for Win98. Currently all I have is JVM 1.5.0_05 (which is for Win98SE), and doesn't work. I went back to the MSJVM which doesn't work either. Any help would be greatly appreciated.

    Don't know, but I uninstalled it. I'm trying to get 1.4.2_07 back.

  • Run java application only on a specific machine!!!???

    I have my java application and I want that my application run only on a singular computer.
    I want anybody take my application and use it without my permission!
    Is it possible that my application read the cpu's serial number of the computer where it is installed? or other unique identifier
    Thanks

    You can put varous gotcha's in the program and then obfuscate it, but anything can be decompiled and re-engineered.
    Put your computer in your room, no internet connection, take off the floppy and DVD/CD burner and then put a great security alarm in your room. That is about the best you can do to keep your application from being stolen.
    Aside from these things--you're going to have to trust a little that everyone is not out to steal your stuff. Ask any security company off the record and they will all admit--total security is an illusion, but you can choose varying degrees of difficulty to take your stuff.

  • Applications only work in admin accounts

    I am installing os 10.6.8 into a master iMac Intel Duo Core (some one year olds and some 3 year olds) computer and am need to deploy onto computers in a lab for students. I click on Parental controls to limit their applications. I allow everything but System Preferences. When I log in as the student (a managed account) I cannot access Illustrator and some other Adobe products. I cannot access Safari, Firefox, and a host of others.
    I get a message saying I'm not allowed to use the application and i get a dialogue box to say "Always Allow" but it never allows after I use admin pw to allow. It just keeps asking for the admin pw.
    The account works fine is I don't limit applications but the students will have access to changing the system preferences and passwords for student logins.
    The same thing is happening if I try to use 10.7.
    Does anyone have this issue? Is there a fix for it? Is there a workaround? Anything?
    ANY help would be greatly appreciated.

    "If you checked  "allow users to manage this computer" in system preferences it is not a managed account. Trying to set this up locally does not work."
    Not true.  OD or AD accounts are Managed, but may also be admins. But this is not the case in my Mac labs. I am doing this via the local machine.
    "So (and I'm doing some educated guessing here), you might remove the settings in Workgroup Manager for that user or group, and then logon and execute the apps.  Then restore the settings."
    Just set the radio button (in Workgroup Manager, Applications) to "Never," save, and then start over using my method.
    "I will have to confess that in this context, I don't know what whitelist means.  But if it means that everyone has access to these folders, then it defeats the purpose that I am using it for. I did get Workgroup Manager to work, but unlike PC which allows you to OK a child app, WGM requires you to find the child app that fails and add it to the allowed application list."
    You people are making things hard on yourselves here.
    It is all very simple. One more time, just allow following:
    /Library/
    /Applications/
    Then just disallow any applications that you want.
    The problem described here is that non-admin users cannot run Adobe Creative Suite 6, correct? So, if the users are not admins, then they cannot copy anything to those folders. Hence, there is no issue. They cannot run applications from any other folder, either. Test it.
    Clear as mud?

  • Java Application working fine,JSP App. throwing error for same reference

    hi all
    i had written java(window) application and jsp(web) application with the same reference(third party reference)
    Java Application is working fine but when i try run JSP application the following error came up
    java.lang.NoClassDefFoundError: com/documentum/fc/client/DfClient
    could any one help me out of this issue? i am in very need of that one it will be very helpfull to me.
    Thank You
    Regards
    Oersla Afrzoe Ahmed

    hi thanks for reply
    cant i put the reference to the JAR Files(such as classpath e.t.c.,) so that all my JSP Application take a reference from thier?
    is that i have to copy all my jar files physically to al my each individual JSP application web-inf/lib folder?
    how to find out where my particular JSP App. web-inf folder exists?
    Regards
    Oersla Afroze Ahmed

  • Calling Java application from servlet

    Hi !
    I'm trying to run a Java application from within a servlet with Tomcat 4. I'm using the Runtime.getRuntime ().exec () method. So the application is run in a different JVM as a subprocess of the servlet. I use ObjectInputStream and ObjectOutputStream and a serializable object to enable communication between the servlet and the application.
    I tested the application and the serializable object with another Java application that works as the caller and it works fine. However, replacing the caller application with the servlet I get a StreamCorruptedException. The structure of the caller application and the servlet is the same.
    My questions are:
    - Is there something I should configure in Tomcat to create a subprocess ?
    - What is the cause of the StreamCorruptedException ? How do I get it with the servlet and not with the application ?
    - Should I use an environment with the call to Runtime.getRuntime ().exec () ? How do I use it ?
    - Is the called application forced to run in my servlet's context ?
    - Is there a better way to do this ?
    Thanks to all

    Here's my code:
    1. The serializable object:
    // Object Obj
    import java.io.*;
    public class Obj implements Serializable
    public int n;
    public Obj ()
    n = 0;
    public Obj (int n)
    this.n = n;
    public String toString ()
    return getClass ().getName () + " -> (n = " + n + ")";
    2. The application Sub (subprogram)
    // Application Sub
    import java.io.*;
    public class Sub
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, InterruptedException, ClassNotFoundException
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj;
    ois = new ObjectInputStream (System.in);
    obj = (Obj) ois.readObject ();
    f = new File ("Sub.txt");
    fw = new FileWriter (f);
    fw.write (obj.toString ());
    fw.close ();
    oos = new ObjectOutputStream (System.out);
    oos.writeObject (obj);
    ois.close ();
    oos.close ();
    3. The application AMain (caller application)
    // Application AMain
    import java.io.*;
    class AMain
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, ClassNotFoundException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    r = Runtime.getRuntime ();
    p = r.exec ("java Sub");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    B.comunica (obj);
    System.out.println ("AMain sends to Sub: " + obj.toString ());
    try
    p.waitFor ();
    catch (InterruptedException e)
    System.out.println ("Subprogram was interrupted");
    System.out.println (e.toString ());
    ois = new ObjectInputStream (p.getInputStream ());
    System.out.print ("Sub sends to AMain: ");
    obj2 = (Obj) ois.readObject ();
    System.out.println (" " + obj2.toString ());
    oos.close ();
    ois.close ();
    p.destroy ();
    4. The servlet SMain (the calling servlet)
    // Servlet SMain
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class SMain extends HttpServlet
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    int state, i;
    res.setContentType ("text/html");
    ServletOutputStream out = res.getOutputStream ();
    out.println ("<html>");
    out.println ("<head><title>Sub</title></head>");
    out.println ("<body>");
    out.println ("Invoking subprogram...");
    out.println ("<br>");
    try
    r = Runtime.getRuntime();
    p = r.exec ("java -cp .;c:\\Programs\\Apache~1.0\\webapps\\SMain\\WEB-INF\\classes Sub");
    out.println ("...invoked<br>");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    out.println ("<br>SMain sends to Sub: " + obj.toString () + "<br>");
    try
    p.waitFor ();
    catch (InterruptedException e)
    out.println ("<br>Subprogram was interrupted<br>");
    out.println ("<br>" + e.toString () + "<br>");
    state = p.exitValue ();
    out.println ("<br>Subprogram state: " + state + "<br>");
    ois = new ObjectInputStream (p.getInputStream ());
    out.print ("<br>Sub sends to SMain: ");
    obj2 = (Obj) ois.readObject ();
    p.destroy ();
    catch (SecurityException e)
    out.println ("<br>SecurityException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (IOException e)
    out.println ("<br>IOException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (Exception e)
    out.println ("<br>Exception<br>");
    out.println ("<br>" + e.toString () + "<br>");
    out.println ("</body>");
    out.println ("</html>");
    So, as you can see, both application AMain and servlet SMain invoke application Sub and pass it the serializable object Obj. Oddly enough, application AMain works fine whereas servlet SMain throws a StreamCorruptedException exception.
    johnpoole said:
    �It's hard to guess what would cause the exception without seeing code, but the interaction between the processes would differ from that between two applications, because the servlet process is started with a different class loader. I'm not sure which one the jvm started by the call would use.�
    How can I enforce that a System classloader be used in the call to Runtime.getRuntime ().exec () ? (I mean by System classloader a classloader equals to the one applications are launched from console).
    johnpoole said
    �Is there a reason why you aren't starting the second process manually and then connecting to it on a port?�
    The idea is providing a Web interface for an application running in the server. The servlet is used to restrict access to this application but once access is granted (passing the servlet) the application should not be constrained.

  • Command` only working in finder

    I've just got a new Macbook Air and used a Time Machine backup from my old Macbook Pro to transfer settings etc. All works fine except now the command` shortcut for switching between windows in the foremost application only works in Finder, whereas it used to work on all applications (Mail, Microsoft word etc.).
    Is there a way to enable this for all other applications again?
    Thanks for any help.

    Reboot your device. Whatever it is that you typed in, a reboot will clear it out.
    Cheers,
    GB

  • UploadedFile & https Only work first time upload ????

    I am using 10.1.3.4 Jdev. I use UploadedFile interface to upload files from local PC and ftp files to unix server. My "upload" web page works between my local PC and Unix server, but it only works first time upload file and ftp between
    https server (application server--weblogic 10.0) and Unix server. If I just use http without SSL and my codes work fine you can upload file as many times you want and ftp them to Unix server. I used FTP not sftp to transfer files from application server to unix server. Can anyone shed some lights on my head ???? Thx.

    Yes. I changed my code to SFT from ftp. it works. Thx. This URL for sftp: http://www.jcraft.com/jsch/ and is very good .
    Edited by: albertpi on Feb 11, 2010 8:05 AM
    Edited by: albertpi on Feb 11, 2010 8:05 AM

  • 10 minute hang in our Java application on HP-UX only...

    10 minute hang in our Java application on HP-UX only...
    To simulate a network outage, we unplug the network cable from the box. Our Java application hangs for 10 minutes on the first #sql statement it encounters, then finally returns an exception. On Windows and Linux boxes the exception is returned immediately under the same conditions.
    Is this an HP-UX com issue, or an Oracle issue?

    It seems that the Java Environment can't connect to the Display (perhaps no XServer is running or the display variable is not set correctly)
    This seems to be the case when the call
    java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
    fails.

  • How to Open or load the swf file only in Java application

    Hai.,
         How I Secure my Flash SWF files(AS2 and AS3).?
         The SWF files are only work through java application. When the java call the swf file that time only it will work otherwise it won't work including browsers also..

    I attached the file to this post. It would be great if you could send me the pdf version of the block diagram. It's not totally finished, but that doesn't matter, I can complete it in school.
    Thank you, really, thank you.
    I know that this is not the purpose of this forum, but it was the easiest solution for my problem.
    Attachments:
    Programma transportmiddel.vi ‏129 KB

  • Delegated Admin web application only requests first 100 accounts?

    Hi,
    - Sun Java System Messenger Express 6.2
    - Delegated Administrator 6.3-0.09 built Sep 6, 2005
    Is this true that the Delegated Admin (DA) web application only requests first 100 accounts?
    Once logged in to DA web application, we only see "Retrieved Users (100)" if we want to see all users; but if we do a search on uid or username, all other users are retrieved.
    One of the admin gave us the following response:
    This is not a directory-related problem, but rather a matter of the design of the DA application you are using. The web-based java app only requests the first 100 accounts from the directory (presented by default as 10 pages of 10 accoints each.) , since you're supposed to be using the search facility to find accounts when you need to modify or delete them.
    This is a deliberate design choice by the Sun programmers who wrote the thing, probably because the directory is capable of holding several thousand accounts and pulling them all would take quite a bit of time (not to mention memory space), so in the interest of response-time speed they limited the data pull.
    I cannot modify this application's functionality. If you need a list of all user accounts in your domain, I can supply an LDIF on request, with any attributes (mail, uid, cn, etc.) that you like.
    Please let us know if there is any way we can view all users (approx. 1000) from DA web application.
    Thank you for your time,
    GJ

    Yes, the terminal commands I gave are changing permissions.
    Properly written OS X apps should run under any user account, and should store any account-specific information in the each user's home folder. Some poorly written apps might only be executable by the administrator. Running the first command I have will make the app executable to all users.
    Some even more poorly written apps will write user data into the application itself rather than to the user's home folder. This is a particularly bad problem with game software, which for example might write high score info into the app itself. If this is the case for your misbehaving apps, the second command I gave will make the app writable by everybody and should solve the problem.

Maybe you are looking for

  • How do you "power search"on the new  itunes?

    How does one power search on the new itunes? Is it still possible?

  • Vostro 200 running Win 7 Pro 64 bit

    Computer won't recognize my onboard sound card and only says Microsoft HD Audio.  Headset mic won't record.  Any help appreciated.  Thanks

  • Reading Large data files from client machine ( urgent)

    Hi, I want to know the best way for reading large data at about 75MB file from client machine and insert to the database. Can anybody provide sample code for it. Loading the file should be done at client machine and inserting into the database should

  • Itunes cant connect to internet

    need help. im using window 7 64 bit. my itunes wont connect to internet. it show message "itunes could not connect to itunes store.An unkonwn error occurred (0x80090318)

  • APPCRASH EXCEL.EXE LCID: 1033

    Has anyone encounter this issues before: Problem signature:   Problem Event Name:                        APPCRASH   Application Name:                             EXCEL.EXE   Application Version:                           14.0.6126.5003   Application