Home » Developer & Programmer » Forms » determining cd rom's drive letter in forms 6i (forms 6i)
icon6.gif  determining cd rom's drive letter in forms 6i [message #365086] Wed, 10 December 2008 22:31 Go to next message
salman2k960
Messages: 12
Registered: September 2005
Junior Member
salam
Problem:
I want to determine drive letter of the first CD-ROM installed.

Details:
On a form, i have supplied a browse button to open a file using "GET_FILE_NAME". what i want is that file chooser dialog box should open showing Cd-Rom files(i.e CD-ROM as default location to look for files).
I have tried to do this using Java stored procedure with following class, but somehow, im getting NULLPOINTEREXCEPTION.

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "GETDRIVETYPE" AS
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;


class GetDriveType {
 public static String GetCdDrive()
 {
  JFileChooser chooser = new JFileChooser(); 
  String fileTypeName= new String("no drive");
  File file[] = File.listRoots(); 
     for (int i=0;i<file.length;i++)
     {
	    if (chooser.getTypeDescription(file[i]).equals("CD Drive"))
    	fileTypeName= file[i].toString();
     }

 return fileTypeName;
 }
}


This code runs perfectly in JDK, and even gets compiled in Oracle as well. but it gives error at runtime when it tries to execute the line:

JFileChooser chooser = new JFileChooser();

i have read somewhere on OTN that oracle JVM does not support swing or awt and that some HEADLESS awt has been added. But im still unable to find any solution.

Another code that i have tried is:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "GETDRIVETYPE" AS
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;


class GetDriveType {
 public static String GetCdDrive()
 { 
  FileSystemView fsv = FileSystemView.getFileSystemView();
  String fileTypeName= new String("no drive");
  File file[] = File.listRoots(); 
     for (int i=0;i<file.length;i++)
     {
   	   if (fsv.getSystemTypeDescription(file[i]).equals("CD Drive"))
       fileTypeName= file[i].toString();
     }

 return fileTypeName;
 }
}


Now amazingly, this code compiles,runs and give results in JDK, but it fails to even compile in Oracle JVM!!! it gives error

Method getSystemTypeDescription not found in class javax.swing.filechooser.FileSystemView

this probably is because of some jdk version diff.(btw,im using oracle 9i r2)
My only workaround is to use following VB script to write cd rom letter to a file and then reading it from that file.
Dim CDPath as String
Private Sub Form_Load()
Dim fso As New Scripting.FileSystemObject
Dim drv As Drive

For Each drv In fso.Drives
     If drv.DriveType = 4 Then
          CDPath = drv.Path
          Exit For
     End If
Next drv
Set drv = Nothing
Set fso = Nothing
End Sub

Is there any way to do this in forms 6i?
Looking forward for response.

[EDITED by LF: applied [code] tags instead of (the original) [i] (italic) tags]

[Updated on: Thu, 11 December 2008 00:14] by Moderator

Report message to a moderator

Re: determining cd rom's drive letter in forms 6i [message #380458 is a reply to message #365086] Mon, 12 January 2009 00:08 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Did you solve your problem?

David
Re: determining cd rom's drive letter in forms 6i [message #381599 is a reply to message #380458] Sun, 18 January 2009 22:21 Go to previous message
salman2k960
Messages: 12
Registered: September 2005
Junior Member
no. I had to hardcode the path.
thanx for your concern.
Previous Topic: GET_FORM_PROPERTY
Next Topic: How to write data on com port & how to open electric door (merged)
Goto Forum:
  


Current Time: Sat Dec 10 05:24:43 CST 2016

Total time taken to generate the page: 0.12168 seconds