ram shyam

Ranch Hand
+ Follow
since May 04, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ram shyam

Hi all,

Yes, its basically because I have the changeListener called inside a for loop which was the cause of this. Now I have changed this and it works perfectly fine.

Thanks for your help!
15 years ago
yes, this is the code I am using. Since I am using a JoptionPane inside the if condition, and the since the tabbedPane is getting selected automatically by the program after I select it once, the JoptionPane appears multiplt times everytime after I press OK in the JoptionPane.

Any idea what the problem is?

Thanks in advance!!
15 years ago
Hi all,

I am using a JTabbedPane and in the changeListener(), I have the code to do some operation if the selected tab name is of a particluar name. But the stateChanged() method is called multiple times for a single selection. Any idea of how to restrict this?

Here is my code -

---------------------------------------------------------------

tabPane.addChangeListener(new ChangeListener(){

public void stateChanged(ChangeEvent arg0) {

String tabName = tabPane.getTitleAt(tabPane.getSelectedIndex());

if (//condition)
{
// do some operation
}

}
----------------------------------------------------------------

Please clarify!

thanks in advance!!

});
15 years ago
Hi,

Currently I have one more issue to be solved. When I run the following code from eclipse IDE, the code runs fine. But when I create a jar file with the class files and run that jar file from command line, I get the following error - C:\WINNT\system32\ntvdm.exe Erro while setting up environment for the application. Choose 'Close' to terminate the application

-------------------------------------------------------------------------------------------------------------

try
{
String osName = System.getProperty("os.name" );
String[] cmd = new String[4];
if( osName.startsWith("Win"))
{
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "unzip";
cmd[3] = fileName;
}

Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2] + " " + cmd[3]);

process = runTime.exec(cmd);
InputStream ins = process.getErrorStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins));
String line = null;
while((line = bfr.readLine()) != null) {
System.out.println(line);
}
int exitval = process.waitFor();
System.out.println("Wait over..." + exitval);



}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
-----------------------------------------------------------------------------------------------------------------------

Please let me know how to solve this issue.
Thanks in advance!!
15 years ago
Hi,

Thanks for your reply!

I looked into the artilce and the unzip works fine now but unzips the zip file in the current location of where the code is running. But, I wanted the unzip to happen in the same location as that of .zip file is present. So, I used the command as - "unzip <filename> -d <target> which throws "parameter incorrect error".

Following is the code -
---------------------------------------------------------------------------------
zipFileLocation = fileName.substring(0, fileName.length()-4);
try
{
String osName = System.getProperty("os.name" );
String[] cmd = new String[6];
if( osName.equals( "Windows NT" ) )
{
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "unzip";
cmd[3] = fileName;
cmd[4] = "-d";
cmd[5] = zipFileLocation;
}
else if( osName.equals( "Windows 2000" ) )
{
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "unzip";
cmd[3] = fileName;
cmd[4] = "-d";
cmd[5] = zipFileLocation;
}

Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2] + " " + cmd[3] + " " + cmd[4] + " " + cmd[5]);

process = runTime.exec(cmd);
InputStream ins = process.getErrorStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins));
String line = null;
while((line = bfr.readLine()) != null) {
System.out.println(line);
}




}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}

------------------------------------------------------------------------

Follwing is the error -
Cannot run program "command.com": CreateProcess error=87, The parameter is incorrect

Please let me know how to resolve this.

Thanks in advance!!
15 years ago
Hi,

Thanks for your reply!

Now, I am not getting that error but looks like unzip is not working. I tried to print the errorStream to check if there is any error occured during unzip, but bfr.readLine() hangs. If I remove the errorStream code, no exception is caught, the code runs fine but no unzip occurs. I could not find any unzipped folder created in windows.

------------------------------------------------
String[] command = {"unzip" ,fileName};
System.out.println("command " + command[0] + command[1]);
try
{
process = runTime.exec(command);
InputStream ins = process.getErrorStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins));
String line = null;
while((line = bfr.readLine()) != null) {
System.out.println(line);
}


}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
---------------------------------------------------------------------------------

Please help me in solving this issue.

Thanks in advance!!
15 years ago
Hi all,

To re-iterate the problem I am facing, following is the code I am using -

--------------------------------------------------------------------------------------------
final int BUFFER = 2048;
try {
BufferedOutputStream dest = null;
BufferedInputStream is = null;
ZipEntry entry;
ZipFile zipfile = new ZipFile(fileName);
Enumeration e = zipfile.entries();

zipFileLocation = fileName.substring(0, fileName.length()-8);
new File(fileName.substring(0, fileName.length()-4)).mkdirs();

while(e.hasMoreElements()) {
entry = (ZipEntry) e.nextElement();
System.out.println("Extracting: " +entry);
is = new BufferedInputStream
(zipfile.getInputStream(entry));
int count;
byte data[] = new byte[BUFFER];

if (!(entry.getName().substring(entry.getName().indexOf("/"))).endsWith("txt")) // To check if its a .txt file or a directory
new File(zipFileLocation + entry.getName().substring(entry.getName().indexOf("/"))).mkdirs(); // create the unzipped directories
else
new File(zipFileLocation + entry.getName().substring(entry.getName().indexOf("/"))).createNewFile(); // create the .txt file under the unzipped directories
FileOutputStream fos = null;
if (!entry.isDirectory())
{
fos = new FileOutputStream(zipFileLocation + "/" + entry.getName().substring(entry.getName().indexOf("/")));
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = is.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
}
dest.flush();
dest.close();
is.close();
}
} catch(Exception e) {
e.printStackTrace();
}
-----------------------------------------------------------------------------------------------

The above code creates the unzipped directories and the .txt files correctly but only few .txt files are empty without any contents which I am still unable to resolve. Hence I tried using the Runtime library in which I am facing the problem in windows but not in solaris. Following is the code -


-----------------------------------------------------------------------------------------------------

Runtime runTime = Runtime.getRuntime();
Process process = null;
String[] command = {"unzip " + fileName};
System.out.println("command " + command);
try
{
process = runTime.exec(command);
InputStream ins = process.getErrorStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins));
System.out.println(bfr.readLine());
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}

----------------------------------------------------------------------------------

When the filename is C:\Documents and Settings\egrdeep\My Documents\maud.zip, I get the following error as -
unzip: cannot find either C:/Documents or C:/Documents.zip. Looks like the space is the problem while running in windows. Please let me know a solution to either the java.util.zip problem or the Runtime unzip problem.

Thanks in advance!!
15 years ago
Hi all,

I tried changing the writing FOS part of the code as follows but still the output is the same. Few .txt files are created but still there are no contents in them -

FileOutputStream fos = null;
if (!entry.isDirectory())
{
fos = new FileOutputStream(fileName.substring(0, fileName.length()-4) + "/" + entry.getName().substring(entry.getName().indexOf("/")));
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = is.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
}

Please let me know if there is any other means of doing unzip of a folder.zip. Since this code seems not to be working in all cases.

Thanks in advance!!
15 years ago
Hi,

No, there are no exceptions caught as well. I have checked by uncommenting the printstacktrace code. The while loop of writitng to the fileoutputstream is called only once in those files and the content is empty. I have no clue why this happens to selective files.

Please let me know what would have gone wrong.

Thanks in advance!!
15 years ago
Hi all,

I am using the following code to unzip a folder but eventually I find that few files are just created but has no content in them. I have no clue why few files are missed out in writing the content alone.



The folder structure after unzip will be -
Parent - containing 3 folders - each containinng multiple .txt files. In this few .txt files are empty (has no content inside). Please let me know what could be the problem in which only few files are missed out while unzipping.

Thanks in advance!!

[ UD: Please UseCodeTags when posting code of any length. It's unnecessarily hard to read without them, making it less likely that people will take the time to do so (and thus be able to answer your question). ]
15 years ago
Hi,

How do I use WINRAR in JAVA code?
15 years ago
Hi all,

I tried using GZIPInputStream on the file of type .tar.gz and wrote the outputstream which returned a file of type VisualPax Archive instead of a .tar type. So, I am not able to use any Runtime code to run "tar xvf" on the generated output file and untar the folder.

Please let me know how to extract the folder of type .tar.gz which contains multiple text files.

Thanks in advance!!
15 years ago
Hi all,

As per one of my project requirements, in which we do not have the license agreement to add any 3pps to the existing product, I want to convert a XSD to POJO. Since the project is built on jre1.4 version, JAXB jars cannot be shipped as per the license agreement. If it had been jre1.6 version, then the jaxb APIs could have been implicity used and the unmarshalling can be done with ease.

So, in this scenario, as I had mentioned earlier, I can very well code the getters and setters using JAVA Beans for each element defined in the XSD file. But once this is done, how will I parse the xml document contents using the getters that I have created earlier. Ofcourse, I know that there exists the JAXB, XMLBeans APIs to unmarshall the xml document to JAVA objects. But without using these APIs, is there any means to get this done?
Please clarify.

Thanks in advance!!
Hi all,

I would like to convert a xml schema file (.xsd) to corresponding JAVA objects without using any 3pps like JAXB or XMLBeans. I can probably write down the POJO (getters and setters) for each element/attribute corresponding to the xsd file. But, without using any of the either JAXB APIs or XMLBeans APIs, how can i parse the xml document contents to the POJO that I have created earlier?

Please let me know if this is possible or any other means to achieve the same.

Thanks in advance!!
Hi all,

I am using the JAXB apis and the xjc utitlity in my project. The code I am writing should be compatible for both jdk 1.4 and jdk 1.6 versions. I tried the following -

Used xjc of jdk1.6 and generated JAVA source code for a .xsd file and compiled the JAVA source files and used these class files and able to unmarshall the xml file in jdk1.6 environment. I used the same source code of unmarshalling as shown below - in jdk1.4 environment using the same class files generated using the xjc of 1.6 version, but I am getting unsupported version error.

==============================unmarshall code==============================

try{
JAXBContext jc = JAXBContext.newInstance("com.ericsson.jaxb");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Items items = (Items)unmarshaller.unmarshal(new File("Items.xml"));
List itemList = items.getItem();
for(int i=0; i<itemList.size();i++){
Item item = (Item)itemList.get(i);
System.out.println("Name = " + item.getName() +
", Price = " + item.getPrice() + ", Id = " + item.getId());

}
}
catch(Exception e)
{
e.printStackTrace();
}

=============================================================================

The error I get in jdk1.4 - javax.xml.bind.JAXBException: Provider com.sun.xml.bind.ContextFactory could not be instantiated: java.lang.UnsupportedClassVersionError: com/ericsson/jaxb/ObjectFactory (Unsupported major.minor version 50.0)

So, there is a compatibility issue between the generated source code for a .xsd file in jdk1.4 and jdk1.6 versions. Is there a solution to address this in JAXB? If not, is there any other way to create JAVA objects, given a .xsd file other than unmarshalling using JAXB?

Please clarify.

Thanks in advance!!
">