Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java.lang.runtime.exec cannot resolve symbol

Reply
Thread Tools

java.lang.runtime.exec cannot resolve symbol

 
 
Darren
Guest
Posts: n/a
 
      11-14-2005
i'm invoking to use Java's 'exec' but the documentation says its in the
java.lang.runtime class.. i import it as well as java.lang.process but the
when i compile the programme that calls it i get a "cannot resolve symbol"
on the "exec" line. which is 'exec(JarSignerPath);'

The code for this class alone is below;

package uk.me.g7wap.jarmaker;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.event.ActionEvent;

import java.io.File;
import java.lang.Runtime;
import java.lang.Process;
public class Jarmaker
{

private static String JarSignerPath=null;

public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{

UIManager.setLookAndFeel("com.sun.java.swing.plaf. windows.WindowsLookAndFeel
");

}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
ex.printStackTrace();
}
final JFrame w = new JFrame("Desktop Window");
final JDesktopPane desktop = new JDesktopPane();
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem menuItem = new JMenuItem("New");
JMenuItem menuFileNewJar = new JMenuItem("Create JAR",KeyEvent.VK_J);
JMenuItem menuFileNewZip = new JMenuItem ("Create ZIP",KeyEvent.VK_Z);
JMenuItem menuFileOpenJar = new JMenuItem("Open JAR",KeyEvent.VK_F3);
JMenuItem menuFileOpenZip = new JMenuItem ("Open ZIP",KeyEvent.VK_F3);
JMenuItem menuFileSetRoot = new JMenuItem("Set Root
Dir",KeyEvent.VK_R);
JMenuItem menuFileSignJar =new JMenuItem("Sign Jar",KeyEvent.VK_J);
JMenuItem menuFileExit = new JMenuItem("Exit",KeyEvent.VK_X);
w.setContentPane(desktop);
w.setJMenuBar(menuBar);
menuBar.add(menuFile);
menuFile.add(menuItem);

menuFileNewJar.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_J,ActionEve
nt.ALT_MASK));

menuFileNewZip.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_Z,ActionEve
nt.ALT_MASK));

menuFileSetRoot.setAccelerator(KeyStroke.getKeyStr oke(KeyEvent.VK_R,ActionEv
ent.ALT_MASK));

menuFileExit.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_X,
ActionEvent.ALT_MASK));
menuFileExit.getAccessibleContext().setAccessibleD escription("Exit");

menuFile.add(menuFileNewJar);
menuFile.add(menuFileNewZip);
menuFile.add(menuFileOpenJar);
menuFile.add(menuFileOpenZip);
menuFile.add(menuFileSetRoot);
menuFile.add(menuFileSignJar);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
menuItem.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
//-- Create a JarFileFrame --
JarFileFrame JIF = new JarFileFrame("pickles");
desktop.add(JIF);
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
//---------------------
}
});

menuFileNewZip.addActionListener
(
new ActionListener()
{

public void actionPerformed(ActionEvent e)
{
ZipFileFilter myfilter=new ZipFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);

fc.setFileSelectionMode(JFileChooser.FILES_AND_DIR ECTORIES);
int lnReturnVal = fc.showSaveDialog(w);

ZipFileFrame JIF = new
ZipFileFrame(fc.getSelectedFile().getAbsolutePath( ),desktop);
File loJarOutFile = fc.getSelectedFile();

if (loJarOutFile.exists())
{
String title = "New";
JOptionPane loOverwriteConfirm = new JOptionPane();
int lnResult=loOverwriteConfirm.showConfirmDialog(w,"F ile
exists, overwrite?","File Exists",JOptionPane.YES_NO_OPTION);
if(lnResult==0)
{
desktop.add(JIF);
try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}
}
else
{
desktop.add(JIF);
try
{

Zip outzip = new
Zip("*.*",loJarOutFile.getCanonicalPath(),"c:\\App lets");
}
catch (java.io.IOException eee)
{
}

try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}
}



}
}
);

menuFileOpenZip.addActionListener
(
new ActionListener()
{

public void actionPerformed(ActionEvent e)
{

JarFileFilter myfilter=new JarFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);

fc.setFileSelectionMode(JFileChooser.FILES_AND_DIR ECTORIES);
int lnReturnVal = fc.showOpenDialog(w);

ZipFileFrame JIF = new
ZipFileFrame(fc.getSelectedFile().getAbsolutePath( ),desktop);
File loJarOutFile = fc.getSelectedFile();


desktop.add(JIF);
try
{


JIF.openZipFile(loJarOutFile.getCanonicalPath());
}
catch (java.io.IOException eee)
{
}

try
{
JIF.setSelected(true);
}
catch (java.beans.PropertyVetoException ee)
{
}




}
}
);

menuFileSignJar.addActionListener
(
new ActionListener()
{

public void actionPerformed(ActionEvent e)
{

if (JarSignerPath==null)
{
JarSignerFilter myfilter=new JarSignerFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);

fc.setFileSelectionMode(JFileChooser.FILES_AND_DIR ECTORIES);
fc.setDialogTitle("Where is JarSigner?");
int lnReturnVal = fc.showOpenDialog(w);

File loJarSignerFile = fc.getSelectedFile();
JarSignerPath=loJarSignerFile.getAbsolutePath();

}
JarFileFilter myfilter=new JarFileFilter();
JFileChooser fc = new JFileChooser();
fc.resetChoosableFileFilters();
fc.setFileFilter(myfilter);

fc.setFileSelectionMode(JFileChooser.FILES_AND_DIR ECTORIES);
fc.setDialogTitle("Jar File to Sign?");
int lnReturnVal = fc.showOpenDialog(w);

File loJarOutFile = fc.getSelectedFile();
exec(JarSignerPath);


}
}
);


w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setSize(700,500);
w.setLocation(50,50);
w.setVisible(true);
}






}



 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      11-14-2005
Darren wrote:

> i'm


Sentences that are easy to read are more likely to get
read. Using an uppercase character at the beginning
of a sentence helps to make posts easier to read.

>...invoking to use Java's 'exec' but the documentation says its in the
> java.lang.runtime class..


That is becasue it is.

>..i import it


No need. java.lang.* is imported by default.

>..as well as java.lang.process


ditto.

>.. but the
> when i compile the programme that calls it i get a "cannot resolve symbol"
> on the "exec" line. which is 'exec(JarSignerPath);'


Please always copy/paste errors, or the first lines
of stack traces.

> The code for this class alone is below;


252 lines of uncompilable* code is unlikely to get much
attention. If you need to post code, please post either
a very short snippet, or an SSCCE.
<http://www.physci.org/codes/sscce.jsp>

* had to fix code lines broken by being too wide, and
hunt through the errors caused by the missing classes.

But to your more immediate problem..

> File loJarOutFile = fc.getSelectedFile();
> exec(JarSignerPath);


F:\...Jarmaker\Jarmaker.java:227: cannot find symbol
symbol: method exec(java.lang.String)
exec(JarSignerPath);
^

<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)>
OK. 'exec(String)' is a method of a Runtime object. if we had
a runtime object called 'runtime' you might invoke it using..

runtime.exec("the command");

If that method were declared 'static', you would not even
require the object, but instead invoke it from the static context..

Runtime.exec("the command");

...in your code, your call effectively becomes..

this.exec("the command");

...where 'this' is an instance of Jarmaker, which has no 'exec'
method.

The error is saying there is no 'exec(String)' method for
the Jarmaker class, because that is where the compiler
thinks you mean to find it.

To get a instance of a Runtime object, see
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#getRuntime()>

And, as 2 asides..
1) It pays to ask a question - though we've already been there.
2) The best groups for helping those new to Java is..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH
 
Reply With Quote
 
 
 
 
Bjorn Abelli
Guest
Posts: n/a
 
      11-14-2005

"Darren" <(E-Mail Removed)> skrev i meddelandet
news:Vh1ef.2079$(E-Mail Removed)...
> i'm invoking to use Java's 'exec' but the documentation says its in the
> java.lang.runtime class.. i import it as well as java.lang.process but the
> when i compile the programme that calls it i get a "cannot resolve symbol"
> on the "exec" line. which is 'exec(JarSignerPath);'


Due to the strictness of OO in Java, any method must be an instance method
or a class method.

This also affects how you can call it, i.e. *only* through an instance or a
class. When you don't provide a "receiver" for the call, the current
instance or class is considered the default reciever.

To take the "exec"-method as an example.

You don't have an "exec"-method in your class JarMaker, because exec is an
instance method for a Runtime-object.

Hence you can't call it just by:

exec(whatever);

....you have to have an instance to send the message exec to, e.g.

myRuntime.exec(whatever);

There's also a class method to retrieve a reference to the "current"
Runtime-instance, so here's how you can proceed:

Runtime myRuntime = Runtime.getRuntime();
myRuntime.exec(JarSignerPath);

I can't guarantee that it will work in your particular case, as I didn't
check if your "JarSignerPath" is valid as an argument to exec.

To read further:

http://java.sun.com/j2se/1.5.0/docs/...g/Runtime.html

// Bjorn A




 
Reply With Quote
 
klynn47@comcast.net
Guest
Posts: n/a
 
      11-14-2005
Remember that Java is case sensitve. It isn't java.lang.runtime. It's
java.lang.Runtime

 
Reply With Quote
 
Darren
Guest
Posts: n/a
 
      11-15-2005

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:A%1ef.17403$(E-Mail Removed)...
> Darren wrote:
>
> > i'm

>
> Sentences that are easy to read are more likely to get
> read. Using an uppercase character at the beginning
> of a sentence helps to make posts easier to read.


You can read, 'I'm' but you can't read 'i'm'?
>
> >...invoking to use Java's 'exec' but the documentation says its in the
> > java.lang.runtime class..

>
> That is becasue it is.
>
> >..i import it

>
> No need. java.lang.* is imported by default.
>
> >..as well as java.lang.process

>
> ditto.


Yo see I didn't know that and even then I don't take things as red because
if I do then knowing my luck a future version will not include them as red.
:\
>
> >.. but the
> > when i compile the programme that calls it i get a "cannot resolve

symbol"
> > on the "exec" line. which is 'exec(JarSignerPath);'

>
> Please always copy/paste errors, or the first lines
> of stack traces.


I did,
"cannot resolve symbol"

>
> > The code for this class alone is below;


>
> 252 lines of uncompilable* code is unlikely to get much
> attention. If you need to post code, please post either
> a very short snippet, or an SSCCE.
> <http://www.physci.org/codes/sscce.jsp>


Look I'm not being funny but will you guys make up your minds? I got moaned
at for not posting the whole code now i did you moan at me. Why don't you
guys decide what you want and put it in the faq then we all know where we
are. or perhaps you have already and I missed it

>
> * had to fix code lines broken by being too wide, and
> hunt through the errors caused by the missing classes.
>
> But to your more immediate problem..
>
> > File loJarOutFile = fc.getSelectedFile();
> > exec(JarSignerPath);

>
> F:\...Jarmaker\Jarmaker.java:227: cannot find symbol
> symbol: method exec(java.lang.String)
> exec(JarSignerPath);
> ^
>
>

<http://java.sun.com/j2se/1.5.0/docs/...l#exec(java.la
ng.String)>
> OK. 'exec(String)' is a method of a Runtime object. if we had
> a runtime object called 'runtime' you might invoke it using..
>
> runtime.exec("the command");
>
> If that method were declared 'static', you would not even
> require the object, but instead invoke it from the static context..
>
> Runtime.exec("the command");
>
> ..in your code, your call effectively becomes..
>
> this.exec("the command");
>
> ..where 'this' is an instance of Jarmaker, which has no 'exec'
> method.


hehe well i thought it would include it as i did the import
>
> The error is saying there is no 'exec(String)' method for
> the Jarmaker class, because that is where the compiler
> thinks you mean to find it.
>
> To get a instance of a Runtime object, see
>

<http://java.sun.com/j2se/1.5.0/docs/...ml#getRuntime()
>


Many thanks. I replaced it with 'Runtime.getRuntime().exec(JarSignerPath);'

I know i could have done it tidier but it works.
>
> And, as 2 asides..
> 1) It pays to ask a question - though we've already been there.


Yeah i haven't read your reply to tthat yet
> 2) The best groups for helping those new to Java is..
> <http://www.physci.org/codes/javafaq.jsp#cljh>

Hey we should all help each other and my proggy isn't bad for one written by
a newbie
>
> HTH


It did. thanks a lot


 
Reply With Quote
 
Darren
Guest
Posts: n/a
 
      11-15-2005

"Bjorn Abelli" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Darren" <(E-Mail Removed)> skrev i meddelandet
> news:Vh1ef.2079$(E-Mail Removed)...
> > i'm invoking to use Java's 'exec' but the documentation says its in the
> > java.lang.runtime class.. i import it as well as java.lang.process but

the
> > when i compile the programme that calls it i get a "cannot resolve

symbol"
> > on the "exec" line. which is 'exec(JarSignerPath);'

>
> Due to the strictness of OO in Java, any method must be an instance method
> or a class method.
>
> This also affects how you can call it, i.e. *only* through an instance or

a
> class. When you don't provide a "receiver" for the call, the current
> instance or class is considered the default reciever.
>
> To take the "exec"-method as an example.
>
> You don't have an "exec"-method in your class JarMaker, because exec is an
> instance method for a Runtime-object.
>
> Hence you can't call it just by:
>
> exec(whatever);
>
> ...you have to have an instance to send the message exec to, e.g.
>
> myRuntime.exec(whatever);
>
> There's also a class method to retrieve a reference to the "current"
> Runtime-instance, so here's how you can proceed:
>
> Runtime myRuntime = Runtime.getRuntime();
> myRuntime.exec(JarSignerPath);
>
> I can't guarantee that it will work in your particular case, as I didn't
> check if your "JarSignerPath" is valid as an argument to exec.
>
> To read further:
>
> http://java.sun.com/j2se/1.5.0/docs/...g/Runtime.html
>
> // Bjorn A
>

Very helpful, thanks very much.

>
>
>



 
Reply With Quote
 
Darren
Guest
Posts: n/a
 
      11-15-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Remember that Java is case sensitve. It isn't java.lang.runtime. It's
> java.lang.Runtime
>

Well spotted dude.


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-15-2005
Darren wrote:

>>>The code for this class alone is below;

>
>
>>252 lines of uncompilable* code is unlikely to get much
>>attention. If you need to post code, please post either
>>a very short snippet, or an SSCCE.
>><http://www.physci.org/codes/sscce.jsp>

>
> Look I'm not being funny but will you guys make up your minds?


I am but one person, I have my opinions.

Some people agree with me, some people don't, others don't care
enough about what I have to say to listen long enough to make a
choice.

>..I got moaned
> at for not posting the whole code now i did you moan at me.


Who asked you for the whole code? I requested an *SSCCE*,
that is a very different thing, with some very specific
requirements. Requirements not met by your code.

Consider that there were fixes required to see the code run.
If two people wanted to see it, both of them had to fix the
errors, errors you might not have posted in the first place,
had you prepared an SSCCE.

>.. Why don't you
> guys decide what you want and put it in the faq


...Is this a troll, Darren? [1]

The closest thing that this group has to an FAQ is mentioned
in the Java mini-FAQ posted regularly to this, and several other
groups. The Java FAQ that is mentioned, resides at my site, and
was compiled by me, with the help of a number of other people.

Having said that, the words I put in that FAQ are not entirely
acceptable to all participants of these groups, and it is not
the 'official' FAQ of this (or any other) Java group.

[1] If so - "Ya' Got Me!"

>>2) The best groups for helping those new to Java is..
>><http://www.physci.org/codes/javafaq.jsp#cljh>

>
> Hey we should all help each other and my proggy isn't bad for one written by
> a newbie


I do not understand what you are getting at, but I will be more plain.

I would not normally offer the level of description and detail
I did in that post, at least, not here on c.l.j.programmer.

OTOH, I (as well as some other people who help out on c.l.j.h.)
set out to 'take more time' when answering questions on c.l.j.help.
Also, the general nature of the discussion on help is different,
there are things (accusations, derision..) flung about on
c.l.j.programmer without comment, that would prompt a severe
criticism on c.l.j.help.

>>HTH


> It did. thanks a lot


You're welcome.
 
Reply With Quote
 
Michael Dunn
Guest
Posts: n/a
 
      11-15-2005

"Darren" <(E-Mail Removed)> wrote in message
news:Vh1ef.2079$(E-Mail Removed)...
> i'm invoking to use Java's 'exec' but the documentation says its in the
> java.lang.runtime class.. i import it as well as java.lang.process but the
> when i compile the programme that calls it i get a "cannot resolve symbol"
> on the "exec" line. which is 'exec(JarSignerPath);'
>
> The code for this class alone is below;

<snipped>

I don't have some of the classes required to run the program, but if
everything
unrelated to the problem is stripped, and hard-code a string representing a
program
to run (which seems to be the intention of 'exec(..)') - in this e.g. using
notepad,
the compiler generates a "can't find symbol" error (after leaving all the
imports as is)

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.event.ActionEvent;

import java.io.File;
import java.lang.Runtime;
import java.lang.Process;
class Jarmaker
{
private static String JarSignerPath="notepad.exe";
public static void main(String[] args)
{
exec(JarSignerPath);
}
}

exec is unknown because it is a method of Runtime
Runtime may be imported, but it is not used

change
exec(JarSignerPath);
to
try{Runtime.getRuntime().exec(JarSignerPath);}catc h(Exception e){}

compile/run and see what happens



 
Reply With Quote
 
Darren
Guest
Posts: n/a
 
      11-15-2005

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:clhef.18049$(E-Mail Removed)...
> Darren wrote:
>
> >>>The code for this class alone is below;

> >
> >
> >>252 lines of uncompilable* code is unlikely to get much
> >>attention. If you need to post code, please post either
> >>a very short snippet, or an SSCCE.
> >><http://www.physci.org/codes/sscce.jsp>

> >
> > Look I'm not being funny but will you guys make up your minds?

>
> I am but one person, I have my opinions.
>
> Some people agree with me, some people don't, others don't care
> enough about what I have to say to listen long enough to make a
> choice.
>
> >..I got moaned
> > at for not posting the whole code now i did you moan at me.

>
> Who asked you for the whole code? I requested an *SSCCE*,
> that is a very different thing, with some very specific
> requirements. Requirements not met by your code.


I had to look up *SSCCE*
>
> Consider that there were fixes required to see the code run.
> If two people wanted to see it, both of them had to fix the
> errors, errors you might not have posted in the first place,
> had you prepared an SSCCE.


No problem, but it's misunderstanding like this that call for a group FAQ
and no that wasn't a troll.
>
> >.. Why don't you
> > guys decide what you want and put it in the faq

>
> ..Is this a troll, Darren? [1]


Nope.
>
> The closest thing that this group has to an FAQ is mentioned
> in the Java mini-FAQ posted regularly to this, and several other
> groups. The Java FAQ that is mentioned, resides at my site, and
> was compiled by me, with the help of a number of other people.


Perhaps the group might see it as a suitable one for this group.
>
> Having said that, the words I put in that FAQ are not entirely
> acceptable to all participants of these groups, and it is not
> the 'official' FAQ of this (or any other) Java group.
>
> [1] If so - "Ya' Got Me!"


LOL no, you still win, it wasn't a troll.
>
> >>2) The best groups for helping those new to Java is..
> >><http://www.physci.org/codes/javafaq.jsp#cljh>

> >
> > Hey we should all help each other and my proggy isn't bad for one

written by
> > a newbie

>
> I do not understand what you are getting at, but I will be more plain.
>
> I would not normally offer the level of description and detail
> I did in that post, at least, not here on c.l.j.programmer.


It was very kind of you to do so.
>
> OTOH, I (as well as some other people who help out on c.l.j.h.)
> set out to 'take more time' when answering questions on c.l.j.help.
> Also, the general nature of the discussion on help is different,
> there are things (accusations, derision..) flung about on
> c.l.j.programmer without comment, that would prompt a severe
> criticism on c.l.j.help.

erm ok
>
> >>HTH

>
> > It did. thanks a lot

>
> You're welcome.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
src-resolve: Cannot resolve the name ... ivanet@gmail.com XML 1 03-23-2007 12:10 PM
unexpected token / cannot resolve symbol error vivienne wykes Java 4 07-28-2004 06:48 PM
Cannot resolve symbol Jo Java 3 04-10-2004 06:12 PM
Re: Cannot resolve Symbol (class) but why? (JSP) @lex-kid Java 2 07-07-2003 07:26 AM
Re: Cannot resolve Symbol (class) but why? (JSP) sufia Java 1 07-06-2003 07:06 PM



Advertisments