Question

translating code through use of properties class

Asked by: tigabalm

ok so i have a properties class and an inputStream

wondering how to sort/parse/translate the inputStream according to the loaded properties object?

i'd appreciate all the help i can get!

thanks

peace

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-02-16 at 18:17:54ID21317912
Topics

Java Programming Language

,

Delphi Components

Participating Experts
1
Points
350
Comments
57

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. translator
    I realy need a translater for pokemon green
  2. a translation
    Could someone help, I'm tryinging to change the coordinates of some points from : | * | ++ | ++ | ++ | ++ | ---------------------- where the * is an x,y and so are the + . I want to translate these points so that the * is my (0,0) point and the other ...
  3. Translational question
    I'd like to translate any delphi default text to norwegian. This applies especially to default button texts on MessageDlg dialogs. I know these texts are defined in recourcestrings in consts.pas. I want to, of course, keep the original consts.pas, but i also want to overrid...
  4. c# translation to vb.net
    How would you translate this to vb.net public class ShoppingCart : List<ShoppingItem> { ... }

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: objectsPosted on 2005-02-16 at 18:43:39ID: 13331103

Whats in your stream?

 

by: tigabalmPosted on 2005-02-16 at 18:47:58ID: 13331127

its me again objects (the guy with the DNA translation program)

trying to figure out how to apply the properties to the DNA code file

peace

 

by: objectsPosted on 2005-02-16 at 19:51:00ID: 13331399

I thought you were reading the mapings *from* the stream, and translating them into the properties file.

 

by: tigabalmPosted on 2005-02-16 at 19:56:15ID: 13331421

not really the properties file

contains the translation table:

AGT=A
ATT=A
ACT=A

etc

and i would like to apply this table to the stream

thanks

peace

 

by: objectsPosted on 2005-02-16 at 19:58:05ID: 13331426

so what do u have so far?

 

by: tigabalmPosted on 2005-02-16 at 20:00:08ID: 13331439

well my translate class is:

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;


//This class holds the genome/protein conversion through the use of a properties map.  
public class Translate{
  //Instance of a properties class which holds the key for the translation tbale
  private Properties props = new Properties();
  private File inFile;
 
 
  //this method loads the key and then our read/write class can call this to translate the input file
  //@param InputStream the properties file that holds the translation table
  public void load(InputStream in) throws IOException{
    //need to load in the properties class
    props.load(new FileInputStream("codes.properties"));
  }
  //This method actually translates the separated file though the use of a while loop that parses through the file
  //@param inFile the file that is separated
  //@param in the properties object which holds the translation table
  public void translate(File inFile, InputStream in){
    Separate sep = new Separate();
    //sep.separate(inFile) = separated;
    //loop that translates the code
    try {
      BufferedReader inReader = new BufferedReader(new FileReader("infilename"));
      String str;
     
      while ((str = inReader.readLine()) != null) {
       
        }
        inReader.close();
      }
   
      catch (IOException e) {
      }
     
    }
 
  //the method that gets a Protein code
  //@param code the protein code that we are looking for
  public String getProtein(String code){
    return (String) props.get(code);
  }
 
 
}

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

and my separate class is:

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This is the class the parses the DNA code into bits of three so it can be translated using the translation table
public class Separate {
  private static File inFile;
  private String line;
  private int pos;
 
  public Separate(){
   
  }
 
  //This method parses the DNA code into parts of three beginning at the first start code
  public void separate(File inFile){
    String triplet = line.substring(pos, pos+3);
    pos += 3;
    //line = reader.readLine();
  }
 
  public static void main(String[] args) {
    GetFile g = new GetFile();
    g.openFile(inFile);
   
   
}

its pretty ugly in both of those, but i was basically going through some trial and error...

thanks

peace

 

by: tigabalmPosted on 2005-02-16 at 20:02:14ID: 13331443

oh and sorry my getfile class is:

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;

public class GetFile{
  //private JButton openButton;
  private FileInputStream input;
  private String sourceFilename;
  private File inFile;
  private String line;
  private int pos;
  private Separate s;
   
 
  public GetFile(){
    openFile(inFile);
   
    //inFile.close();
   
  }  
 
  public static void main(String[] args){
    new GetFile();
    Separate s = new Separate();
  }  
 
  public void openFile(File inFile){
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int result = fileChooser.showOpenDialog(null);
    if (result == JFileChooser.CANCEL_OPTION)
      return;
    inFile = fileChooser.getSelectedFile();
   
    try{
      input = new FileInputStream(inFile);
     
    }
    catch (IOException ioException){
      JOptionPane.showMessageDialog(null,"Error opening file", "Error",JOptionPane.ERROR_MESSAGE);
     
    }
    try{
     
      BufferedReader reader = new BufferedReader(new FileReader(inFile));
       line = reader.readLine();
      //System.out.println("The line : \"" +line+ "\"");
      while(line!=null){
        System.out.println("The next line is " +line);

//        String triplet = line.substring(pos, pos+3);
//        pos += 3;
//        line = reader.readLine();
//        System.out.println("The next line is \"" +line+ "\"");
//        line = reader.readLine();        
      }
    }
    catch
      (IOException exception) {
      System.out.println("readLine caught IOException");
    }      
   
  }  
}  

thanks

peace

 

by: objectsPosted on 2005-02-17 at 01:00:49ID: 13332783

your reading loop should look something like:

      BufferedReader reader = new BufferedReader(new FileReader(inFile));
      StringBuffer result = new StringBuffer();
      while((line=in.readLine()!=null){
        System.out.println("The next line is " +line);
        if (!line.startsWith(">"))
        {
        int pos = 0;
        while (pos<line.length()-3)
        {
           String triplet = line.substring(pos, pos+3);
           String symbol = properties.getProperty(symbol);
           result.append(symbol);
           pos += 3;
      }
   }
}

 

by: tigabalmPosted on 2005-02-23 at 14:03:02ID: 13387651

hmm was trying this out and when i compile i get:

while((line=in.readLine()!=null)){  

------

Error: incompatible types
found   : java.lang.String
required: boolean

peace

 

by: objectsPosted on 2005-02-23 at 14:07:17ID: 13387682

sorry, should be:

while((line=in.readLine())!=null){  

 

by: tigabalmPosted on 2005-02-23 at 14:16:03ID: 13387771

dang... tried re-arranging some things and whut not to try and clean it up but getting one last error:

while((line=inFile.readLine())!=null){  

Error: cannot resolve symbol
symbol  : method readLine ()
location: class java.io.File

thanks

peace

 

by: objectsPosted on 2005-02-23 at 14:19:59ID: 13387807

you've change in to inFile.
readLine() is a method in BufferedReader

 

by: tigabalmPosted on 2005-02-23 at 14:23:26ID: 13387840

oh right... read some of the code wrong.. thought inFile was the bufferedReader...

so then should i declare:

private BufferedReader in;

or

private InputStream in;

thanks

peace

 

by: tigabalmPosted on 2005-02-23 at 14:26:36ID: 13387868

hmm declared it as an InputStream variable and it got past it, but now it is saying that "String symbol = properties.getProperty(symbol);"

Error: variable symbol might not have been initialized

thanks

peace

 

by: objectsPosted on 2005-02-23 at 14:36:20ID: 13387975

easiest if you post the current code

 

by: tigabalmPosted on 2005-02-23 at 14:46:04ID: 13388058

its still a "little" messy but should all be there:

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;


//This class holds the genome/protein conversion through the use of a properties map.  
public class Translate{
  //Instance of a properties class which holds the key for the translation tbale
  private Properties props = new Properties();
  private File input;
  private File inFile;
  private InputStream in;
  private String line;
  private String symbol;
 
 
  //this method loads the key and then our read/write class can call this to translate the input file
  //@param InputStream the properties file that holds the translation table
  public void load(InputStream in) throws IOException{
    //need to load in the properties class
    props.load(new FileInputStream("codes.properties"));
  }
  //This method actually translates the separated file
  //@param inFile the file that is separated
  //@param in the properties object which holds the translation table
  public void translate(File inFile, InputStream in){
    Separate sep = new Separate();
    sep.separate(input);
    //    String string = props.getProperty("triplet.value");
//    props.setProperty("triplet.value", "value");  
   
    try{
      BufferedReader reader = new BufferedReader(new FileReader(inFile));
      StringBuffer resultFile = new StringBuffer();
      while((line=reader.readLine())!=null){  
        System.out.println("The next line is " +line);
        if (!line.startsWith(">"))
        {
        int pos = 0;
        while (pos<line.length()-3)
        {
           String triplet = line.substring(pos, pos+3);
           String symbol = props.getProperty(symbol);
           resultFile.append(symbol);
           pos += 3;
      }
   }
   
   
  }
  }
    catch (IOException exception) {
      System.out.println("readLine caught IOException");
  }      
  }
 
  //the method that gets a Protein code
  //@param code the protein code that we are looking for
  public String getProtein(String code){
    return (String) props.get(code);
  }
 

thanks

peace

 

by: objectsPosted on 2005-02-23 at 14:50:47ID: 13388116

>  String symbol = props.getProperty(symbol);

should be:

 String symbol = props.getProperty(triplet);

 

by: tigabalmPosted on 2005-02-23 at 15:01:52ID: 13388203

sorry mang... just had two midterms and brain is working so well....

but getting a null pointer exception at runtime...

can u just take a look at my two classes and see if you can find what is throwing it?

getFile class:

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;

public class GetFile{
  //private JButton openButton;
  private FileInputStream input;
  private FileInputStream inFile;
  private String sourceFilename;
  private File codes;
  private String line;
  private int pos;
  private Separate s;
  private File resultFile;
 
 
 
  public GetFile(){
    //openFile(inFile);
   
    //inFile.close();
   
  }  
 
  public static void main(String[] args){
    new GetFile();
    Separate s = new Separate();
  }  
 
  public void openFile(File inFile){
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int result = fileChooser.showOpenDialog(null);
    if (result == JFileChooser.CANCEL_OPTION)
      return;
    inFile = fileChooser.getSelectedFile();
   
    try{
      input = new FileInputStream(inFile);
     
    }
    catch (IOException ioException){
      JOptionPane.showMessageDialog(null,"Error opening file", "Error",JOptionPane.ERROR_MESSAGE);
     
    }
____________________________


translate class:

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;


//This class holds the genome/protein conversion through the use of a properties map.  
public class Translate{
  //Instance of a properties class which holds the key for the translation tbale
  private Properties props = new Properties();
  private File input;
  private File inFile;
  private InputStream in;
  private String line;
  private String symbol;
 
 
  //this method loads the key and then our read/write class can call this to translate the input file
  //@param InputStream the properties file that holds the translation table
  public void load(InputStream in) throws IOException{
    //need to load in the properties class
    props.load(new FileInputStream("codes.properties"));
  }
  //This method actually translates the separated file
  //@param inFile the file that is separated
  //@param in the properties object which holds the translation table
  public void translate(File inFile, InputStream in){
    Separate sep = new Separate();
    sep.separate(input);
    //    String string = props.getProperty("triplet.value");
//    props.setProperty("triplet.value", "value");  
   
    try{
      BufferedReader reader = new BufferedReader(new FileReader(inFile));
      StringBuffer resultFile = new StringBuffer();
      while((line=reader.readLine())!=null){  
        System.out.println("The next line is " +line);
        if (!line.startsWith(">"))
        {
        int pos = 0;
        while (pos<line.length()-3)
        {
           String triplet = line.substring(pos, pos+3);
           String symbol = props.getProperty(triplet);
           resultFile.append(symbol);
           pos += 3;
      }
   }
   
   
  }
  }
    catch (IOException exception) {
      System.out.println("readLine caught IOException");
  }      
  }
 
  //the method that gets a Protein code
  //@param code the protein code that we are looking for
  public String getProtein(String code){
    return (String) props.get(code);
  }
 
 
}

thanks

peace

 

by: tigabalmPosted on 2005-02-23 at 15:04:52ID: 13388221

and then i am calling it like this:

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;

//This class stores the gene information and translated information
public class Store{
  private static File inFile;
  private static Separate sep;
  private static Translate t;
  private static InputStream in;
  private static File inputFile;
  private static String translated;
 
 
  public static void main(String[] args) {
    try{
      GetFile g = new GetFile();
      g.openFile(inFile);
      t.load(in);
      t.translate(inputFile,in);
     
     
    }
    catch
      (IOException exception) {
      System.out.println("readLine caught IOException");
    }      
   
  }
 
 
 
}
  ________________________

i think it is because the t.translate isnt getting anything... so how do i connect the FileInputStream from getFile to the inputFile in translate?

thanks a bunch man!

peace

 

by: objectsPosted on 2005-02-23 at 15:11:15ID: 13388261

you don't create your Translate instance

  Translate t = new Translate();
  t.load(in);
  t.translate(inputFile,in);

 

by: objectsPosted on 2005-02-23 at 15:11:46ID: 13388262

actually scratch that, should be:

  t = new Translate();
  t.load(in);
  t.translate(inputFile,in);

 

by: tigabalmPosted on 2005-02-24 at 15:56:44ID: 13398664

man this is taking way longer than expected... thanks for helping me through this!!

looks like readLine caught an IOException...

trying to find where its coming from... but not sure... think it might have to do with FileInoputStream but not sure...

thanks

peace

 

by: objectsPosted on 2005-02-24 at 16:05:51ID: 13398723

use the following to get the details of the excep[tion

    catch (IOException exception) {
      System.out.println("readLine caught IOException");
      exception.printStackTrace();
  }      

 

by: tigabalmPosted on 2005-02-24 at 16:08:39ID: 13398741

hmmm file not found codes.properties...


but its in the folder... i double checked that... do i need to declare its absolute path?

thanks

peace

 

by: objectsPosted on 2005-02-24 at 16:14:25ID: 13398763

> but its in the folder

in what folder? It needs to be in the folder that it is being run from
otherwise you need to use the absolute path

 

by: tigabalmPosted on 2005-02-24 at 16:18:01ID: 13398779

well its in the folder that has all the classes in it...

peace

 

by: objectsPosted on 2005-02-24 at 16:23:28ID: 13398806

that code will not find it there, it is looking in the same directory as you run it from.

to load from same directory as class try:

props.load(getClass().getResourceAsStream("codes.properties"));

 

by: tigabalmPosted on 2005-02-24 at 16:32:34ID: 13398857

man... now i get a null pointerexception... it gets past t.load(in)... but i dont htink its getting anything from the "inputFile"

i was looking through my code... and i dont think the file from getFile is linked to the inputFile in separate... therefore when translate runs... its not getting anything to translate...

thanks

peace

 

by: tigabalmPosted on 2005-02-24 at 16:35:59ID: 13398872

sorry would prolly help if i posted the Separate class:

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
//This is the class the parses the DNA code into bits of three so it can be translated using the translation table
public class Separate {
  private static File inFile;
  private String line;
  private int pos;
 
  public Separate(){
   
  }
 
  //This method parses the DNA code into parts of three beginning at the first start code
  public void separate(File inFile){
    GetFile get = new GetFile();
    get.openFile(inFile);
    int pos = 0;
    while (pos<line.length()-3)
    {
      String triplet = line.substring(pos, pos+3);
      System.out.println(triplet);
    }
    //line = reader.readLine();
  }
 
//  public static void main(String[] args) {
//    GetFile g = new GetFile();
//    g.openFile(inFile);
   
   
   
    //String triplets = "ATTGGCTCTTACCACTTGTCCCTCAAAACGACCACCCCATTGACTGGTGGCGATTGCGTCGACGGA";
   
    //               TripletReader tr = new TripletReader(new FileReader(inFile));
    //               String code = null;
    //               while((code = tr.readNextCode()) != null) {
    //                    System.out.println(code);
    //               }
    //               tr.close();
    //               }
    //               catch(Exception e) {
    //                    e.printStackTrace();
    //               }
  }
 
//}


//class TripletReader {
//
//     private Reader in;
//     private char[] codeBuffer;
//
//     public TripletReader(Reader in) {
//          this.in = in;
//          codeBuffer = new char[3];
//     }
//
//     public String readNextCode() throws IOException {
//          String code = null;
//          int charsRead = in.read(codeBuffer);
//          if (charsRead == 3) {
//               code = new String(codeBuffer);
//          }
//          else if (charsRead < 0) {
//               in.close();
//          }
//          else if (charsRead < 3) {
//               throw new EOFException("Incorrect number of characters in source file");
//          }
//          return code;
//
//     }
//
//     public void close() {
//          try { in.close(); } catch(IOException e) { /* ignore */     }
//     }
//}

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

thanks

peace

 

by: objectsPosted on 2005-02-24 at 16:48:21ID: 13398923

when do you set inFile?

 

by: objectsPosted on 2005-02-24 at 16:50:49ID: 13398940

that class is (very) incopmplete (it should look more like whats in translate).
What is its intended purpose of that method?

 

by: tigabalmPosted on 2005-02-24 at 16:54:07ID: 13398950

thats exactly what i just thought...

what i wanted it to do was to separate an input file... then the translate class would take the separated file and apply codes.properties  to the separated strings and then translate...

now i am thinking... either i combine separate() and translate()

or i have separate() save the separated file and then translate() will read the new file...

which would u suggest?

thanks

peace

 

by: objectsPosted on 2005-02-24 at 17:00:51ID: 13398987

translate already does that doesn't it, I'm not sure I see a need for seperate at all.

 

by: tigabalmPosted on 2005-02-26 at 01:12:30ID: 13409518

well i closed separate and removed everything related to it... but getting a null pointer exception when trying to run it...

oh and objects... can u help me with the next part of my project lol?  i will open up a new question...

thanks

peace

 

by: objectsPosted on 2005-02-26 at 01:18:47ID: 13409525

what line is giving u the npe?

 

by: tigabalmPosted on 2005-02-26 at 01:44:55ID: 13409562


  public static void main(String[] args) {
    try{
      GetFile g = new GetFile();
      g.openFile(inFile);
      t = new Translate();
      t.load(in);
      System.out.println("got here");
      t.translate(inFile,in);
      System.out.println("got here");
----------

it prints "got here" and then throws the error... so i am assuming it the "t.translate(inFile,in);" since it doesnt print the second print statement

thanks

peace

 

by: objectsPosted on 2005-02-26 at 01:48:02ID: 13409569

what does your translate() method look like?

if you print out the stack trace of the exception it will give u the line that it occurs on

ex.printStackTrace();

NPE's are caused by accessiung a null variable so check that the vars used on that  line are not null.

 

by: tigabalmPosted on 2005-02-26 at 01:53:01ID: 13409574

well my translate() method is posted above... and i am still trying to figure out where the null variable is...

where should i put the ex.printStrackTrace();?

thanks

peace

 

by: tigabalmPosted on 2005-02-26 at 02:01:42ID: 13409591

ok traced it through print statements... and this line is throwing the NPE:

BufferedReader reader = new BufferedReader(new FileReader(inFile));

-------

inFile is declared in the class and in the method param....

any ideas?

thanks

peace

 

by: tigabalmPosted on 2005-02-26 at 02:02:47ID: 13409593

is the file that i select with:

g.openFile(inFile);

the same "inFile" as the one declared in:

BufferedReader reader = new BufferedReader(new FileReader(inFile));

thanks

peace

 

by: objectsPosted on 2005-02-26 at 02:15:33ID: 13409614

you never initialise inFile

  inFile = ....
  t.translate(inFile,in);

 

by: tigabalmPosted on 2005-02-26 at 02:23:23ID: 13409636

ic... so should inFile be instialized in the translate() method...

ie: in the bufferedReader?

thanks

peace

 

by: objectsPosted on 2005-02-26 at 02:31:55ID: 13409650

no because ytou pass it to the translate method, you need to pass a valid File to translate.
Also in is not used so you can get rid of it.
translate will then look like:

public void translate(File inFile){

and you'll call it using something like:

File inFile = new File("xyz.properties");
t.translate(inFile);


you can also get rid of the following line

 private File inFile;

 

by: tigabalmPosted on 2005-02-26 at 02:37:19ID: 13409658

well... thing is it is getting the properties file... its just not getting the file to translate IE: AGTCGTAGTAGCGT

also which "inFile" am i getting rid of?  translate class or store class?

thanks

peace

 

by: objectsPosted on 2005-02-26 at 02:41:37ID: 13409674

i'm refering to the translate class (one problem at a time)

 

by: objectsPosted on 2005-02-26 at 02:42:13ID: 13409676

actually you can get rid of it in both by the looks

 

by: tigabalmPosted on 2005-02-26 at 02:45:45ID: 13409685

ok so this is what my translate() method looks like now:

public void translate(File inFile, InputStream in){
    //    String string = props.getProperty("triplet.value");
//    props.setProperty("triplet.value", "value");  
    try{
      GetFile g = new GetFile();
      g.openFile(inFile);
      System.out.println("going to translate");
      BufferedReader reader = new BufferedReader(new FileReader(inFile));
      StringBuffer resultFile = new StringBuffer();
      System.out.println("reading line");
      while((line=reader.readLine())!=null){  
        System.out.println("The next line is " +line);
        if (!line.startsWith(">"))
        {
        int pos = 0;
        while (pos<line.length()-3)
        {
           String triplet = line.substring(pos, pos+3);
           String symbol = props.getProperty(triplet);
           resultFile.append(symbol);
           pos += 3;
      }
   }

------------
i deleted inFile from the class so what should the "inFile" be in:
g.open(inFile);
and
BufferedReader reader = new BufferedReader(new FileReader(inFile));

thanks

peace

 

by: tigabalmPosted on 2005-02-26 at 02:50:09ID: 13409694

objects... how long will u be up/online for?

was wondering if you could help me with part 2

thanks

peace

 

by: objectsPosted on 2005-02-26 at 02:56:26ID: 13409703

i'm finishing up about now sorry, may be back online tomorrow
otherwise monday

change GetFile to

  public InputStream openFile() throws IOException {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int result = fileChooser.showOpenDialog(null);
    if (result == JFileChooser.CANCEL_OPTION)
      return;
    File inFile = fileChooser.getSelectedFile();
   
      input = new FileInputStream(inFile);
      return input;
    }

transtale to:


public void translate(InputStream in){
    try{
      System.out.println("going to translate");
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      StringBuffer resultFile = new StringBuffer();
      System.out.println("reading line");
      while((line=reader.readLine())!=null){  
        System.out.println("The next line is " +line);
        if (!line.startsWith(">"))
        {
        int pos = 0;
        while (pos<line.length()-3)
        {
           String triplet = line.substring(pos, pos+3);
           String symbol = props.getProperty(triplet);
           resultFile.append(symbol);
           pos += 3;
      }
   }

and main to:


 public static void main(String[] args) {
    try{
      GetFile g = new GetFile();
      InputStream in = g.openFile();
      t = new Translate();
      t.load(in);
      System.out.println("got here");
      t.translate(g.openFile());
      System.out.println("got here");

 

by: tigabalmPosted on 2005-02-26 at 03:21:54ID: 13409747

hmm hope your still on, but it says that in getFile:

   if (result == JFileChooser.CANCEL_OPTION)
      return;

is missing a return value...

thanks

peace

 

by: tigabalmPosted on 2005-02-26 at 03:22:31ID: 13409749

btw omg thank you so much for all that!!!!!!!!!

peace

 

by: objectsPosted on 2005-02-26 at 14:48:20ID: 13412252

if (result == JFileChooser.CANCEL_OPTION)
      return null;

 

by: tigabalmPosted on 2005-02-26 at 14:57:11ID: 13412273

funny cause thats what i ended up doing... guess i am learning this stuff lol...

i'm so happy that i works!!  one thing tho... when i run java Store... it opens two jfilechoosers... so that i'll select one file, and then instantly anothner filechooser window opens... and then afteri  choose the 2nd one it starts translating...

but the other funny thing is that it just keeps running forever.... i let it run for like 5 minutes and it just kept spitting out the same translation over and over again....

do i need to close the file stream or something?  

also could u help me with hamming distances?  i opened up a new question...

thanks so much!!

peace

 

by: objectsPosted on 2005-02-26 at 16:59:33ID: 13412552

post your current code and yor input files and I'll test it here tomorrow

 

by: tigabalmPosted on 2005-02-26 at 17:20:41ID: 13412587

nah its all good... its due tonight and i am trying to figure some other stuff out...

i would increase the points on this question but dont have any more points... and pretty broke right now lol...

thank you so much objects!! i def owe you a big one!!

peace

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...