Loading the correct constructor from an init file...
by reading lines like that:
Apple 10 rgb000100255
Apple 20 rgb255150255
from an "init.txt" file
but i get an IllegalArgumentException
when it tries to find the correct constructor based
on the paramTypes array, which contains the
types of the parameters of the appropriate constructor
it seems that the error has to do with the unwrapping
of the class of the primitive types(Integer class in
my program)
any suggestion is welcome,
thanks
here's the complete code,
feel free to try it
(don't forget the "init.txt" file)
import java.io.*;
import java.util.*;
import java.awt.*;
import java.lang.reflect.*;
class FruitMgr
ArrayList fruits;
public
FruitMgr(String name)
fruits = new ArrayList(4);
InitFileLoader init = new InitFileLoader("init.txt");
init.load();
init.close();
return;
public String
toString()
String str = "";
for(int i = 0; i < fruits.size(); i++)
str += fruits.get(i) + "\n";
return str;
private class InitFileLoader
private String filename;
private BufferedReader br;
private String line;
private int linenumber;
private char separator;
private boolean eof;
private Class clazz;
private Class[] paramTypes;
private Object[] initArgs;
public
InitFileLoader(String name)
filename = name;
separator = ' ';
linenumber = 0;
eof = true;
try
br = new BufferedReader(new FileReader(filename));
eof = false;
catch(IOException e)
error("Opening file \"" + filename + "\"");
/*getLine();
while(!eof)
System.out.println(line);
String s;
while((s = getNextWord()) != "")
System.out.println("*" + s);
getLine();
return;
public void
getLine()
try
line = br.readLine();
catch(IOException e)
error("Couldn't read line " + linenumber + " of file \"" + filename + "\"");
if(line != null )
eof = false;
linenumber++;
else
eof = true;
return;
public String
getNextWord()
String word;
if(line.indexOf(separator) != -1)
word = line.substring(0, line.indexOf(separator));
line = line.substring(line.indexOf(separator) + 1);
return word;
else if(line.indexOf(separator) == -1 && line != "")
word = line;
line = "";
return word;
else
return "";
public int
getNumberOfArgs()
int numOfArgs = 0;
for(int i = 0; i < line.length(); i++ )
if(line.charAt(i) == separator)
numOfArgs++;
return numOfArgs;
public void
load()
getLine();
int numOfArgs = getNumberOfArgs();
while(!eof)
System.out.println(line);
String clazzname = getNextWord();
try
clazz = Class.forName(clazzname);
catch(ClassNotFoundException e)
error("Class " + clazzname + " not found");
initArgs = new Object[numOfArgs];
paramTypes = new Class[numOfArgs];
int j = 0;
String arg;
while((arg = getNextWord()) != "")
//System.out.println("*" + arg);
if(Character.isDigit(arg.charAt(0)))
int n = Integer.parseInt(arg);
initArgs[j] = new Integer(n);
paramTypes[j] = initArgs[j].getClass();
System.out.println("+++" + paramTypes[j]);
j++;
else if(arg.startsWith("rgb"))
int len = 3;
arg = arg.substring(len, arg.length());
int red = Integer.parseInt(arg.substring(0, len));
arg = arg.substring(len, arg.length());
int green = Integer.parseInt(arg.substring(0, len));
arg = arg.substring(len, arg.length());
int blue = Integer.parseInt(arg.substring(0, len));
initArgs[j] = new Color(red, green, blue);
paramTypes[j] = initArgs[j].getClass();
System.out.println("+++" + paramTypes[j]);
j++;
try
Constructor con[] = clazz.getConstructors();
for(int i = 0; i < Array.getLength(paramTypes); i++)
System.out.println("****" + paramTypes);
for( int k = 0; k < Array.getLength((Object)con); k++ )
Object o = con[2].newInstance(initArgs);
System.out.println("****" + o);
fruits.add(o);
/* preferred way */
/*Constructor con = clazz.getConstructor(paramTypes);
Object o = con.newInstance(initArgs);
System.out.println("****" + o);
fruits.add(o);*/
catch(InstantiationException e)
error("Instantiation");
catch(IllegalAccessException e)
error("IllegalAccess");
catch(IllegalArgumentException e)
error("IllegalArgument");
catch(InvocationTargetException e)
error("InvocationTarget");
/*catch(NoSuchMethodException e)
error("NoSuchMethod");
initArgs = null;
paramTypes = null;
getLine();
return;
public void
close()
try
br.close();
catch(IOException e)
error("Closing file \"" + filename + "\"");
return;
private void
error(String message)
System.err.println("Exception occured : " + message);
return;
class Fruit
String name;
int weight;
public
Fruit()
name = "Fruit";
weight = 1;
return;
public
Fruit(int kilos)
this();
weight = kilos;
return;
public int
getWeight()
return weight;
public String
toString()
return name + " " + weight;
class Apple extends Fruit
Color col;
public
Apple()
super();
name = "Apple";
col = Color.red;
public
Apple(Color c)
super();
name = "Apple";
col = c;
public
Apple(int kilos, Color c)
super(kilos);
name = "Apple";
col = c;
public Color
getColor()
return col;
public String
toString()
return name + " " + weight + " " + col;
class Foo
public static void main( String[] args )
FruitMgr fmgr2 = new FruitMgr("init.txt");
/*Apple a = new Apple();
Constructor cc[] = a.getClass().getConstructors();
for(int i = 0; i < Array.getLength(cc); i++)
Class c[] = cc[i].getParameterTypes();
System.out.println(cc[i]);
for(int j = 0; j < Array.getLength(c); j++)
System.out.println("\t" + c[j]);
return;
http://www.adtmag.com/java/article.asp?id=4276&mon=8&yr=2001
Similar Messages
-
My XP machine is unable to load iTunes 10.5.1. It gets about halfway loaded then says it can't find Bonjour.msi. However, that file is on the computer. I tried loading the Bonjour.msi from another computer but it came up with the same message. I also tried to remove iTunes from the add/remove sector on Control Panel but it also refused for the same reason. Help, please.
Try:
- iOS: Not responding or does not turn on
- Also try DFU mode after try recovery mode
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
- If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
- Try another cable
- Try on another computer
- If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
Apple Retail Store - Genius Bar
The missing apps could have been done by setting the Restrictions that can hid those apps. If the backup was made with those retrictions set the the Restrictions are also restored.
Thus, if you get it to work restore to factory settings/new iPod, not from backup
You can redownload most iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
I cant up load the correct size image for my cover
I cant up load the correct size image for my cover...please help
Hello tiffgill,
I recommend reviewing the following guidelines for page images for iTunes U:
When creating your provider art for your iTunes 11 and iOS 6 or later provider page, keep the following in mind:
Only submit artwork you can legally share.
Provider art must be JPEG or PNG with appropriate file extensions (.jpg, .png).
iTunes U Public Site Manager only supports RGB color profiles.
Artwork must be at least 3200 pixels in width and 600 pixels in height with a minimum resolution of 72 dpi, with a maximum file size of 5MB.
You can upload a single piece of art that iTunes U Public Site Manager can use across all platforms and devices (see sample below). If you upload a single piece of art you must also:
Make sure that any text or logo is in the center of the artwork, in the Text/Logo Safe Area.
The Minimum View is 994 x 600 pixels. Texts or logos should not exceed the Minimum View of 994 pixels and should not exceed 400 pixels in height.
Ensure that you do not include any text or logos in the Tag Area, as this area is needed for iTunes-related tags. The Tag Area is part of the Minimum View and 200 pixels in height from bottom of the artwork.
For more information and the iTunes Design Specifications, see https://itunesconnect.apple.com/itc/docs/itunes-design-specs.html.
You can find the full article here:
Understanding provider page image guidelines
http://sitemanager.itunes.apple.com/help/AboutYourProviderPage/chapter_5_section _3.html#//apple_ref/doc/uid/iTUPSM-CH5-SW2
Thank you for using Apple Support Communities.
Best,
Sheila M. -
Removing the Control Characters from a text file
Hi,
I am using the java.util.regex.* package to removing the control characters from a text file. I got below programming from the java.sun site.
I am able to successfully compile the file and the when I try to run the file I got the error as
------------------------------------------------------------------------D:\Debi\datamigration>java Control
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repet
ition
{cntrl}
at java.util.regex.Pattern.error(Pattern.java:1472)
at java.util.regex.Pattern.closure(Pattern.java:2473)
at java.util.regex.Pattern.sequence(Pattern.java:1597)
at java.util.regex.Pattern.expr(Pattern.java:1489)
at java.util.regex.Pattern.compile(Pattern.java:1257)
at java.util.regex.Pattern.<init>(Pattern.java:1013)
at java.util.regex.Pattern.compile(Pattern.java:760)
at Control.main(Control.java:24)
Please help me on this issue.
Thanks&Regards
Debi
import java.util.regex.*;
import java.io.*;
public class Control {
public static void main(String[] args)
throws Exception {
//Create a file object with the file name
//in the argument:
File fin = new File("fileName1");
File fout = new File("fileName2");
//Open and input and output stream
FileInputStream fis =
new FileInputStream(fin);
FileOutputStream fos =
new FileOutputStream(fout);
BufferedReader in = new BufferedReader(
new InputStreamReader(fis));
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(fos));
// The pattern matches control characters
Pattern p = Pattern.compile("{cntrl}");
Matcher m = p.matcher("");
String aLine = null;
while((aLine = in.readLine()) != null) {
m.reset(aLine);
//Replaces control characters with an empty
//string.
String result = m.replaceAll("");
out.write(result);
out.newLine();
in.close();
out.close();Hi,
I used the code below with the \p, but I didn't able to complie the file. It gave me an
D:\Debi\datamigration>javac Control.java
Control.java:24: illegal escape character
Pattern p = Pattern.compile("\p{cntrl}");
^
1 error
Please help me on this issue.
Thanks&Regards
Debi
// The pattern matches control characters
Pattern p = Pattern.compile("\p{cntrl}");
Matcher m = p.matcher("");
String aLine = null; -
My JSP engine won't load the new source from my page
My JSP engine won't load the new source from my page, even know I saved it, and I restarted apache, and resaved the files again, no dice! It must be running off of cash, it's not in my browser cash I cleared it out too, what else can I do?
Tomcat checks to see if the JSP has changed since it was last compiled with you request that page... So, if the file is updated, it should recompile it. Are you sure that when you update the page, you're updating the same copy of the page? (the location defined in the server.xml file)
-
Loading a database table from a UNIX file
hi,
Need A program to load a database table from a UNIX file
thnks.HI,
report zmjud001 no standard page heading.
tables: z_mver.
parameters: test(60) lower case default '/dir/judit.txt'.
data: begin of unix_intab occurs 100,
field(53),
end of unix_intab.
data: msg(60).
***open the unix file
open dataset test for input in text mode message msg.
if sy-subrc <> 0.
write: / msg.
exit.
endif.
***load the unix file into an internal table
do.
read dataset test into unix_intab.
if sy-subrc ne 0.
exit.
else.
append unix_intab.
endif.
enddo.
close dataset test.
***to process the data. load the database table
loop at unix_intab.
z_mver-mandt = sy-mandt.
z_mver-matnr = unix_intab-field(10).
translate z_mver-matnr to upper case.
z_mver-werks = unix_intab-field+10(4).
translate z_mver-werks to upper case.
z_mver-gjahr = sy-datum(4).
z_mver-perkz = 'M'.
z_mver-mgv01 = unix_intab-field+14(13).
z_mver-mgv02 = unix_intab-field+27(13).
z_mver-mgv03 = unix_intab-field+40(13).
to check the data on the screen (this is just for checking purpose)
write: / z_mver-mandt, z_mver-matnr, z_mver-werks, z_mver-gjahr,
z_mver-perkz, z_mver-mgv01,
z_mver-mgv02, z_mver-mgv03.
insert z_mver client specified.
*if the data already had been in table z_mver then sy-subrc will not be
*equal with zero. (this can be *interesting for you - (this list is
*not necessary but it maybe useful for you)
if sy-subrc ne 0.
write:/ z_mver-matnr, z_mver-werks.
endif.
endloop.
1. This solution is recommended only if the database table is NOT a standard SAP database table .
Cheers,
Chandra Sekhar. -
Is there a way to get the correct order from the dependent types of a sche
Hi ,
I have a CT facing the following problem:
When trying to built a SQL script to create all the object types within a schema using the DBMS_METADATA packages.
Did insert in a table the names of the types that will be exported following a concrete order, next loop into the table and call the DBMS_METADATA package for each row.
These type are depedent between them, there are some type attributes calling other types and here the issue
First : try to generate the order by created column of dba_objects and when the generated SQL script is launched a lot of type appearing as incomplete state due to the order isn't correct.
Second : try to insert the table ordering by object_id colums of dba_tables view, it appears incomplete types too.
Currently want to insert the table using a recursive query with connect by against the dba_type_attrs starting with the rows when ATTR_TYPE_NAME is not null (the types that are called by other types), but this way has a issue dificult to resolve: the roots of hierarchy are the rows when ATTR_TYPE_NAME is not null and we've dependencies between roots nodes
The question is is there a way to get the correct order from the dependent types of a schema?
Platform: IBM SP AIX
DB version: 9.2.0.7
Any help will be appreciated .
Thanks in advance.The xxx_dependencies view should give you the dependencies betwee nthe various types. I would look at something along the lines of:
SELECT object_name, referenced_name
FROM (SELECT o.object_name, d.referenced_name
FROM user_objects o, user_dependencies d
WHERE o.object_name = d.name(+) and
o.object_type = d.type(+) and
d.referenced_type(+) = 'TYPE' and
o.object_type = 'TYPE')
START WITH referenced_name IS NULL
CONNECT BY PRIOR object_name = referenced_nameThe outer join between user_objects and user_dependencies is required to generate the names of types which are not dependent on other types, or do not have other types dependent on them.
HTH
John -
How do i remove the exif metadata from my jpg file produced with a digital camera photo?
How do i remove the exif metadata from my jpg file produced with a digital camera photo?
The excellent and free utility Irfanview has the option to remove the EXIF data.
Simply open and the file and do a Save, or Save As with the original name.
Surprisingly, the default is to not keep the original EXIF data. -
How do I get the java code from a class file ?
I want to know how to findout the java code from a .class file . Is there any utility or any way to get the java code from a .class file. If so , please let me know the step by step procedure .
Thanks
ShivaCheck out Mocha (http://www.brouhaha.com/~eric/computers/mocha.html)
It's free! -
Hi everybody, I am trying to create a DVD pal without menu with the program iDVD from a .mov file. Any ideas? Thanks so much.
(From fellow poster Mishmumken: )
How to create a DVD in iDVD without menu (there are several options):
1. Easy: Drop your iMovie in the autoplay box in iDVD's Map View, then set your autoplay item (your movie) to loop continously. Disadvantage: The DVD plays until you hit stop on the remote
2. Still easy: If you don't want your (autoplay) movie to loop, you can create a black theme by replacing the background of a static theme with a black background and no content in the dropzone (text needs to be black as well). Disadvantage: The menu is still there and will play after the movie. You don't see it, but your disc keeps spinning in the player.
3. Still quite easy but takes more time: Export the iMovie to DV tape, and then re-import using One-Step DVD.
Disadvantage: One-Step DVD creation has been known to be not 100% reliable.
4. (My preferred method) Easy enough but needs 3rd party software: Roxio Toast lets you burn your iMovie to DVD without menu - just drag the iMovie project to the Toast Window and click burn. Disadvantage: you'll need to spend some extra $$ for the software. In Toast, you just drop the iMovie project on the Window and click Burn.
5. The "hard way": Postproduction with myDVDedit (freeware)
Tools necessary: myDVDedit ( http://www.mydvdedit.com )
• create a disc image of your iDVD project, then double-click to mount it.
• Extract the VIDEO_TS and AUDIO_TS folders to a location of your choice. select the VIDEO_TS folder and hit Cmd + I to open the Inspector window
• Set permissions to "read & write" and include all enclosed items; Ignore the warning.
• Open the VIDEO_TS folder with myDVDedit. You'll find all items enclosed in your DVD in the left hand panel.
• Select the menu (usually named VTS Menu) and delete it
• Choose from the menu File > Test with DVD Player to see if your DVD behaves as planned.If it works save and close myDVDedit.
• Before burning the folders to Video DVD, set permissions back to "read only", then create a disc image burnable with Disc Utility from a VIDEO_TS folder using Laine D. Lee's DVD Imager:
http://lonestar.utsa.edu/llee/applescript/dvdimager.html
Our resident expert, Old Toad, also recommends this: there is a 3rd export/share option that give better results. That's to use the Share ➙ Media Browser menu option. Then in iDVD go to the Media Browser and drag the movie into iDVD where you want it.
Hope this helps! -
How to find the dsn name from an *.rpd file provided?
How to find the dsn name from an *.rpd file provided? All the ODBC details which would require to run your dashboard.
Hi
DSN name is not a part of .rpd file. So There is no information about DSN name in .rpd file.
Thanks
Siddhartha P -
Application to Read and Write the Configuration Data from a xml file
Hi,
I have to develop a Webdynpro application that will do the following:
Read the Configuration data from an xml file
If stored in a file , and the file is not found, prompt the user to provide the file location.
Pre-Populate the screen(table) with the configuration data
Allow the user to edit the data
Store the configuration data when the user hits the Save button
The config xml file details are as follows:
Regardless of the location of the configuration data, the following fields will be stored
Application (string) will always contain u201CSFA_EDOCSu201D
Key (string) eg LDAP_USER, DB_PREFIX, etc.
Type (character) u201CPu201D = Plain Text, u201CEu201D = Encrypted
Value (string)
Since I am new to WD, I would require help on this.
Please help.Its Urgent.
Regards,
Vaishali.
Edited by: vaishali dhayalan on Sep 19, 2008 8:29 AMHi,
I have to develop a Webdynpro application that will do the following:
Read the Configuration data from an xml file
If stored in a file , and the file is not found, prompt the user to provide the file location.
Pre-Populate the screen(table) with the configuration data
Allow the user to edit the data
Store the configuration data when the user hits the Save button
The config xml file details are as follows:
Regardless of the location of the configuration data, the following fields will be stored
Application (string) will always contain u201CSFA_EDOCSu201D
Key (string) eg LDAP_USER, DB_PREFIX, etc.
Type (character) u201CPu201D = Plain Text, u201CEu201D = Encrypted
Value (string)
Since I am new to WD, I would require help on this.
Please help.Its Urgent.
Regards,
Vaishali.
Edited by: vaishali dhayalan on Sep 19, 2008 8:29 AM -
I down loaded the Aperture trial from the internet. I bought the Aperture 3. I put the Apple Product Serial Number appropriate litlle box. However when I open the Aperture 3 program, it still says Aperture 3 Trial Library. Is this normal?
Hi TD,
Thank you for the quick reply, very helpful. Now I can sleep in peace and without worry. I had transferred 30.000 pictures and was a little worried.
Kind regards,
Peter. -
What is the best way to load and convert data from a flat file?
Hi,
I want to load data from a flat file, convert dates, numbers and some fields with custom logic (e.g. 0,1 into N,Y) to the correct format.
The rows where all to_number, to_date and custom conversions succeed should go into table STG_OK. If some conversion fails (due to an illegal format in the flat file), those rows (where the conversion raises some exception) should go into table STG_ERR.
What is the best and easiest way to archive this?
Thanks,
Carsten.Hi,
thanks for your answers so far!
I gave them a thought and came up with two different alternatives:
Alternative 1
I load the data from the flat file into a staging table using sqlldr. I convert the data to the target format using sqlldr expressions.
The columns of the staging table have the target format (date, number).
The rows that cannot be loaded go into a bad file. I manually load the data from the bad file (without any conversion) into the error table.
Alternative 2
The columns of the staging table are all of type varchar2 regardless of the target format.
I define data rules for all columns that require a later conversion.
I load the data from the flat file into the staging table using external table or sqlldr without any data conversion.
The rows that cannot be loaded go automatically into the error table.
When I read the data from the staging table, I can safely convert it since it is already checked by the rules.
What I dislike in alternative 1 is that I manually have to create a second file and a second mapping (ok, I can automate this using OMB*Plus).
Further, I would prefer using expressions in the mapping for converting the data.
What I dislike in alternative 2 is that I have to create a data rule and a conversion expression and then keep the data rule and the conversion expression in sync (in case of changes of the file format).
I also would prefer to have the data in the staging table in the target format. Well, I might load it into a second staging table with columns having the target format. But that's another mapping and a lot of i/o.
As far as I know I need the data quality option for using data rules, is that true?
Is there another alternative without any of these drawbacks?
Otherwise I think I will go for alternative 1.
Thanks,
Carsten. -
How to edit PSA and continue the load with corrected data from PSA.
Hi,
Can you guide me on how to edit data in PSA and then continue a load?
i.e. if you can provide me with the steps on how to fix a load problem if a load fails. The load fails and Monitor shows red, so how do I fix them in the PSA and then allow the load continue with the corrected data into the data target.
I will appreciate the details steps involved.
ThanksHi
First select that request then turn to Red and delete the Request , delete the qeruest then system allow to edit the psa data ,selete psa then selet packet then selet record double click modify the data, dont forget after completing save the data. after competing modification then select psa right click select- start update immediatly......
thanks
ram
Maybe you are looking for
-
10.4.11 Pro Tools Compatability
As i was installing 10.4.11 through software update an error occoured in the update. I then had to do an archive install. Once installed i ran the 10.4.11 combo update. Everything is working fine except Pro Tools. Everytime i try to launch the applic
-
Don't see the SCM Installation Guide on 9i Developer Suite CD
Hi everybody, I don't see the SCM Installation Guide on my 9i Developer Suite CD. The CD is Release 2 (9.0.2.0.0) for Windows. I do see a file for the release notes titled 'Oracle Software Configuration Manager Release Notes Oracle9i Developer Suite
-
Beginner trying to get my beans to work with jsp on tomcat
Please help me open my eyes! I know this is a stupid oversight on my part, but I've been working for days on getting other things to work on my tomcat server, so I'm out of ideas on this one. I've followed all the tomcat docs instructions on where to
-
Getwa not assigned in SAPLSLVC
Hi All! I have a problem at the execution of an ALV. I have automaticaly the "Getwa not assigned" dump. I checked the name of the fields that are in fieldcatalog as I saw on the internet and checked my internal table has the same field than the field
-
Localize app. using Bundle.properties files, need help
Hi! I used tutorial to internationalize my app.: http://www.oracle.com/technology/products/jdev/101/howtos/jsfinter/index.html I use Jdeveloper 11g. Have 2 files: LocalizeKokaugi.properties and LocalizeKokaugi_en.properties. My app is internationaliz