Problem with code: reading a string

Hi,
I am very new to java so excuse my naivety. i need to write some code which will decode an encrypted message. the message is stored as a string which is a series of integers which. Eg. Nick in this code is 1409030110 where a = 1, b = 2,... and there is a 0 (zero) after every word. at the moment the code only goes as far as seperating the individual characters in the message up and printing them out onscreen.
Heres the code:
int index = 0;
while(index < line.length() - 1) {
char first = line.charAt(index);
char second = line.charAt(index + 1);
if(second == 0) {
char third = line.charAt(index + 2);
if(third == 0) {
System.out.print(first + "" + second);
index = index + 3;
else {
System.out.print(first);
index = index + 2;
else {
System.out.print(first + "" + second);
index = index + 3;
Basically its meant to undo the code by reading the first two characters in the string then determining whether the second is equal to 0 (zero). if the second is 0 then it needs to decide whether the third character is 0 (zero) because the code could be displaying 10 or 20. if so the first two characters are recorded to another string and if not only the first is recorded. obviously if the second character is not a zero then the code will automatically record the first 2 characters.
my problem is that the code doesnt seem to recognise the 0 (zero) values. when i run it thru with the string being the coded version of Nick above (1409030110) the outputted answer is 1490010 when it should be 149311. as far as i can see the code is right but its not working! basically the zeros are begin removed but i need each group of non-zero digits to be removed seperately so i can decode them.
if anyone has understood any of this could you give me some advice, im at my wits end!
Thanks, Nick

Try something like this:
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;
public class SimpleDecoder
    /** Default mapping file */
    public static final String DEFAULT_MAPPING_FILE = "SimpleDecoder.properties";
    /** Regular expression pattern to match one or more zeroes */
    public static final String SEPARATOR = "0+";
    private Properties decodeMapping = new Properties();
    public static void main(String [] args)
        try
            SimpleDecoder decoder = new SimpleDecoder();
            decoder.setDecodeMapping(new FileInputStream(DEFAULT_MAPPING_FILE));
            for (int i = 0; i < args.length; ++i)
                System.out.println("Original encoded string: " + args);
System.out.println("Decoded string : " + decoder.decode(args[i]));
catch (Exception e)
e.printStackTrace();
public void setDecodeMapping(InputStream stream) throws IOException
this.decodeMapping.load(stream);
public String decode(final String encodedString)
StringBuffer value = new StringBuffer();
String [] tokens = encodedString.split(SEPARATOR);
for (int i = 0; i < tokens.length; ++i)
value.append(this.decodeMapping.getProperty(tokens[i]));
return value.toString();
I gave your "1409030110" string on the command line and got back "nick". The SimpleDecoder.properties file had 26 lines in it:
1 = a
2 = b
3 = c
// etc;Not a very tricky encryption scheme, but it's what you asked for. - MOD

Similar Messages

  • CND problem with code-completion

    Hi,
    First of all I don't really know where to put this post about C++ Pack in NetBeans. I've read one post in which someone suggests that this section will be pretty close...
    Maybe someone here would be so kind and try to help me...
    I'm using Ubuntu 7.04 and I have a problem with code completion in NetBeans 5.5.1 CND and I'm a little bit frustrated right now....
    I installed Netbeans, then CND, Created new C++ Project. Added new source file, with #include <GL/glut.h> directive.
    Whole code was compiled without errors, and that's fine.
    There were some problems with linking but I've added "glut", "GL", "GLU" string to linker parameters in Project Properties.
    The main problem is the code assistant. When I'm hitting "glut" and press ctrl+space it shows functions from glut library but when I type "gl" (to type "glColor3ub...") and try to show the code completion pop-up it shows "No suggestions". The same thing is with GLU library.
    I've installed GL, GLU, glut libraries (they all sit calmly in /usr/include/GL).
    I've added the /usr/include and /usr/include/GL to C++ section.
    I think that the Netbeans is able to find those *.h files because, as I said before, the glut (and the glX) functions are shown properly but there is no sign of "gl" and "glu" FUNCTIONS in code completion (the #define values specified in gl.h and glu.h are on the list, but the functions aren't)...
    I don't have idea why glut and glX are working fine, and gl and glu aren't... If anyone have similar problem, know where to look for an answer or have some suggestions I would be much obliged...
    I've seen Eclipse CDT, Anjuta, kDevelop, Code::Blocks, VIM + icomplete... after checking them all there is only one decision - I want to use NetBeans CND. It's user-friendly, fast and I just like it. That's why I would really like to know why the code-completion isn't working in 100%...

    Vladimir,
    The glColor3ub function declaration is in gl.h file (which along with glu.h is included in glut.h).
    Thanks Maxim,
    In the matter of fact since yesterday I've been looking for the reason why the GL and GLU aren't indexed properly by the Netbeans CC and I've found something.
    The GLU library was indexed after deleting
    #include <GL/gl.h>directive. So it means that the gl.h library is messing up.
    I've checked whole file (gl.h) and noticed that the only part which is in conflict with NetBeans is this one:
    #elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
    #  define GLAPI __attribute__((visibility("default")))
    #  define GLAPIENTRYI'm using GCC 4.1 so the expression value is 401, so the GLAPI define looks like the line above.
    gl.h is indexed properly by NetBeans when it is representing "extern", so it should look like
    #  define GLAPI externIt is working fine if you delete this part of gl.h or for example (which I've done) add predefined macro (or change the existing one)
    __GNUC_MINOR__=-200I know that it isn't very clean solution... I'm not happy with cheating NetBeans about the version of installed GCC but unfortunately I am not a specialist in GNU C so maybe someone would find more elegant solution.
    As far as I know the __attribute__ feature makes the GCC more verbose (warnings, errors) but I don't know how much functionality am I loosing in fact...
    Edit: Why the code tags aren't working? :/
    Message was edited by:
    Makula

  • Problem with ImageIO.read and ImageReader JPG colors are distorted/wrong

    (Using JDK 1.5)
    ImageIO incorrectly reads some jpg images.
    I have a jpg image that, when read by the ImageIO api, all the colors become reddish.
            try
                java.awt.image.BufferedImage bi = javax.imageio.ImageIO.read( new java.io.File("javabug.jpg") );
                javax.imageio.ImageIO.write( bi, "jpg", new java.io.File("badcolors.jpg") );
                javax.imageio.ImageIO.write( bi, "png", new java.io.File("badcolors.png") );
            catch ( java.io.IOException ioe )
                ioe.printStackTrace();
            }Why is this happening??? My guess is there is a problem with the ImageIO.read ?
    the jpg can be downloaded at http://www.alwaysvip.com/javabug.jpg
    <BufferedImage@11faace: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1ebbfde transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 1691 height = 1269 #numDataElements 3 dataOff[0] = 2>
    I have even tried creating a new buffered image but still have the same problem:
    (suggested by http://forum.java.sun.com/thread.jspa?forumID=20&threadID=665585) "Java Forums - ImageIO: scaling and then saving to JPEG yields wrong colors"
            try
                java.awt.image.BufferedImage bi = javax.imageio.ImageIO.read( new java.io.File("javabug.jpg") );
                java.awt.image.BufferedImage out = new java.awt.image.BufferedImage( bi.getWidth(), bi.getHeight(), java.awt.image.BufferedImage.TYPE_INT_RGB );
                java.awt.Graphics2D g = out.createGraphics();
                g.drawRenderedImage(bi, null);
                g.dispose();
                javax.imageio.ImageIO.write( out, "jpg", new java.io.File("badcolors.jpg") );
            catch ( java.io.IOException ioe )
                ioe.printStackTrace();
            }I have used the following which works but does not use the ImageIO api. However, I tried using the ImageIO to write and it worked for writing which leads me to believe there is a problem with the reader.
    (suggested by http://developers.sun.com/solaris/tech_topics/java/articles/awt.html "Server-Side AWT")
            try
                java.awt.Image image = new javax.swing.ImageIcon(java.awt.Toolkit.getDefaultToolkit().getImage("javabug.jpg")).getImage();
                java.awt.image.BufferedImage bufferedImage = new java.awt.image.BufferedImage( image.getWidth( null ), image.getHeight( null ), java.awt.image.BufferedImage.TYPE_INT_RGB );
                java.awt.Graphics g = bufferedImage.createGraphics();
                g.setColor( java.awt.Color.white );
                g.fillRect( 0, 0, image.getWidth( null ), image.getHeight( null ) );
                g.drawImage( image, 0, 0, null );
                g.dispose();
                com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder( new java.io.FileOutputStream( "goodcolors.jpg" ) );
                encoder.encode( bufferedImage );
                javax.imageio.ImageIO.write( bufferedImage, "jpg", new java.io.File("goodiocolors.jpg") );
                javax.imageio.ImageIO.write( bufferedImage, "png", new java.io.File("goodiocolors.png") );
            catch ( java.io.IOException ioe )
                ioe.printStackTrace();
            }BTW, the following does not work either:
                java.util.Iterator readers = javax.imageio.ImageIO.getImageReadersByFormatName( "jpg" );
                javax.imageio.ImageReader reader = ( javax.imageio.ImageReader ) readers.next();
                javax.imageio.stream.ImageInputStream iis = javax.imageio.ImageIO.createImageInputStream( new java.io.File("javabug.jpg") );
                reader.setInput( iis, true );
                java.awt.image.BufferedImage bufferedImage = reader.read( 0 );

    I figured out the problem. It was an actual BUG in the JDK!
    The code failed with the following JDKs:
    java version "1.5.0_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
    Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
    java version "1.5.0_03"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
    Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode)
    The code ran sucessful with this JDK:
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
    If you are using the ImageIO classes, I highly suggest you upgrade to the latest JDK.
    Best,
    Scott

  • Problem with Adobe Reader not being able to run with Maverick  10.9.2?

    problem with Adobe Reader not being able to run with Maverick  10.9.2?

    Have you updated your version of Adobe Reader?

  • Problem with adobe reader, commenting

    one of our authors is using adobe reader x 11,1, and I send him a pdf (enabled commenting and measuring), but for some reason the commenting-fields does not show on his screen?
    should I save the pdf in another way?

    What do you mean by "commenting fields" exactly? By “commenting filds” I mean the tools in top of the page – delete, highlight etc. When I send the pdf, I save it as “file - save as -  reader extended pdf – enable commenting and measuring”, otherwise the commenting tools normally don’t appear by the author.
    Are they existing comments? no, it is the text in his pdf-book he needs to correct
    Is he able to access the commenting tools? no
    You can try sending a non-enabled version since Reader 11 can add comments to a non-enabled document. will try that J
    Fra: George Johnson [email protected]
    Sendt: 6. november 2012 16:16
    Til: Forlagene Idag & Nordan
    Emne: problem with adobe reader, commenting
    Re: problem with adobe reader, commenting
    created by George Johnson <http://forums.adobe.com/people/George_Johnson>  in Creating, Editing & Exporting PDFs - View the full discussion <http://forums.adobe.com/message/4826849#4826849

  • Continued problems with Adobe Reader 9.3.1

    Adobe Reader stops at the half-way mark in the progress block when loading a form to print.  Cannot get this fixed. Does anyone out there have a fix for this.  Is Adobe even recognizing that there is a problem with this.  Error message keeps telling me that there is a problem with Adobe Reader, exit and try again.

    I haven't been able to print any .pdf files since I downloaded 9.3.
    My message says Internet Explorer has closed it down because of data executable files.  I've changed my DEF settings to allow
    Adobe Reader but it still doesn't work.  I never had any problems before with newer versions.

  • Having problem with adobe reader

    Hi,
    I have a problem with adobe reader in my cell phone E71 model recently.I could open any pdf files till yesterday,but now without any reason the adobe reader icon in the office folder does not open.I wanna know what should I do.

    Might be some problem with adobe reader. You may Google another pdf app called pdf plus. Install it and see if the problem is solved or not.
    Nokia C7

  • Problems with flash reader, flash reader

    problems with flash reader, flash reader

    flash reader is an App for iPhone, iPad and iPod. Do you mean Flash Player?
    And, what is the problem?

  • Trying to open PDF getting error message " there is a problem with Acrabat /Reader. Please exit Adob

    I have windows XP, when I am trying open PDF getting a error message " there is a problem with Acrabot /Reader. Please exit Adobe Acrabat/Reader Please try again'  It was working earlier today  HELP

    If all else fails, you can try one of 2 things (I will assume you are talking about Reader - though this is not the Reader forum). Use ctrl-alt-del to go to the task list. Kill AcroRd32.exe. Then try again. If that does not work, a reboot will probably solve the problem.

  • Strange Problem with Code Groups / Codes

    Hey all, have a strange problem with Code Groups and Codes.
    Our data migration team accidentally loaded an early version of our catalog (code groups and codes) in to our 'Gold' configuration client. They then proceed to delete them all via transaction qs41. However, the code groups have been deleted, but not the codes.
    So, basically, no codes groups exist in table QPGR or QPGT but all the entries remain in QPCD with the assigment to code groups. The usage indicator is not set on the codes so why they did not get deleted with the codes groups is unknown.
    The issue that this is now causing us is that we can't recreate the codes groups with these codes assigned as the system thinks they already exist (via a check on table QPCD i would expect).
    Also, i have been unable to recreate what happened did in other clients... seems very strange.
    Any help appreciated.
    Cheers

    Ben,
    You could try SE11, and see if you can delete the records from there.. but I'm not hopeful...
    Otherwise you may need to write a quick ABAP program to delete the data base entries.
    PeteA

  • Problem With File Reading And Sorting

    I'm having problems with a particular task. Here is what I have to do:
    Write a program which reads 100 integers from a file. Store these integers
    in an array in the order in whcih they are read. Print them to the screen.
    Sort the integers in place using bubble sort. Print the sorted array to the
    screen. Now implement the sieve of Eratosthenes to place all prime numbers
    in an ArrayList. Print that list to the screen.
    Here is the code I have so far:
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add();
            catch(Exception e)
    This is the file reading part I have done but it doesn't recognise the line numbers.add() . It brings up the error - 'Cannot resolve symbol - method add(). Thats the first problem I have, can anyone see any way to fix it and to achieve the task. Also can someone help with the structure of a bubble sort method and a sieve of Eratosthenes method as I have no clue whatsoever. Any help will be greatly appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Ok, I've done that but I'm having another problem. When I'm printing an output to the screen, it prints 100 lines of integers and not 1 line of 100 integers. Can you see the problem in the code that is doing this?
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add(temp);
                    System.out.println(numbers);
            catch(Exception e)
    }

  • Problem with code

    hi all ! I hadd some problems with my code. I have some dates that should be ordered by the hour (hora) but its not. Now I know its not the SQL because I execute it with my sql control center and its just fine. SO it must be when I pass the data from one object to another.
    Here what I do:
    OK I think I got it. ITS NOT A SQL ERROR !!! or a table error !!! I executed the code using my sql control center and the result is ordered and correct. So it has to be something related to the code that saves the data. I save the data in a bean like this:
    public HashMap getCitasxfecha2(java.sql.Date fecha,String tipo) throws java.sql.SQLException
            BeanDatosCitas t = new BeanDatosCitas();
            HashMap m = new HashMap();
            ResultSet cdr = bd3.busquedaCitas2(fecha,tipo);
            java.sql.Time vector[]= new java.sql.Time[9999];
            System.out.println("salgo del busquedaCitas2");
            int id = 0;
            while (cdr.next())
            //String hora=convertir(cdr.getTime("Hora"));
             id = cdr.getInt("idCita");
                t = new BeanDatosCitas(
                id,                             // Nos servir� como identificador en la tabla HashMa
                cdr.getDate("Fecha"),
                cdr.getTime("Hora"),
                cdr.getString("Protocolo"),
                cdr.getString("DNI"),
                cdr.getString("Opcion"),
                cdr.getString("Observacion"),
                cdr.getString("Horaentrada"),
                cdr.getString("Nombres"),
                cdr.getString("Apellidos"),
                cdr.getString("Prescriptor"),
                cdr.getString("Mutua"),
                cdr.getInt("Sesigast"),
                cdr.getInt("Sesifaltantes"),
                cdr.getString("Tipo"),
                0
                m.put(new Integer(id), t);
            numFilas = m.size();
            return m;
        }Then I do a:
    respuesta = bBDCit.getCitasxfecha2(datNac,tipo);
            int nFilas2 = bBDCit.getNumFilas();
            Collection tabla2 = respuesta.values();
            request.setAttribute("citas_diarias",tabla2); And in my JSP I do:
    <c:forEach var="fila" items="${requestScope.citas_diarias}">it seems like in any part of this code the error happens. What could it be?
    Thanks again!

        public java.util.List getCitasxfecha2(java.sql.Date fecha,String tipo) throws java.sql.SQLException
            BeanDatosCitas t = new BeanDatosCitas();
            java.util.List list = new java.util.ArrayList();
            ResultSet cdr = bd3.busquedaCitas2(fecha,tipo);
            java.sql.Time vector[]= new java.sql.Time[9999];
            System.out.println("salgo del busquedaCitas2");
            int id = 0;
            while (cdr.next())
                //String hora=convertir(cdr.getTime("Hora"));
                id = cdr.getInt("idCita");
                t = new BeanDatosCitas( id,
                            // Nos servir� como identificador en la tabla HashMa
                    cdr.getDate("Fecha"),
                    cdr.getTime("Hora"),
                    cdr.getString("Protocolo"),
                    cdr.getString("DNI"),
                    cdr.getString("Opcion"),
                    cdr.getString("Observacion"),
                    cdr.getString("Horaentrada"),
                    cdr.getString("Nombres"),
                    cdr.getString("Apellidos"),
                    cdr.getString("Prescriptor"),
                    cdr.getString("Mutua"),
                    cdr.getInt("Sesigast"),
                    cdr.getInt("Sesifaltantes"),
                    cdr.getString("Tipo"),
                    0
                list.add(t);
            numFilas = list.size();
            return list;
            int nFilas2 = bBDCit.getNumFilas();
            Collection tabla2 = bBDCit.getCitasxfecha2(datNac,tipo);
            request.setAttribute("citas_diarias",tabla2);That should just about cover it. The JSP can stay the same.

  • Problem with code-Please Help!!!

    Hey guys i have some problems with the following code:
    1. I have to do a stutter and reverse of an array [ 2 4 ] and it should return [ 4 4 2 2 ]. I wrote the code and i get [ 2 2 4 4]. How can this be fixed?
    public class Part1
         public static void main(String[] args)
              int[] values = {2, 4};     
              stutterAndReverse(values);
         public static int[] stutterAndReverse(int[] values)
              //Stutter
              System.out.print("[ ");
              for (int i = 0; i < values.length; i++)
                   for(int j = values.length-1; j >=0; j--)
                        System.out.print(values[i] + " ");
              System.out.print("] ");
              return values;
    2. This one takes the array and returns the even numbers to the left and odds to the right. It works with the code i have so far but the odds on the right should be in order. For example an array of 6 gives the output [2, 4, 6, 5, 3, 1]. Mine gives [2, 4, 6, 1, 5, 3]. How can i fix this???
    public class Part2
         public static void main(String[] args)
              int[] arr = new int[6];
              for(int i = 0; i < arr.length; i++)
              arr[i] = i + 1 ;
              printArray(arr);
              arr = evensToLeft(arr);
              //arr = oddsToRight(arr);
              System.out.println("Evens to the Left");
              printArray(arr);               
         public static void printArray(int[] arr)
              System.out.print("[");
              for(int i = 0; i < arr.length; i++)
                   System.out.print(arr);
                   if(i < arr.length-1)
                   System.out.print(", ");
                   System.out.println("]");
         public static int[] makeArray(int n)
              int[] arr = new int[6];
              return arr;          
         public static int[] evensToLeft(int[] arr)
              int split = 0;
              for(int i = 0; i < arr.length; i++)
                   if(arr[i]%2==0) //even
                        swap(arr,i,split);
                        split++;
                   return arr;
         public static void swap(int[] arr, int n1, int n2)
              int temp = arr[n1];
              arr[n1] = arr[n2];
              arr[n2] = temp;
    Thank you for your time i really appreciate it.

    now i'm more confused than ever...:(This'll probably make it worse :)
    class Testing
      public Testing()
        String[] values1 = {"2","4"};
        System.out.println(java.util.Arrays.asList(values1));
        System.out.println(java.util.Arrays.asList(stutterAndReverse(values1)));
        String[] values2 = {"1","2","3","4","5","6","7","9","11"};
        System.out.println(java.util.Arrays.asList(values2));
        System.out.println(java.util.Arrays.asList(evensOdds(values2)));
      public String[] stutterAndReverse(String[] arr)
        String[] temp = new String[arr.length * 2];
        for(int x = 0; x < temp.length; x++)
          temp[temp.length - 1 -x] = arr[x/2];
        return temp;
      public String[] evensOdds(String[] arr)
        StringBuffer evens = new StringBuffer();
        StringBuffer odds = new StringBuffer();
        for(int x = 0; x < arr.length; x++)
          if(Integer.parseInt(arr[x]) % 2 == 0) evens.append(","+arr[x]);
          else odds.insert(0,","+arr[x]);
        return (evens.toString().substring(1)+odds.toString()).split(",");
      public static void main(String[] args){new Testing();}
    }

  • Problem with ImageIO.read()

    I have a problem with loading picture from file to variable Image img. Function ImageIO.read(fileIn) return always null pointer (whereas fileIn!=null). I'm using j2sdk-1_4_2_0. The same problem problem is in WindowsXP SP2 and Fedora 3 64bit.
    Here is code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import java.io.*;
    public class Converter extends JPanel implements ActionListener {
    JPanel mainPanel, info1Panel,info2Panel,convertionPanel, fSizePanel,displayPanel;
    JCheckBox enableConvertion;
    JButton selectFile,doIt,close;
    JRadioButton size1,size2;
    ButtonGroup sizeGroup;
    ImageIcon imagePrev;
    JRadioButton[] convertion = new JRadioButton[2];
    Image img;
    JLabel previewLabel;
    JFileChooser fc;
    File fileIn = new File("10.jpg");
    File fileOut;
    public Converter() {
    // Tworzenie paneli
    mainPanel=new JPanel();
    mainPanel.setLayout(null);
    info1Panel=new JPanel();
    info2Panel=new JPanel();
    convertionPanel=new JPanel(new BorderLayout());
    fSizePanel=new JPanel();
    displayPanel= new JPanel();
    //Tworzenie pozostalych elementow
    enableConvertion = new JCheckBox("Enable JPG <-> PNG");
    selectFile = new JButton("Select File");
    doIt = new JButton("Do it!");
    close= new JButton("Close");
    fc = new JFileChooser();
    size1 = new JRadioButton("The same resolution");
    size2= new JRadioButton("Resize image to target size of file");
    JLabel previewLabel = new JLabel();
    ButtonGroup sizeGroup = new ButtonGroup();
    imagePrev= new ImageIcon();
    // proba ulozenia elementow na ramce
    Insets insets = mainPanel.getInsets();
    Dimension size = selectFile.getPreferredSize();
    selectFile.setBounds(15 + insets.left, 15 + insets.top,size.width, size.height);
    doIt.setBounds(15 + insets.left,15+5+ insets.top+size.height,size.width, size.height);
    close.setBounds(15+insets.left,15+2*(5+size.height)+insets.top,size.width,size.height);
    convertionPanel.setBounds(10,150,250,90);
    convertionPanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Convertion"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    info1Panel.setBounds(150,10,200,140);
    info1Panel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Source File Information"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    info2Panel.setBounds(360,10,200,140);
    info2Panel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Target File Information"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    fSizePanel.setBounds(10, 250, 250, 90);
    fSizePanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("File size"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    fSizePanel.setLayout(new GridLayout(2,0));
    displayPanel.setBounds(270,150,290,190);
    displayPanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Display"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    previewLabel.setHorizontalAlignment(JLabel.CENTER);
    previewLabel.setVerticalAlignment(JLabel.CENTER);
    previewLabel.setVerticalTextPosition(JLabel.CENTER);
    previewLabel.setHorizontalTextPosition(JLabel.CENTER);
    previewLabel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createLoweredBevelBorder(),
    BorderFactory.createEmptyBorder(5,5,5,5)));
    previewLabel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createEmptyBorder(0,0,10,0),
    previewLabel.getBorder()));
    size1.setSelected(true);
    mainPanel.add(info1Panel);
    mainPanel.add(info2Panel);
    mainPanel.add(convertionPanel);
    mainPanel.add(fSizePanel);
    mainPanel.add(displayPanel);
    //osadzamy w odpowiednich panelach elementy
    mainPanel.add(selectFile);
    mainPanel.add(doIt);
    mainPanel.add(close);
    sizeGroup.add(size1);
    sizeGroup.add(size2);
    fSizePanel.add(size1);
    fSizePanel.add(size2);
    displayPanel.add(previewLabel);
    convertionPanel.add(enableConvertion);
    selectFile.addActionListener(this);
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showOpenDialog(Converter.this);
    if (returnVal == JFileChooser.APPROVE_OPTION)
    File fileIn = fc.getSelectedFile();
    JFrame frame1=new JFrame();
    JOptionPane.showMessageDialog(frame1, fileIn.getName());
    if(fileIn==null)
    JFrame frame2 = new JFrame();
    JOptionPane.showMessageDialog(frame2,"FileIN==NULL");
    //############## PROBLEM IS HERE ###########################
    try
    Image img=ImageIO.read(fileIn); // HERE IS THE PROBLEM: img==NULL
    // WHERAS fileIn!=NULL
    }catch (IOException event){}
    if (img==null)
    JFrame frame2 = new JFrame();
    JOptionPane.showMessageDialog(frame2,"img==NULL");
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create a new instance of LunarPhases.
    Converter conv = new Converter();
    //Create and set up the window.
    JFrame convFrame = new JFrame("Conversion JPG <-> PNG");
    convFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    convFrame.setContentPane(conv.mainPanel);
    Insets insets = convFrame.getInsets();
    convFrame.setSize(600 + insets.left + insets.right,400+insets.top + insets.bottom);
    convFrame.setVisible(true);
    public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    //############## PROBLEM IS HERE ###########################
    try {
    Image img=ImageIO.read(fileIn); // HERE IS THE PROBLEM: img==NULL
    // WHERAS fileIn!=NULL
    } catch (IOException event){}
    if (img==null) {
        JFrame frame2 = new JFrame();
        JOptionPane.showMessageDialog(frame2,"img==NULL");
    }1. Please use [code] tags when posting code -- it makes the code more readable.
    2. When posting code, post a minimal example program. You could have filtered
    out all the extraneous GUI code, for example. Remember: the shorter the code, the
    more likely it is a forum member will read it! Posting long runs of code only
    hurts yourself.
    3. All that being said, your problem is a simple oversight: notice that the
    variable "img" in your try block is a local variable, not the field named "img"
    than you test after the try block.
    You should have written:
    try {
        img=ImageIO.read(fileIn);
    } catch (IOException event){
        e.printStackTrace();
    }

  • AP 2602 Problem with Code 7.4.100.60

    Hi at all,
    I have problems with the code 7.4.100.60 and 2602 AP´s.
    The AP´s stops delivering services and no client can connected to them. After a reboot
    all problems are solved, but this problem comes back every ten days.
    In the logs are only shown a disconnect from these AP´s on the controller.
    On the AP´s is nothing to find.
    Is this a known problem? Is there a workaround available?
    Thanks in advance,
    Mario

    Hello Mario,
    As per your query i can suggest you the following solution-
    Please check the powering options-
    • 802.3af Ethernet Switch
    • Cisco AP2600 Power Injectors (AIR-PWRINJ4=)
    • Cisco AP2600 Local Power Supply (AIR-PWR-B=)
    and Power Draw
    AP2600: 12.95W
    Note: When deployed using Power over Ethernet (PoE), the power drawn from the power sourcing equipment will be higher by some amount depending on the length of the interconnecting cable. This additional power may be as high as 2.45W, bringing the total system power draw (access point + cabling) to 15.4W.
    Hope this will help you.

Maybe you are looking for

  • Welcome to the Metro Discussion

    Welcome to the Cisco Networking Professionals Connection Service Provider Forum. This conversation will provide you the opportunity to discuss issues surrounding Metro. We encourage everyone to share their knowledge and start conversations on issues

  • I have Firefox 3.6. Firefox will no longer allow me to open additional tabs within the same window.

    I've tried opening up Firefox in safe mode and restoring its original settings. This works for about 5 minutes and then it stops again. I also tried uninstalling and reinstalling. Neither clicking on the open tab nor going to "file" and clicking "New

  • Trying to install Adobe PS without opening OS9

    I am trying in install Adobe PS on my eMac 10.4.11 without launching OS9. I need to be able to print a postscript file but can't get it to work.

  • Group report without repeating group value

    I am trying to format my report that breaks by department like this: Dept ID Employee 1____1___BoB _____2___Mike _____3___John 2____4___Tim I don't want the 'Dept' field to repeat every line. Only where it is changed. I tried this, but ut shows the v

  • Exporting in Unix and importing in Windows

    Hi, I have exported a DB in Unix, I connected from my windows client and exported the db. I want to import this to in to a DB created on windows. The versions of oracle are the same(exp db and imp db). Can I perform normal import or do I have to hand