Analog Out from reading a file
I have a written a file .txt which is built from analog in vi's at 2Ks/sec.
How to read a upper mentioned file containing voltage signal data,and how to out the data to the analog out to PCI card at the sampling rate equal to the that of read(2ks/sec).
There are example VIs that generate a waveform datavalue computationally and outputs it through a D/A channel. You could take one of those examples and replace the waveform generation subVI with one that reads the waveform data from your file...
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
Similar Messages
-
How to stop ipod touch dropping out from reading email, then displaying main menu
My wife's Ipod touch (4 or 5 years old) has worked fine for years, but now when reading emails, without touching the screen or any controls, the ipod drops out of the application and displays the main menu after a few seconds. Have rebooted it a couple of times, but the fault persists.
Ipod is a 16Gb with 10.4 Gb available
Does anyone know how I can solve this problem ?Many thanks for your quick reply. The full reset has cured the problem.
Thanks again -
I am suddenly unable to print Adobe Reader pdfs. I am running Reader XI (11.0.05). Printing is fine in all other applications.
What OS? What printer? Did you install any updates about the time this behavior manifested itself? How about error messages? Can you give us any exact error message?
-
Read multiple files and save all into one output file(AGAIN)
Hi, guys
I need your help for reading data from multiple files and save the results into one output file. When files are selected from file chooser, my program read the data line by line , do some calculations and save the result into the output. I made an array to store input files and it seems to be working fine, but when it comes to SaveFile() function, issues NullPointException message.
public class FileReduction1 extends JFrame implements ActionListener
// GUI definition and layout
/* ACTION PERFORMED */
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("Open File")) getFileName();
/* OPEN THE FILE */
private void getFileName() {
// Display file dialog so user can select file to open
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(true);
int result = fileChooser.showOpenDialog(this);
// If cancel button selected return
if (result == JFileChooser.CANCEL_OPTION) return;
if (result == JFileChooser.APPROVE_OPTION)
files = fileChooser.getSelectedFiles();
textArea.setText("");
if(files.length>0)
filelist="";
System.out.println("files length"+files.length);
for(int i=0;i<files.length;i++)
System.out.println(files.getName());
filelist+=files[i].getName()+" ,";
if (checkFileName(files[i]) )
openButton.setEnabled(true);
readButton.setEnabled(true);
textArea.append("file "+files[i].getName()+"is a proper file"+"\n");
readFile(files[i]);
textfield.setText(filelist);
else{JOptionPane.showMessageDialog(this,"Please select file(s)",
"Error 5: ",JOptionPane.ERROR_MESSAGE); }
// Obtain selected file
/* READ FILE */
private void readFile(File fileName_in) {
// Disable read button
readButton.setEnabled(false);
// Dimension data structure
getNumberOfLines(fileName_in);
data = new String[numLines][4];
// Read file
readTheFile(fileName_in);
// Rnable open button
openButton.setEnabled(true);
/* GET NUMBER OF LINES */
/* Get number of lines in file and prepare data structure. */
private void getNumberOfLines(File fileName_in) {
int counter = 0;
// Open the file
openFile(fileName_in);
// Loop through file incrementing counter
try {
String line = fileInput.readLine();
while (line != null) {
counter++;
System.out.println("(" + counter + ") " + line);
line = fileInput.readLine();
numLines = counter;
closeFile(fileName_in);
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error reading File",
"Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile(fileName_in);
System.exit(1);
/* READ FILE */
private void readTheFile(File fileName_in)
// Open the file
//int row=0;
int col=0;
openFile(fileName_in);
System.out.println("Read the file");
// Loop through file incrementing counter
try
String line = fileInput.readLine();
while (line != null)
boolean containsDoubles = false;
double temp;
String[] lineParts = line.split("\t");
try
for (col=0;col<lineParts.length;col++)
temp=Double.parseDouble(lineParts[col]);
data[row][col] = lineParts[col];
containsDoubles = true;
System.out.print("data["+row+"]["+col+"]="+lineParts[col]+" ");
} catch (Exception e) {row=0; col=0; temp=0.0;}
if (containsDoubles){ row++;}
System.out.println();
line = fileInput.readLine();
catch(IOException ioException)
JOptionPane.showMessageDialog(this,"Error reading File", "Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile(fileName_in);
System.exit(1);
//System.out.println("length"+data.length);
closeFile(fileName_in);
process(fileName_in);
/* CHECK FILE NAME */
/* Return flase if selected file is a directory, access is denied or is
not a file name. */
private boolean checkFileName(File fileName_in) {
if (fileName_in.exists()) {
if (fileName_in.canRead()) {
if (fileName_in.isFile()) return(true);
else JOptionPane.showMessageDialog(null,
"ERROR 3: File is a directory");
else JOptionPane.showMessageDialog(null,
"ERROR 2: Access denied");
else JOptionPane.showMessageDialog(null,
"ERROR 1: No such file!");
// Return
return(false);
/* OPEN FILE */
private void openFile(File fileName_in) {
try {
// Open file
FileReader file = new FileReader(fileName_in);
fileInput = new BufferedReader(file);
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
textArea.append("OPEN FILE\n---------\n");
textArea.append(fileName_in.getPath());
textArea.append("\n");
//System.out.println("File opened successfully");
/* CLOSE FILE */
private void closeFile(File fileName_in) {
if (fileInput != null) {
try {
fileInput.close();
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
System.out.println("File closed");
private void process(File fileName_in) {
//getNumberOfLines();
//data = new String[numLines][3];
// Read file
double temp,temp1;
//readTheFile();
//System.out.println("row:"+row);
//int number=data.length;
//System.out.println(number);
for (int i=0; i<row; i++)
temp=Double.parseDouble(data[i][1]);
sumx+=temp;
temp1=Double.parseDouble(data[i][3]);
sumy+=temp1;
multixy+=(temp*temp1);
square_x_sum+=(temp*temp);
square_y_sum+=(temp1*temp1);
//System.out.println("Sum(x)="+sumx);
double tempup=(row*multixy)-(sumx*sumy);
double tempdown=(row*square_x_sum)-(sumx*sumx);
slope=tempup/tempdown;
double tempbup=sumy-(slope*sumx);
intb=tempbup/row;
double tempside=(row*square_y_sum)-(sumy*sumy);
double cordown=Math.sqrt(tempdown*tempside);
corr=tempup/cordown;
r_sqrt=corr*corr;
textArea.append("Data for file"+ fileName_in.getName()+" have been processed successfully.");
textArea.append("\n");
textArea.append("Please enter output file name including extension.");
System.out.println("number"+row);
System.out.println("slope(m)="+slope);
System.out.println("intecept b="+intb);
System.out.println("correlation="+corr);
System.out.println("correlation="+r_sqrt);
saveFile();
private void saveFile()
textArea.append("SAVE FILE\n---------\n");
if (openFile1())
try {
outputToFile();
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Writing to File",
"Error",JOptionPane.ERROR_MESSAGE);
private boolean openFile1 ()
// search for the file path
StringBuffer stringpath;
title=textfield1.getText().trim();
int temp=fileName_in.getName().length();
int temp_path=fileName_in.getPath().length();
int startd=(temp_path-temp);
stringpath=new StringBuffer(fileName_in.getPath());
stringpath.delete(startd, temp_path+1);
//System.out.println("file-path="+temp_path);
//System.out.println("length-file="+temp);
path=stringpath.toString();
fileName_out = new File(path, title);
//System.out.println(file_out.getName());
if (fileName_out==null || fileName_out.getName().equals(""))
JOptionPane.showMessageDialog(this,"Invalid File name",
"Invalid File name",JOptionPane.ERROR_MESSAGE);
return(false);
else
try
boolean created = fileName_out.createNewFile();
if(created)
fileOutput = new PrintWriter(new FileWriter(fileName_out));
fileOutput.println("File Name"+"\t"+"Slope(m)"+"\t"+"y-intercept(b)"+"\t"+"Coefficient(r)"+"\t"+"Correlation(R-Squared)");
return(true);
else
fileOutput = new PrintWriter(new FileWriter(fileName_out,true));
return(true);
catch (IOException exc)
JOptionPane.showMessageDialog(this,"Please enter the file name","Error",JOptionPane.ERROR_MESSAGE);
return(false);
private void outputToFile() throws IOException
// Initial output
textArea.append("File name = " + fileName_out + "\n");
// Test if data exists
if (data != null)
fileOutput.println(fileName_in.getName() +"\t"+ slope+"\t"+intb+"\t"+corr+"\t"+r_sqrt);
textArea.append("File output complete\n\n");
else
textArea.append("No data\n\n");
// End by closing file
initialcomp();
fileOutput.close();
private void initialcomp()
slope=0.0;
intb=0.0;
corr=0.0;
r_sqrt=0.0;
sumx=0.0; sumy=0.0; multixy=0.0; square_x_sum=0.0; square_y_sum=0.0;
for(int i=0;i<data.length;i++)
for(int j=0;j<data[i].length;j++)
data[i][j]=null;
/* MAIN METHOD */
public static void main(String[] args) throws IOException
// Create instance of class FileChooser
FileReduction1 newFile = new FileReduction1("File Reduction Program");
// Make window vissible
newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFile.setSize(500,400);
newFile.setVisible(true);
Sorry about the long lines.
As you can see, all input files saved in array called files, however when OpenFile1() function is called, it take input (fileName_in) as a single file not an array. I'm assuming this causes the exception.
When there's muptiple inputs, program should take each file from getFileName() to outputToFile() sequentially.
Does anybody have an idea to solve this?
Thanks a lot!!you naming convention is confussing. you should follows Java naming convention..you have a getXXX but decalred the return type as "void"...get usully means to return something...
your code is doing too much..and hard to follows..
1. get the selected files
for each selected file
process the file and return the result
write out the result.
/** close the precious resource */
public void closeResource(Reader in){
if (in != null){
try{ in.close(); }
catch (Exception e){}
/** get the total number of line in a file */
public int getLineCount(File file) throws IOException{
BufferedReader in = null;
int lineCount = 0;
try{
in = new BufferedReader(new FileReader(file));
while ((in.readLine() != null)
lineCount++;
return lineCount;
finally{ closeResource (in); }
/** read the file */
public void processFile(File inFile, File outFile) throws IOException{
BufferedReader in = null;
StringBuffer result = new StringBuffer();
try{
in = new BufferedReader(new FileReader(inFile));
String line = null;
while ((in.readLine() != null){
.. do something with the line
result.append(....);
writeToFile(outFile, result.toString());
finally{ closeResource (in); }
public void writeToFile(File outFile, String result) throws IOException{
PrintWriter out = null;
try{
out = new PrintWriter(new FileWriter(outFile, true)); // true for appending to the end of the file
out.println(result);
finally{ if (out != null){ try{ out.close(); } catch (Exception e){} } }
} -
(Urgent help needed) how to read txt file and store the data into 2D-array?
Hi, I have a GUI which allow to choose file from the file chooser, and when "Read file" button is pressed, I want to show the array data into the textarea.
The sample data is like this followed:
-0.0007 -0.0061 0.0006
-0.0002 0.0203 0.0066
0 0.2317 0.008
0.0017 0.5957 0.0008
0.0024 1.071 0.0029
0.0439 1.4873 -0.0003
I want my program to scan through and store these data into 2D array.
However for some reason, my source code issues errors, and I don't know what's wrong with it, seems to have a problem in StringTokenizer though. Can anybody help me?
Thanks in advance.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.StringTokenizer;
public class FileReduction1 extends JFrame implements ActionListener{
// GUI features
private BufferedReader fileInput;
private JTextArea textArea;
private JButton openButton, readButton,processButton,saveButton;
private JTextField textfield;
private JPanel pnlfile;
private JPanel buttonpnl;
private JPanel buttonbar;
// Other fields
private File fileName;
private String[][] data;
private int numLines;
public FileReduction1(String s) {
super(s);
// Content pane
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
// Open button Panel
pnlfile=new JPanel(new BorderLayout());
textfield=new JTextField();
openButton = new JButton("Open File");
openButton.addActionListener(this);
pnlfile.add(openButton,BorderLayout.WEST);
pnlfile.add(textfield,BorderLayout.CENTER);
readButton = new JButton("Read File");
readButton.addActionListener(this);
readButton.setEnabled(false);
pnlfile.add(readButton,BorderLayout.EAST);
cp.add(pnlfile, BorderLayout.NORTH);
// Text area
textArea = new JTextArea(10, 100);
cp.add(new JScrollPane(textArea),BorderLayout.CENTER);
processButton = new JButton("Process");
//processButton.addActionListener(this);
saveButton=new JButton("Save into");
//saveButton.addActionListener(this);
buttonbar=new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonpnl=new JPanel(new GridLayout(1,0));
buttonpnl.add(processButton);
buttonpnl.add(saveButton);
buttonbar.add(buttonpnl);
cp.add(buttonbar,BorderLayout.SOUTH);
/* ACTION PERFORMED */
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("Open File")) getFileName();
if (event.getActionCommand().equals("Read File")) readFile();
/* OPEN THE FILE */
private void getFileName() {
// Display file dialog so user can select file to open
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(this);
// If cancel button selected return
if (result == JFileChooser.CANCEL_OPTION) return;
if (result == JFileChooser.APPROVE_OPTION)
fileName = fileChooser.getSelectedFile();
textfield.setText(fileName.getName());
if (checkFileName()) {
openButton.setEnabled(false);
readButton.setEnabled(true);
// Obtain selected file
/* READ FILE */
private void readFile() {
// Disable read button
readButton.setEnabled(false);
// Dimension data structure
getNumberOfLines();
data = new String[numLines][];
// Read file
readTheFile();
// Output to text area
textArea.setText(data[0][0] + "\n");
for(int index=0;index < data.length;index++)
for(int j=1;j<data[index].length;j++)
textArea.append(data[index][j] + "\n");
// Rnable open button
openButton.setEnabled(true);
/* GET NUMBER OF LINES */
/* Get number of lines in file and prepare data structure. */
private void getNumberOfLines() {
int counter = 0;
// Open the file
openFile();
// Loop through file incrementing counter
try {
String line = fileInput.readLine();
while (line != null) {
counter++;
System.out.println("(" + counter + ") " + line);
line = fileInput.readLine();
numLines = counter;
closeFile();
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error reading File",
"Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile();
System.exit(1);
/* READ FILE */
private void readTheFile() {
// Open the file
int row=0;
int col=0;
openFile();
System.out.println("Read the file");
// Loop through file incrementing counter
try {
String line = fileInput.readLine();
while (line != null)
StringTokenizer st=new StringTokenizer(line);
while(st.hasMoreTokens())
data[row][col]=st.nextToken();
System.out.println(data[row][col]);
col++;
row++;
closeFile();
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error reading File",
"Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile();
System.exit(1);
/* CHECK FILE NAME */
/* Return flase if selected file is a directory, access is denied or is
not a file name. */
private boolean checkFileName() {
if (fileName.exists()) {
if (fileName.canRead()) {
if (fileName.isFile()) return(true);
else JOptionPane.showMessageDialog(null,
"ERROR 3: File is a directory");
else JOptionPane.showMessageDialog(null,
"ERROR 2: Access denied");
else JOptionPane.showMessageDialog(null,
"ERROR 1: No such file!");
// Return
return(false);
/* FILE HANDLING UTILITIES */
/* OPEN FILE */
private void openFile() {
try {
// Open file
FileReader file = new FileReader(fileName);
fileInput = new BufferedReader(file);
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
System.out.println("File opened");
/* CLOSE FILE */
private void closeFile() {
if (fileInput != null) {
try {
fileInput.close();
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
System.out.println("File closed");
/* MAIN METHOD */
/* MAIN METHOD */
public static void main(String[] args) throws IOException {
// Create instance of class FileChooser
FileReduction1 newFile = new FileReduction1("File Reduction Program");
// Make window vissible
newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFile.setSize(500,400);
newFile.setVisible(true);
Java.lang.NullpointException
at FileReductoin1.readTheFile <FileReduction1.java :172>
at FileReductoin1.readFile <FileReduction1.java :110>
at FileReductoin1.actionPerformed <FileReduction1.java :71>
.1) Next time use the CODE tags. this is way too much unreadable crap.
2) The problem is your String[][] data.... the only place I see you do anything approching initializing it is
data = new String[numLines][];I think you want to do this..
data = new String[numLines][3];anyway that's why it's blowing up on the line
data[row][col]=st.nextToken(); -
Reading a file and changing one part of the file
I am trying to read a file and then I want to change the first value on each line. The file I am reading is a .HEADER file. Which is just read in notepad I am just opening this like a txt file. I get no say at all how this file is created originally
I want to change the value on the first line the a new title plus the ext .dat. The file is below. This stays the same format just with different values.
ECG000 1 171 26112 9:14:56 23/04/2002
ECG000 8 43(0) 8 127 79 -24066 0 AED trace
I want to change the ECG000 to a new value eg Pat1.dat on the first line and Pat1 on the second line. When I read this file in and output to the dos window I get ECG000 0 0 0 and that is it. Any ideas why this is happening and how I can replace the values in the file??
private void FileExt() throws IOException
System.out.println("In function");
BufferedReader br = new BufferedReader(new FileReader("c:\\Projects\\FirstSupport\\ECG000.HEADER"));
String s;
Vector data = new Vector();
ECGFile = new FileWriter("c:\\Projects\\FirstSupport\\ECG.txt",true);
System.out.println("Reading the file");
while ((s = br.readLine()) != null)
data.add(s);
System.out.println(s);
System.out.println("Finished");
String label = s.substring(0, s.indexOf(" "));
System.out.println(label);
String newLabel = (label+".dat");
System.out.println(newLabel);
}I think this is what you're looking for: private void FileExt() {
java.util.List data=new ArrayList();
String s;
try {
BufferedReader br=new BufferedReader(new InputStreamReader(
new FileInputStream(new File("ECG000.HEADER"))));
while ((s = br.readLine()) != null) {
data.add(s);
System.out.println(s);
br.close();
catch (FileNotFoundException fnfe) {
System.out.println("Input file not found");
return;
catch (IOException ioe) {
ioe.printStackTrace();
return;
ListIterator li=data.listIterator();
try {
PrintWriter ECGFile=new PrintWriter(new FileOutputStream(
new File("ECG.txt")));
while(li.hasNext()) {
s=(String)li.next();
if (s.substring(0, 6).equals("ECG000")) {
s="Pat1.dat"+s.substring(6, s.length());
ECGFile.println(s);
ECGFile.close();
catch (FileNotFoundException fnfe1) {}
}Mark -
Simultaneous Analog In and Analog Out
How to Output on Analog Out and read Analog In at the same time.
I am using a VC++, NIDAQ 7.01.
No LabView.Greetings,
The following example demonstrates how to perform synchronized analog input and analog output:
Synchronizing Analog Input and Output
The example was written in CVI, but modifying it for use in VC++ is fairly straightforward and documented within the code.
Good luck with your application.
Spencer S. -
How to read out message cycle time from Vector CANdb file?
Hello LabVIEW friends,
I tried to open a Vector CAN Database (*.dbc) using the NI-CAN 2.3.2 Channel API and read out the cycle time of a message.
The CAN get property.vi should provide the sample rate which is described as followed:
Input parameter of the CAN Init Start function.
The sample rate specifies
whether to transfer data in a periodic or event-driven manner.
For periodic
behavior, the rate specifies the number of read/write samples to perform per
second.
But for all messages in my database I get the value 0.
When I connect a sample rate to the CAN Initialize.vi I will get it's value.
Could anybody help?
Thank You.
Greets,
MarcusHi,
unfortunately there is no way to use the cycle time property from your DBC file, because the NI driver is not able to read this information.
This is because the cycletime is stored in different places for different users and only Vector itself can read this information back.
In your case, you have to figure out this information by yourself and you can use the sample rate input of the init or initstart function to configure the cycle time in Hz.
If you need different cycle times for different messages, see the attached example.
DirkW
Attachments:
CAN_Multi-Chans_Diff-Period.vi 26 KB -
Read spreadsheet file for Analog Out Profile using DAQmx
I am trying to read a .txt file in, then output the Analog out profile (Daqmx) vs. time. The first column is time is (ms) in .001 sec increments. The second column is the Analog out voltage I want to output. I want to read the profile in, and ouput the a Analog out voltage incrementing in .001 sec intervals (or whatever the time increments are in the .txt file). The problem I am having is, it reads in the whole file and outputs it in a fraction of a sec, instead of incrementing by the time. I attached a screen shot of what I have. Any help would be great. Thanks
Attachments:
screen shot read.jpg 75 KBYou are reading the timing but not doing anything with it. You've specified Analog Wfm 1Chan NSamp for the DAQmx Write but you did not create the waveform data type. Use the Build Waveform function on the Waveform palette and wire in your array to the Y (waveform component) input and the time interval to the dt input.
Message Edited by Dennis Knutson on 04-06-2006 08:56 AM
Attachments:
Build Waveform.JPG 6 KB -
How to read the file from ftp server
Hi
I need to read a file from a ftp server . Iam using apache lib common-net .jar .
FTPClient ftp = new FTPClient();
ftp.connect(server);
ftp.login(username,password);
FTPFile[] files = ftp.listFiles();
for(int i=0 ;i<files.length;i++){
System.out.println(" File : "+ i + " - " + files);
InputStream ip = ftp.retrieveFileStream(path);
I got the inputstream from the ftp server. but iam not able to read the contents of the file ....
help me plzzzzzHi
I have one more problem . first i try to read the file and write the file in local directory . then i try to read the data in the remote file .. iam getting the datas as null.
InputStream ip = ftp.retrieveFileStream(path);
File f = new File("D:\\ftp.txt");
FileOutputStream fo = new FileOutputStream(f);
byte[] buf = new byte[1024];
while ((len = ip.read(buf)) > 0) {
fo.write(buf,0,len);
fo.close();
BufferedReader br = new BufferedReader(new InputStreamReader(ip));
String line;
do {
line = br.readLine();
System.out.println(" data " +line);
}while (line != null); -
How to read .xls file from FTP server t oInternal table
Hi
am using the FTP_SERVER_TO_R3 to read xls file from FTP server to internal table
but the data i get in LT_TEXT is special characters.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = hdl
fname = f_name "ProdDataFromCRM.xls.
* CHARACTER_MODE = 'X'
* IMPORTING
* BLOB_LENGTH =
TABLES
BLOB = lt_text
* TEXT = lt_text
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4
can any one help me out to get the exact data..
Really appreciate your quick response..
Thank YouHi, if you really retrieve an excel file, you can not see the data in ABAP. You may see them in Excel. For this you may use
CALL METHOD document->open_document_from_table
of the interface i_oi_document_proxy for OLE objects. You can access the data with reference to the interface i_oi_spreadsheet.
Please check [Desktop Office Integration (BC-CI)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf] for details.
But, who knows, perhaps you want "And Now For Something Completely Different".
Regards
Clemens -
Reading a file from a folder.
Hi everyone,
I am trying to modify my first java program.
The method below is used to read a file that is hard coded in the below method. What I would like it to do is to pick up files that are stored in a folder. The reason for this is that the file names will never be the same.
I am unsure how to do this and would appreciate some help from you.
Thanks in advance.
public void fileBreakdown()
try
FileReader file = new FileReader("files/myTextFile.txt");
BufferedReader buffer = new BufferedReader(file);
String textline = null;
ArrayList arr = new ArrayList();
while ((textline = buffer.readLine()) != null)
boolean syswarnEndFound = false;
if((textline.substring(45, 52)).equals("SYSWARN"))
System.out.println(textline.substring(45, 52));
arr.add(textline);
while ((textline = buffer.readLine()) != null && !syswarnEndFound)
if(textline.indexOf("}") == -1)
//System.out.println("not found : " + textline);
buffer.mark(1000);
arr.add(textline);
else
//System.out.println("found");
syswarnEndFound = true;
buffer.reset();
OutputFileTypes.processSYSWARN(arr);
else if((textline.substring(45, 51)).equals("SYSMSG"))
System.out.println("Stopped, program ends");
System.out.println(textline.substring(45, 51));
arr.add(textline);
while ((textline = buffer.readLine()) != null && !syswarnEndFound)
if(textline.indexOf("}") == -1)
buffer.mark(1000);
arr.add(textline);
else
syswarnEndFound = true;
buffer.reset();
OutputFileTypes.processSYSMSG(arr);
else
String[] messageArr = textline.split(" ");
Processing.whichFileType(getSubject(messageArr),getMessage(messageArr),getPublishedDate(messageArr));
getPublishedDate(messageArr);
buffer.close();
catch( IOException e) {System.out.println(e);}
}I could not compile your code. But if you wanted to get all .txt files from a folder then you could do something like this
class EndsWith implements FilenameFilter {
String ext;
public EndsWith(String ext) {
this.ext = "." + ext;
public boolean accept(File dir, String name) {
return name.endsWith(ext);
public static void main(String args[]) {
String srcDir="C:/temp/";
try {
File srcFiles = new File(srcDir);
FilenameFilter filteredFiles = new EndsWith("txt");
String sourceDir[]=srcFiles.list(filteredFiles);
for(int i=0;i<sourceDir.length;i++)
String fileName = srcDir+sourceDir;
System.out.println(fileName);
FileReader file = new FileReader(fileName);
//..your code here
}catch(IOException ioe) {
ioe.printStackTrace();
NOTE: I haven't tested this code. You can give a try. -
Regarding Reading the file from Application Server
Hi,
I am trying to read data from Application Server but due to special characters it is getting dumped out.
US24,Q,Acero (Carbon),AA,0010,0001,01,Ver Mir para dimension#
US24,Q,Acero (Carbon),AA,0010,0002,01,Area rectificada sin da#os ra
US24,Q,Acero (Carbon),AA,0010,0003,01,Ver Mir para dimension#
US24,Q,Acero (Carbon),CD,0010,0001,01,ITPE Soken para verificacion
US24,Q,Acero (Carbon),CD,0010,0010,01,No se permite desprendimiento
US24,Q,Acero (Carbon),CD,0010,0002,01,"Vernier, cinta metrica"#
In the last line it is going into dump due to special character ".
Please suggest.
Thanks
Priyanka.Hi,
You can check the mode in which you are reading the file
from application server that is
Open Dataset in Binary or Text Mode.
Hope it helps
Regards
Mansi -
Problem with ArrayLists and writing and reading from a .dat file (I think)
I'm brand new to this forum, but I'm sure hoping someone can help me with a problem I'm having with ArrayLists. This program was originally created with an array of objects that were displayed on a GUI with jtextFields, then cycling thru them via jButtons: First, Next, Previous, Last. Now I need to add the ability to modify, delete and add records. Both iterations of this program needed to write to and read from a .dat file.
It worked just like it was suppose to when I used just the array, but now I need to use a "dynamic array" that will grow or shrink as needed: i.e. an ArrayList.
When I aded the ArrayList I had the ArrayList use toArray() to fill my original array so I could continue to use all the methods I'd created for using with my array. Now I'm getting a nullPointerException every time I try to run my program, which means somewhere I'm NOT filling my array ???? But, I'm writing just fine to my .dat file, which is confusing me to no end!
It's a long program, and I apologize for the length, but here it is. There are also 2 class files, a parent and 1 child below Inventory6. This was written in NetBeans IDE 5.5.1.
Thank you in advance for any help anyone can give me!
LabyBC
package my.Inventory6;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.IllegalStateException;
import java.util.NoSuchElementException;
import java.util.ArrayList;
import java.text.NumberFormat;
// Class Inventory6
public class Inventory6 extends javax.swing.JFrame {
private static InventoryPlusColor[] inventory;
private static ArrayList inList;
// create a tool that insure the specified format for a double number, when displayed
private DecimalFormat doubleFormat = new DecimalFormat( "0.00" );
private DecimalFormat singleFormat = new DecimalFormat( "0");
// the index within the array of products of the current displayed product
private int currentProductIndex;
/** Creates new form Inventory6 */
public Inventory6() {
initComponents();
currentProductIndex = 0;
} // end Inventory6()
private static InventoryPlusColor[] getInventory() {
ArrayList<InventoryPlusColor> inList = new ArrayList<InventoryPlusColor>();
inList.add(new InventoryPlusColor(1, "Couch", 3, 1250.00, "Blue"));
inList.add(new InventoryPlusColor(2, "Recliner", 10, 525.00, "Green"));
inList.add(new InventoryPlusColor(3, "Chair", 6, 125.00, "Mahogany"));
inList.add(new InventoryPlusColor(4, "Pedestal Table", 2, 4598.00, "Oak"));
inList.add(new InventoryPlusColor(5, "Sleeper Sofa", 4, 850.00, "Yellow"));
inList.add(new InventoryPlusColor(6, "Rocking Chair", 2, 459.00, "Tweed"));
inList.add(new InventoryPlusColor(7, "Couch", 4, 990.00, "Red"));
inList.add(new InventoryPlusColor(8, "Chair", 12, 54.00, "Pine"));
inList.add(new InventoryPlusColor(9, "Ottoman", 3, 110.00, "Black"));
inList.add(new InventoryPlusColor(10, "Chest of Drawers", 5, 598.00, "White"));
for (int j = 0; j < inList.size(); j++)
System.out.println(inList);
InventoryPlusColor[] inventory = (InventoryPlusColor[]) inList.toArray
(new InventoryPlusColor[inList.size()]);
return inventory;
} // end getInventory() method
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
IDNumberLbl = new javax.swing.JLabel();
IDNumberField = new javax.swing.JTextField();
prodNameLbl = new javax.swing.JLabel();
prodNameField = new javax.swing.JTextField();
colorLbl = new javax.swing.JLabel();
colorField = new javax.swing.JTextField();
unitsInStockLbl = new javax.swing.JLabel();
unitsInStockField = new javax.swing.JTextField();
unitPriceLbl = new javax.swing.JLabel();
unitPriceField = new javax.swing.JTextField();
invenValueLbl = new javax.swing.JLabel();
invenValueField = new javax.swing.JTextField();
restockingFeeLbl = new javax.swing.JLabel();
restockingFeeField = new javax.swing.JTextField();
jbtFirst = new javax.swing.JButton();
jbtNext = new javax.swing.JButton();
jbtPrevious = new javax.swing.JButton();
jbtLast = new javax.swing.JButton();
jbtAdd = new javax.swing.JButton();
jbtDelete = new javax.swing.JButton();
jbtModify = new javax.swing.JButton();
jbtSave = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
searchIDNumLbl = new javax.swing.JLabel();
searchIDNumbField = new javax.swing.JTextField();
jbtSearch = new javax.swing.JButton();
searchResults = new javax.swing.JLabel();
jbtExit = new javax.swing.JButton();
jbtExitwoSave = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Inventory Program"));
IDNumberLbl.setText("ID Number");
IDNumberField.setEditable(false);
prodNameLbl.setText("Product Name");
prodNameField.setEditable(false);
colorLbl.setText("Product Color");
colorField.setEditable(false);
colorField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
colorFieldActionPerformed(evt);
unitsInStockLbl.setText("Units In Stock");
unitsInStockField.setEditable(false);
unitPriceLbl.setText("Unit Price $");
unitPriceField.setEditable(false);
invenValueLbl.setText("Inventory Value $");
invenValueField.setEditable(false);
restockingFeeLbl.setText("5% Restocking Fee $");
restockingFeeField.setEditable(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(unitPriceLbl)
.addComponent(unitsInStockLbl)
.addComponent(colorLbl)
.addComponent(prodNameLbl)
.addComponent(IDNumberLbl)
.addComponent(restockingFeeLbl)
.addComponent(invenValueLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(IDNumberField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addComponent(prodNameField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addComponent(colorField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addComponent(unitsInStockField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addComponent(unitPriceField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addComponent(restockingFeeField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
.addComponent(invenValueField, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
.addContainerGap())
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(IDNumberLbl)
.addComponent(IDNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(prodNameLbl)
.addComponent(prodNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(colorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(colorLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(unitsInStockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(unitsInStockLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(unitPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(unitPriceLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(restockingFeeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(restockingFeeLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(invenValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(invenValueLbl))
.addContainerGap())
jbtFirst.setText("First");
jbtFirst.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtFirstActionPerformed(evt);
jbtNext.setText("Next");
jbtNext.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtNextActionPerformed(evt);
jbtPrevious.setText("Previous");
jbtPrevious.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtPreviousActionPerformed(evt);
jbtLast.setText("Last");
jbtLast.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtLastActionPerformed(evt);
jbtAdd.setText("Add");
jbtAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtAddActionPerformed(evt);
jbtDelete.setText("Delete");
jbtModify.setText("Modify");
jbtModify.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtModifyActionPerformed(evt);
jbtSave.setText("Save");
jbtSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtSaveActionPerformed(evt);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Search by:"));
searchIDNumLbl.setText("Item Number:");
jbtSearch.setText("Search");
searchResults.setFont(new java.awt.Font("Tahoma", 1, 12));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(searchIDNumLbl)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(259, 259, 259)
.addComponent(searchResults, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jbtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(searchIDNumbField, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(searchIDNumLbl)
.addComponent(searchIDNumbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(searchResults, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtSearch)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
jbtExit.setText("Save and Exit");
jbtExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtExitActionPerformed(evt);
jbtExitwoSave.setText("Exit");
jbtExitwoSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtExitwoSaveActionPerformed(evt);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jbtExitwoSave, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jbtExit)))
.addGroup(layout.createSequentialGroup()
.addComponent(jbtFirst)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtNext)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtPrevious)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtLast))
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jbtAdd)
.addComponent(jbtDelete)
.addComponent(jbtModify)
.addComponent(jbtSave))))
.addContainerGap())
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtFirst, jbtLast, jbtNext, jbtPrevious});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtAdd, jbtDelete, jbtModify, jbtSave});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jbtAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtDelete)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtModify)
.addGap(39, 39, 39)
.addComponent(jbtSave))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jbtFirst)
.addComponent(jbtNext)
.addComponent(jbtPrevious)
.addComponent(jbtLast))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jbtExit)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbtExitwoSave)))
.addContainerGap())
pack();
}// </editor-fold>
private void jbtExitwoSaveActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
private void jbtSaveActionPerformed(java.awt.event.ActionEvent evt) {
String prodNameMod, colorMod;
double unitsInStockMod, unitPriceMod;
int idNumMod;
idNumMod = Integer.parseInt(IDNumberField.getText());
prodNameMod = prodNameField.getText();
unitsInStockMod = Double.parseDouble(unitsInStockField.getText());
unitPriceMod = Double.parseDouble(unitPriceField.getText());
colorMod = colorField.getText();
if(currentProductIndex == inventory.length) {
inList.add(new InventoryPlusColor(idNumMod, prodNameMod,
unitsInStockMod, unitPriceMod, colorMod));
InventoryPlusColor[] inventory = (InventoryPlusColor[]) inList.toArray
(new InventoryPlusColor[inList.size()]);
} else {
inventory[currentProductIndex].setIDNumber(idNumMod);
inventory[currentProductIndex].setProdName(prodNameMod);
inventory[currentProductIndex].setUnitsInStock(unitsInStockMod);
inventory[currentProductIndex].setUnitPrice(unitPriceMod);
inventory[currentProductIndex].setColor(colorMod);
displayProduct(inventory[currentProductIndex]);
private static void writeInventory(InventoryPlusColor i,
DataOutputStream out) {
try {
out.writeInt(i.getIDNumber());
out.writeUTF(i.getProdName());
out.writeDouble(i.getUnitsInStock());
out.writeDouble(i.getUnitPrice());
out.writeUTF(i.getColor());
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "I/O Exception writing data",
"", JOptionPane.ERROR_MESSAGE);
System.exit(0);
} //end writeInventory()
private static DataOutputStream openOutputStream(String name) {
DataOutputStream out = null;
try {
File file = new File(name);
out =
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(file)));
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "I/O Error", "", JOptionPane.ERROR_MESSAGE);
System.exit(0);
return out;
} // end openOutputStream()
private static void closeFile(DataOutputStream out) {
try {
out.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "I/O Exception closing file",
"", JOptionPane.ERROR_MESSAGE);
System.exit(0);
} // end closeFile()
private static DataInputStream getStream(String name) {
DataInputStream in = null;
try {
File file = new File(name);
in = new DataInputStream(
new BufferedInputStream(
new FileInputStream(file)));
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "The file doesn't exist",
"", JOptionPane.ERROR_MESSAGE);
System.exit(0);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "I/O Error creating file",
"", JOptionPane.ERROR_MESSAGE);
System.exit(0);
return in;
private static void closeInputFile(DataInputStream in) {
try {
in.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "I/O Exception closing file",
"", JOptionPane.ERROR_MESSAGE);
System.exit(0);
} // end closeInputFile()
private double entireInventory() {
// a temporary double variable that the method will return ...
// after each product's inventory is added to it
double entireInventory = 0;
// loop to control number of products
for (int index = 0; index < inventory.length; index++) {
// add each inventory to the entire inventory
entireInventory += inventory[index].setInventoryValue();
} // end loop to control number of products
return entireInventory;
} // end method entireInventory
private void jbtLastActionPerformed(java.awt.event.ActionEvent evt) {
currentProductIndex = inventory.length-1; // move to the last product
// display the information for the last product
displayProduct(inventory[currentProductIndex]);
private void jbtPreviousActionPerformed(java.awt.event.ActionEvent evt) {
if (currentProductIndex != 0) // it's not the first product displayed
currentProductIndex -- ; // move to the previous product (decrement the current index)
} else // the first product is displayed
currentProductIndex = inventory.length-1; // move to the last product
// after the current product index is set, display the information for that product
displayProduct(inventory[currentProductIndex]);
private void jbtNextActionPerformed(java.awt.event.ActionEvent evt) {
if (currentProductIndex != inventory.length-1) // it's not the last product displayed
currentProductIndex ++ ; // move to the next product (increment the current index)
} else // the last product is displayed
currentProductIndex = 0; // move to the first product
// after the current product index is set, display the information for that product
displayProduct(inventory[currentProductIndex]);
private void jbtFirstActionPerformed(java.awt.event.ActionEvent evt) {
currentProductIndex = 0;
// display the information for the first product
displayProduct(inventory[currentProductIndex]);
private void colorFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
private void jbtModifyActionPerformed(java.awt.event.ActionEvent evt) {
prodNameField.setEditable(true);
prodNameField.setFocusable(true);
unitsInStockField.setEditable(true);
unitPriceField.setEditable(true);
private void jbtAddActionPerformed(java.awt.event.ActionEvent evt) {
IDNumberField.setText("");
IDNumberField.setEditable(true);
prodNameField.setText("");
prodNameField.setEditable(true);
colorField.setText("");
colorField.setEditable(true);
unitsInStockField.setText("");
unitsInStockField.setEditable(true);
unitPriceField.setText("");
unitPriceField.setEditable(true);
restockingFeeField.setText("");
invenValueField.setText("");
currentProductIndex = inventory.length;
private void jbtExitActionPerformed(java.awt.event.ActionEvent evt) {
DataOutputStream out = openOutputStream("inventory.dat");
for (InventoryPlusColor i : inventory)
writeInventory(i, out);
closeFile(out);
System.exit(0);
private static InventoryPlusColor readProduct(DataInputStream in) {
int idNum = 0;
String prodName = "";
double inStock = 0.0;
double pricBalusC -- The line that gives me my NullPointerException is when I call the "DisplayProduct()" method. Its a dumb question, but with NetBeans how do I find out which reference could be null? I'm not very familiar with how NetBeans works with finding out how to debug. Any help you can give me would be greatly appreciated.The IDE is com-plete-ly irrelevant. It's all about the source code.
Do you understand anyway when and why a NullPointerException is been thrown? It is a subclass of RuntimeException and those kind of exceptions are very trival and generally indicate an design/logic/thinking fault in your code.
SomeObject someObject = null; // The someObject reference is null.
someObject.doSomething(); // Invoking a reference which is null would throw NPE. -
Hi, I try to conect Mac Mini from 2009 with my HD Tv Samsung F 6400 . With Mini Dvi conection and adapter to HDMI input in TV I got picture but not sound! I have analog cable from the phones out from mac but imposible to conect to TV? Can you HLP?
You really need a newer Mac Mini with a true HDMI output, because that Mac Mini's DVI output does not support Audio.
You might try a 3.5mm to RCA adapter
from the Mac Mini's headphone jack to the TV's audio input,
but that would require being able to select the Audio input in the TVs menu while using it's HDMI input.
Optionally you could also use an external 2.1 Speaker System or patch the audio from the Mac Mini to your home stereo system to enhance that older Mac Mini's audio.
Maybe you are looking for
-
I tried entering in a new debit card number into my iTunes account yesterday, from my ipod touch. For some reason it was telling me the information I entered does not match my bank account. I tried 3 or 4 times, but to no avail. I figured I would wai
-
How do I find the dpi of an image in a pdf?
I have created a pdf and have opened it with Adobe Reader XI. My book printer (prepress operator) tells me the images are coming out 100 dpi or less. I'm creating the pdf in a different way the second time. I need to check the dpi of images before I
-
After USB recovery, restoration incomplete error - error during PININST_BBV.
I performed a USB recovery with USB made by Creating Recovery to wipe the hard drive.following error message when I click the Details button: ctoerror.flg file [ 1:06:44.60] ChkErrBB.CMD : Detect some error during PININST_BBV. [ 1:06:44.60] ChkErr
-
My iPad screen is stuck. I haven't had the iPad very long. Is this common and how do I fix it? Is there a reset button?
-
On my Imac in Illustrator 10 - when I do 'command open' I can get a preview in illo.ai but Not in illo.eps. How come? Thanks.