What's the simplest way to pass an array of ints to a class
Did I word that right when I called it a "class"? Anyway, doing the obvious doesn't work i.e. from the (String[] args) that occurs in every java program, I thought that using (int[] arg), where arg is an array of ints would work, but it doesn't appear to be as simple as that.
Here's my code:
// Construct a shape from user input
class Shape {
int sides;
void Shape(int[] specs) {
sides = specs[0];
class CreateShape {
public static void main(String[] args) {
if(args.length < 3) {
System.out.println("usage: CreateShape [number of sides], [side1], [side2], ...");
return;
int arg[] = new int[args.length];
int i = 0;
for(String s : args) {
System.out.println("is is: "+i);
arg[i] = Integer.parseInt(s);
i++;
if(arg[0] != args.length + 1) {
System.out.println("You did not specify the correct number of sides");
System.out.println("usage: Shape [number of sides], [side1], [side2], ...");
return;
Shape shape = new Shape(arg);
}I'm just getting one error now:
Shape.java:33: cannot find symbol
symbol : constructor Shape(int[])
location: class Shape
Shape shape = new Shape(arg);
^
1 error
Edited by: psvm on Mar 31, 2008 11:43 AM
Similar Messages
-
What is the simplest way to get a xml-file from 10g R2 -database ?
Hi,
I'm new in xml, there are so many tools to work with xml:
what is the simplest way to get a xml-file from 10g R2 -database ?
I have : 10g R2 and a xsd.file to describe the xml-structure
thank you
NorbertThere is no automatic way to generate XML documents from an arbitary set of relational tables using the information contained in an XML Schema. Typically the easiest way to generate XML from relational data is to use the SQL/XML operators (XMLElement, XMLAGG, XMLAttribtues, XMLForest). There are many examples of using these operators in the forums You can validate the generated XML against the XML Schema by registering the XML Schema with XML DB and then using the XMLType.SchemaValidate() method
-
What is the simplest way to make a movie from BufferedImages?
I have a 3d rendered animation from which I can grab BufferedImages of each frame. What is the simplest way I can create a movie from these images?
I've seen the JpegImagesToMovie.java file and not only is it suprisingly overcomplicated, it requires me to change the code so that I can get images from memory rather than from files.
Is there some simple way of creating a movie which requires a few statements? I'm also prepared to use QuickTime for Java. I don't care about the format, since I can just use any video converter to convert it to my desired video format.I recently came up with a simplified JpegImagesToMovie program. It generates QuickTime movies with a single video track output as a file. Input is a series of jpegs (currently as a list of file names, but easily modified to a take any form of jpeg data.) Since the compression used by the movie is JPEG, if you have an uncompressed image buffer, you'll need to convert that into jpeg data bytes with some quality setting. (Since its a movie file, go with something low if you have a lot of similar images.) This will even run without a full install of jmf--no native code is called (as far as I could tell..)
Here is the source code, sorry about the formatting!
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URL;
import java.util.Vector;
import javax.media.Buffer;
import javax.media.Format;
import javax.media.MediaLocator;
import javax.media.format.VideoFormat;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.FileTypeDescriptor;
import com.sun.media.multiplexer.video.QuicktimeMux;
* This program takes a list of JPEG image files and converts them into a
* QuickTime movie.
* This was based on Sun's JMF Sample Code JpegImagesToMovie.java 1.3 01/03/13
* This code is an attempt to reduce the complexity to demonstrate a very basic
* JPEG file list to movie generator. It does not use a Manager or Processor
* class, so it doesn't need to implement any event listening classes. One
* advantage of this simplified class is that you can just link it with the
* jvm.jar file. (you might also need to track down the com.ms.security library
* stubs, use google. You'll need PermissionID.java and PolicyEngine.java.)
* I tried to get it to generate AVI files without success.
* These output files are could use further compression.
* A Vector of jpeg image paths was one way to do this--the appropriate
* methods can be overwritten to grab images from another source
* --zip file, http, etc.
* - Brad Lowe; Custom7; NuSpectra; 2/10/2005
* The existing Copyright from Sun follows.
* Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGES.
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear facility.
* Licensee represents and warrants that it will not use or redistribute the
* Software for such purposes.
public class SimpleMovie
Vector images; // jpeg image file path list
VideoFormat format; // format of movie to be created..
// Sample code.
public static void main(String args[])
try
// change imageDir to the location of a directory
// of images to convert to a movie;
String imageDir = "images";
File d = new File(imageDir);
SimpleMovie imageToMovie = new SimpleMovie();
// change width, height, and framerate!
// Excercise: Read width and height of first image and use that.
imageToMovie.init(320, 240, 10.0f);
imageToMovie.setFiles(d);
File dest = new File("simple.mov");
imageToMovie.createMovie(dest);
System.err.println("Created movie " + dest.getAbsolutePath() + " "
+ dest.length() + " bytes.");
} catch (Exception e)
System.out.println(e.toString());
e.printStackTrace();
// return jpeg image bytes of image zIndex (zero-based index)
public byte[] getImageBytes(int zIndex) throws IOException
if (images == null)
return null;
if (zIndex >= images.size())
return null;
String imageFile = (String) images.elementAt(zIndex);
// Open a random access file for the next image.
RandomAccessFile raFile = new RandomAccessFile(imageFile, "r");
byte data[] = new byte[(int) raFile.length()];
raFile.readFully(data);
raFile.close();
return data;
// Call this before converting a movie;
// Use movie width, height;
public void init(int width, int height, float frameRate)
format = new VideoFormat(VideoFormat.JPEG,
new Dimension(width, height), Format.NOT_SPECIFIED,
Format.byteArray, frameRate);
// Set up the files to process
public void setFiles(Vector inFiles)
images = inFiles;
// point converter to jpeg directory. Only does one level,
// but could recurse, but then sorting would be interesting..
public void setFiles(File dir) throws Exception
if (dir.isDirectory())
if (images == null)
images = new Vector();
String l[] = dir.list();
for (int x = 0; x < l.length; x++)
if (l[x].toLowerCase().endsWith(".jpg"))
File f = new File(dir, l[x]);
images.addElement(f.getAbsolutePath());
// Crank out the movie file.
public void createMovie(File out) throws Exception
if (format == null)
throw new Exception("Call init() first.");
String name = out.getAbsolutePath();
QuicktimeMux mux = null; // AVI not working, otherwise would use
// BasicMux
if (out.getPath().endsWith(".mov"))
mux = new QuicktimeMux();
mux.setContentDescriptor(new ContentDescriptor(
FileTypeDescriptor.QUICKTIME));
} else
throw new Exception(
"bad movie file extension. Only .mov supported.");
// create dest file media locator.
// This sample assumes writing a QT movie to a file.
MediaLocator ml = new MediaLocator(new URL("file:"
+ out.getAbsolutePath()));
com.sun.media.datasink.file.Handler dataSink = new com.sun.media.datasink.file.Handler();
dataSink.setSource(mux.getDataOutput()); // associate file with mux
dataSink.setOutputLocator(ml);
dataSink.open();
dataSink.start();
// video only in this sample.
mux.setNumTracks(1);
// JPEGFormat was the only kind I got working.
mux.setInputFormat(format, 0);
mux.open();
// Each jpeg goes in a Buffer.
// When done, buffer must contain EOM flag (and zero length data?).
Buffer buffer = new Buffer();
for (int x = 0;; x++)
read(x, buffer); // read in next file. x is zero index
mux.doProcess(buffer, 0);
if (buffer.isEOM())
break;
mux.close();
// close it up
dataSink.close();
// Read jpeg image into Buffer
// id is zero based index of file to get.
// Always starts at zero and increments by 1
// Buffer is a jmf structure
public void read(int id, Buffer buf) throws IOException
byte b[] = getImageBytes(id);
if (b == null)
System.err.println("Done reading all images.");
// We are done. Set EndOfMedia.
buf.setEOM(true);
buf.setOffset(0);
buf.setLength(0);
} else
buf.setData(b);
buf.setOffset(0);
buf.setLength(b.length);
buf.setFormat(format);
buf.setFlags(buf.getFlags() | Buffer.FLAG_KEY_FRAME);
} -
What is the simplest way to get video from mini DV tapes into computer
My computer has no firewire connection. What is the simplest way to get the video from my camera (JVC GR-D340EK) ?
Mikeathome
Thanks for the reply.
The reason that I asked if this was a one time thing or not was related to my thoughts about asking you to look at the relative costs of have the DV data capture firewire done professional or by a friend versus going through looking for slots on your computer for a firewire card or purchasing a computer that still comes with a firewire port.
We will be watching for further developments.
Thanks.
ATR -
What is the simplest way to create slide show
What is the simplest way to create a slide show ? (Premiere Elements 12)
saploe
What computer operating system is your Premiere Elements 12 running on? Premiere Elements 12 Mac does not have a Slideshow option in its Elements Organizer 12. So, that situation would not yield the two choices of creating the slideshow in the Elements Organizer and taking it into Premiere Elements OR doing the whole project solely in Premiere Elements.
What is going into this slideshow....photos (how many, original pixel dimensions), videos (formats and duration), etc?
What is a description of your computer resources?
How do you intent to export this slideshow...
a. burn to DVD-VIDEO standard or widescreen on DVD disc
b. burn to AVCHD format on DVD disc
c. burn to Blu-ray disc format on Blu-ray disc
d. to file saved to the computer hard drive?
We will customize a reply based on the information that you supply.
Thanks.
ATR -
What is the simplest way to remove duplicates on both iMac and iPad2?
What is the simplest way to remove duplicate photos from both iMac & iPad2?
The implication here is that your music is only on the iPod, for if it is in iTunes, you need only do the restore. So you are really asking how you move the music from your iPod back into iTunes, so that when you restore it will go back to the iPod. Take a look at Para. 8 in this summary post I worked up.
-
what is the simplest way to transfer my music in iTune from my old computer to the new plz.
Move or copy the ENTIRE iTunes folder from the old computer to the new computer.
-
What is the best way to pass a constant to a cin expecting a pointer to a value?
I have a cin which has a leg that is expecting a pointer to a value. On the diagram, what is the best way to connect a constant widget to this leg of the cin? Connecting it directly crashes labview as it treats the constant as a pointer to memory.
ThanksI am not sure that I understand your issue. CIN variables can be Input-Output or Output only. Either way, they are being passed in as a pointer to a value. You can see this very easily by placing down a CIN and wiring a constant integer to it. Next, right-click on the CIN and create the C file. You will see that the parameter list has an int* in it.
If you are still having problems, do you have to create a CIN or can you create a DLL instead? The DLL will give you a few more ways to pass the data than a CIN does with no real performance decrease.
Also, have you read the "Using External Code in LabVIEW" manual? This hsould answer some questions as well.
Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask -
What is the simplest way to create a text on black background?
I am new to In Design and want to make a simple design that is a yellow text with a black background. What is the easiest way to do that? I am on a PC running In Design CS4. This is on a computer at work so it may take awhile for me to get back to anybody who answers. Thanks in advance
If you are a novice then iweb is a good place to start. It will allow you to create a site quickly with the minimum amount of work. You can then learn more as you go along if you want to. To publish you will need web space somewhere. Thats how I started and now I am studying web design with the Open University and am learning xhtml and CSS, then progressing to Java etc. Good luck and have fun - it is quite addictive once you start.
-
I have plenty of DVD which I load in my laptop and watch the movies while travel, however I am not able to do that in my iPad .
I would appreciate some one guide me the simplest way of loading the movies in to my iPad. I tried the conventional procedure of loading/copying in to itune then sync to the iPad to load all movies in it, but failed to do the first step( not able to load /copy in itune) leave aside the sync to iPad next.
Do I need to sellout some 20 odd $ to buy a conversion software that would help?
Is it that Apple trying to make money by not making this simplest of thing possible by the user.( ref. windows, every thing is possible with little IQ of the user).
If it is so , I would stop many of my friends to restrain from buying a device like this by spending some 1000$ ,rather look at a good Droid that is catching up so well.If you are the only user on your computer you probably don't have multiple user accounts set up and can disregard that. If you are using iTunes 11 go to View>Show Sidebar. Now see if your iPad appears under Devices on the left side when you connect it. If it does, click on the name of your iPad on the left side and your iTunes sync settings options will appear in folders with tabbed headings to the right.
If it doesn't appear on the left side, follow the troubleshooting steps shown in this article: http://support.apple.com/kb/TS1538. -
What is the simplest way to convert to one page format?
I have a large file set up as facing pages with the master pages having different margin settings. If I want to change so I will no longer be printing 2-sided output but rather 1-sided, what is the easiest way to change the file? Would I just delete one of the master pages and reset margins?
Thanks,
RichardOff the top of my head, enable layout adjustment before removing or modifying the master.
Layout > Layout Adjustment
Modify the right (?) master (margins).
Verify changes to the live pages.
The master does not explicity need to be removed. -
What is the simplest way to make DVD now?
For years I have used iDVD to distribute wedding videos. It was simple and have nice themed menus. What is the best way to do that now? Can you still install iDVD or is something else better? I'm running 10.9.5 on a current Mac Book Pro.
For years I have used iDVD to distribute wedding videos. It was simple and have nice themed menus. What is the best way to do that now? Can you still install iDVD or is something else better? I'm running 10.9.5 on a current Mac Book Pro.
-
I have a vi that runs through two for loops and a while loop, then after a certain number of iterations on the inner while loop it is supposed to pass a trigger to a case stucture to start measurement. I have tried using a local variable attached to a boolean control which in turn is attached to the true case of the case structure involving the measurement sub vi. What is happening is that the boolean control will light on the front panel at the correct # of iterations in the while loop, as if true, but the measurement is not taken, and the boolean control never goes back to false. It remains lit. Am I u
sing the local variable incorrectly? If so, where am I going wrong.
Attachments:
GL_Flicker.vi 118 KB
Take_Measurements.vi 147 KBHello planar,
There are multiple ways to pass control information between loops and VIs and each one has its place. For simple VIs like your example, a local variable will be fine.
The main reason the subVI is not running is that the case structure is not continuously polling the Boolean control. This is because the case structure is not inside a loop and as such will only read the Boolean value once and execute once. Encasing the case structure and control inside the while loop should solve the issue of the subVI not running.
You may find the following links of help in creating more robust and advanced VI architectures.
Application Design Patter
ns: Master/Slave
LabVIEW Application Design Patterns
Keep up to date on the latest PXI news at twitter.com/pxi -
What is the fastest way to pass data between parallel threads?
I have a top level vi running with 6 parallel threads. I need to pass some data from digital I/O to several of the threads. What is the fastest responding way to do this. I am controlling a machine that has quite a few sensed events happening at very close intervals, some as close together as 1 to 2 milliseconds, and I seem to be randomly missing the signal from these sensors. How can I distribute the I/O to the different threads and not miss any inputs?
I usually use a Queue to pass data from one loop to another. Other
choices are Functional Globals or Notifiers. It kind of depends on what
you need to do as to which one is best, so it's a bit hard to recommend
one over the others without knowing more about your application.
Both Queues and the Functional Globals (if written correctly) can
buffer data so you're less likely to lose data if one loop gets behind
the others.
Ed
Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences. -
Hey there,
My specific task is to bring forward the "Swatches" window. I want to initiate this from my plugin code (C++). However, I may want to execute other menu items in the future, so understanding the simplest, most straightforward general mechanism would be great.
I've pieced together a sequence that could work using the Menu and Interface suites, but it seems more complicated than it should be and requires knowledge of the localized name of the menu item (incomplete and uncompiled sample code below). Is there a better way to do this?
// Get the menu item handle by walking all items to find the swatches item
long numMenuItems = 0;
sAIMenu->CountMenuItems( &numMenuItems );
AIMenuItemHandle menuItemHandle;
ai::UnicodeString localizedItemName;
for ( long menuItemIndex = 0; menuItemIndex < numMenuItems; ++menuItemIndex )
sAIMenu->GetNthMenuItem( menuItemIndex, &menuItemHandle );
sAIMenu->GetItemText( menuItemHandle, localizedItemName );
if ( localizedItemName == “Swatches” )
break;
AIBoolean bchecked =false;
sAIMenu->IsItemChecked( menuItemHandle,
&bchecked );
if ( !bchecked )
// Find the plugin responsible for adding and responding to the menu item
SPPluginRef swatchPlugin;
sAIMenu->GetMenuItemPlugin( menuItemHandle, &swatchPlugin );
// Construct and send a message to the plugin instructing it to execute as if the menu item were invoke by the user
AIMenuMessage message;
sSPInterface->SetupMessageData( swatchPlugin, &message.d );
message.menuItem = menuItemHandle;
SPErr result;
sSPInterface->SendMessage( swatchPlugin, kAIMenuCaller, kSelectorAIGoMenuItem, &message, &result );
sSPInterface->EmptyMessageData( swatchPlugin, &message.d );
Glen.That's a clever solution to a problem I'd never considered (but can see how others might need it) I can't think of a better way to invoke it though than what you're doing except maybe with some minor improvements. If you know the menu group, you can use AIMenuSuite::GetMenuGroupRange() to jump to that group in the overall list. Also, since menuitems seem extremely unlikely to change, you can probably cache the handle.
Beyond that, the usual suggestion I'd make it is to at least explore actions. Try recording an action and see if it even picks up when you display the Swatches panel. I'm guessing it doesn't record stuff like that, but who knows?
Maybe you are looking for
-
Custom options in Adobe PDF printer are not showing up in "Default Settings"
Hello, I am using Windows 7 and I am trying to create custom "Default Settings" in my Adobe PDF printer. When I make edits to an existing setting, click "Save As..." and save with a new filename, the new settings are not showing up in the "Default Se
-
I discovered that when I restored my harddrive a few weeks back, not all of my music in iTunes was restored. Now when I go back to an earlier date in my Time Capsule, I get a message that I don't have permissiom to see the files. What do I need to do
-
I am a complete noob with ajax. I used the photo gallery for a site and would like to change the default click behaviour to a mouseover/mouseout behaviour. Thanks for any help. The code for displaying the gallery looks like this: <div id="thumbContai
-
Ok, Recently I started to record gigs and concerts for friends of mine. I have all the video on several DVD-R's for storage purposes and transfer between computers. I would also like to have it in iTunes for ease of viewing. The problem I am having i
-
Apple TV locked on screen with settings and home sharing icons in bottom half and won't let me move back to main menu. Anyone know how to fix it?