HI guys am completely new to java ... and have this couple of bugs am not clear of wt to do... can anybody help me with it i wud be gr8ful


E:\j2sdk1.4.2_19\bin\JAR>javac Training.java
.\Base64.java:39: cannot resolve symbol
symbol : constructor InputStream (java.io.FileInputStream,boolean)
location: class Base64.InputStream
Base64.InputStream localInputStream = new Base64.InputStream(localFileInputStream, false);
^
.\Base64.java:98: cannot resolve symbol
symbol : constructor OutputStream (java.io.ByteArrayOutputStream,boolean)
location: class Base64.OutputStream
localOutputStream = new Base64.OutputStream(localByteArrayOutputStream, true);

^
2 errors

Ezzaral commented: Still using "chat-speak". Read the forum rules on using proper English. -3

Recommended Answers

All 13 Replies

The problem is with the inner classes present in the Base64.java file. Post the code present in the Base64.java file. Also a little background on what exactly are you doing in Training.java would be helpful.

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.net.URLConnection;

public class Training extends Applet
  implements ActionListener
{
  Label mylabel;
  Label answer;
  TextField code;
  Button mybutton;

  public void init()
  {
    add(this.mylabel);
    add(this.code);
    add(this.mybutton);
    add(this.answer);

    this.mybutton.addActionListener(this);

    this.mylabel.setBackground(Color.black);
    this.mylabel.setForeground(Color.green);

    this.answer.setBackground(Color.black);
    this.answer.setForeground(Color.yellow);

    this.code.setForeground(Color.black);

    setBackground(Color.black);

    setLayout(new BorderLayout());
    add(this.mylabel, "West");
    add(this.code, "Center");
    add(this.mybutton, "East");
    add(this.answer, "South");
  }

  public void actionPerformed(ActionEvent paramActionEvent)
  {
    String str1 = this.code.getText();
    try
    {
      URL localURL = new URL("http://www.xyz.com/yrt.php");
      URLConnection localURLConnection = localURL.openConnection();
      String str2 = localURLConnection.getHeaderField("Training-code");

      if (str1.equals(str2))
      {
        String str3 = Base64.encodeString(str2);
        this.code.setText(str3 + ".php");
        this.answer.setText("Go to: " + str3 + ".php");
      }
      else
      {
        this.answer.setText("Incorrect");
      }

    }
    catch (Exception localException)
    {
      showStatus("An error occured, please report this to the Mod-X admins");
    }
  }

  public Training()
  {
    this.mylabel = new Label("Code: ");
    this.answer = new Label("", 1);
    this.code = new TextField(10);
    this.mybutton = new Button("Proceed...");
  }
}

I need to find out what str2 is its a small puzzle i was to solve

Thanx for the replyy....

I don't see any import for the Base64 class? Have you rolled in your own implementation of Base64 or are you using a library which provides such an implementation?

Here is Base64.java

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.lang.Boolean;
public class Base64
{
  public static final boolean ENCODE = true;
  public static final boolean DECODE = false;
  private static final int MAX_LINE_LENGTH = 76;
  private static final byte EQUALS_SIGN = 61;
  private static final byte NEW_LINE = 10;
  private static final byte[] ALPHABET = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47 };
  private static final byte[] DECODABET = { -9, -9, -9, -9, -9, -9, -9, -9, -9, -5, -5, -9, -9, -5, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -5, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, 62, -9, -9, -9, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -9, -9, -9, -1, -9, -9, -9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -9, -9, -9, -9, -9, -9, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -9, -9, -9, -9 };
  private static final byte BAD_ENCODING = -9;
  private static final byte WHITE_SPACE_ENC = -5;
  private static final byte EQUALS_SIGN_ENC = -1;

  public static void main(String[] paramArrayOfString)
  {
    String str = "Hello, world";
    str = "abcd";

    byte[] arrayOfByte1 = encodeString(str).getBytes();
    byte[] arrayOfByte2 = decode(arrayOfByte1, 0, arrayOfByte1.length);

    System.out.println("\n\n" + str + ":" + new String(arrayOfByte1) + ":" + new String(arrayOfByte2));
    try
    {
      FileInputStream localFileInputStream = new FileInputStream("c:\\abcd.txt");
      Base64.InputStream localInputStream = new Base64.InputStream(localFileInputStream, false);
      int i = 0;
      while ((i = localInputStream.read()) > 0);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  private static byte[] encode3to4(byte[] paramArrayOfByte)
  {
    return encode3to4(paramArrayOfByte, 3);
  }

  private static byte[] encode3to4(byte[] paramArrayOfByte, int paramInt)
  {
    byte[] arrayOfByte = new byte[4];
    encode3to4(paramArrayOfByte, 0, paramInt, arrayOfByte, 0);
    return arrayOfByte;
  }

  private static byte[] encode3to4(byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3)
  {
    int i = ((paramInt2 > 0) ? paramArrayOfByte1[paramInt1] << 24 >>> 8 : 0) | ((paramInt2 > 1) ? paramArrayOfByte1[(paramInt1 + 1)] << 24 >>> 16 : 0) | ((paramInt2 > 2) ? paramArrayOfByte1[(paramInt1 + 2)] << 24 >>> 24 : 0);

    switch (paramInt2)
    {
    case 3:
      paramArrayOfByte2[paramInt3] = ALPHABET[(i >>> 18)];
      paramArrayOfByte2[(paramInt3 + 1)] = ALPHABET[(i >>> 12 & 0x3F)];
      paramArrayOfByte2[(paramInt3 + 2)] = ALPHABET[(i >>> 6 & 0x3F)];
      paramArrayOfByte2[(paramInt3 + 3)] = ALPHABET[(i & 0x3F)];
      return paramArrayOfByte2;
    case 2:
      paramArrayOfByte2[paramInt3] = ALPHABET[(i >>> 18)];
      paramArrayOfByte2[(paramInt3 + 1)] = ALPHABET[(i >>> 12 & 0x3F)];
      paramArrayOfByte2[(paramInt3 + 2)] = ALPHABET[(i >>> 6 & 0x3F)];
      paramArrayOfByte2[(paramInt3 + 3)] = 61;
      return paramArrayOfByte2;
    case 1:
      paramArrayOfByte2[paramInt3] = ALPHABET[(i >>> 18)];
      paramArrayOfByte2[(paramInt3 + 1)] = ALPHABET[(i >>> 12 & 0x3F)];
      paramArrayOfByte2[(paramInt3 + 2)] = 61;
      paramArrayOfByte2[(paramInt3 + 3)] = 61;
      return paramArrayOfByte2;
    }

    return paramArrayOfByte2;
  }

  public static String encodeObject(Serializable paramSerializable)
  {
    ByteArrayOutputStream localByteArrayOutputStream = null;
    Base64.OutputStream localOutputStream = null;
    ObjectOutputStream localObjectOutputStream = null;
    try
    {
      localByteArrayOutputStream = new ByteArrayOutputStream();
      localOutputStream = new Base64.OutputStream(localByteArrayOutputStream, true);
      localObjectOutputStream = new ObjectOutputStream(localOutputStream);

      localObjectOutputStream.writeObject(paramSerializable);
    }
    catch (IOException localIOException)
    {
      Object localObject1;
      localIOException.printStackTrace();
      return null;
    }
    finally {
      try {
        localObjectOutputStream.close(); } catch (Exception localException1) { }
      try { localOutputStream.close(); } catch (Exception localException2) { }
      try { localByteArrayOutputStream.close(); } catch (Exception localException3) {
      }
    }
    return new String(localByteArrayOutputStream.toByteArray());
  }

  public static String encodeBytes(byte[] paramArrayOfByte)
  {
    return encodeBytes(paramArrayOfByte, 0, paramArrayOfByte.length);
  }

  public static String encodeBytes(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
  {
    int i = paramInt2 * 4 / 3;
    byte[] arrayOfByte = new byte[i + ((paramInt2 % 3 > 0) ? 4 : 0) + i / 76];

    int j = 0;
    int k = 0;
    int l = paramInt2 - 2;
    int i1 = 0;
    while (j < l)
    {
      encode3to4(paramArrayOfByte, j, 3, arrayOfByte, k);

      i1 += 4;
      if (i1 == 76)
      {
        arrayOfByte[(k + 4)] = 10;
        ++k;
        i1 = 0;
      }
      j += 3; k += 4;
    }

    if (j < paramInt2)
    {
      encode3to4(paramArrayOfByte, j, paramInt2 - j, arrayOfByte, k);
      k += 4;
    }

    return new String(arrayOfByte, 0, k);
  }

  public static String encodeString(String paramString)
  {
    return encodeBytes(paramString.getBytes());
  }

  private static byte[] decode4to3(byte[] paramArrayOfByte)
  {
    byte[] arrayOfByte1 = new byte[3];
    int i = decode4to3(paramArrayOfByte, 0, arrayOfByte1, 0);
    byte[] arrayOfByte2 = new byte[i];

    for (int j = 0; j < i; ++j)
      arrayOfByte2[j] = arrayOfByte1[j];

    return arrayOfByte2;
  }

  private static int decode4to3(byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2)
  {
    int i;
	if (paramArrayOfByte1[(paramInt1 + 2)] == 61)
    {
      i = DECODABET[paramArrayOfByte1[paramInt1]] << 24 >>> 6 | DECODABET[paramArrayOfByte1[(paramInt1 + 1)]] << 24 >>> 12;

      paramArrayOfByte2[paramInt2] = (byte)(i >>> 16);
      return 1;
    }

    if (paramArrayOfByte1[(paramInt1 + 3)] == 61)
    {
      i = DECODABET[paramArrayOfByte1[paramInt1]] << 24 >>> 6 | DECODABET[paramArrayOfByte1[(paramInt1 + 1)]] << 24 >>> 12 | DECODABET[paramArrayOfByte1[(paramInt1 + 2)]] << 24 >>> 18;

      paramArrayOfByte2[paramInt2] = (byte)(i >>> 16);
      paramArrayOfByte2[(paramInt2 + 1)] = (byte)(i >>> 8);
      return 2;
    }

    i = DECODABET[paramArrayOfByte1[paramInt1]] << 24 >>> 6 | DECODABET[paramArrayOfByte1[(paramInt1 + 1)]] << 24 >>> 12 | DECODABET[paramArrayOfByte1[(paramInt1 + 2)]] << 24 >>> 18 | DECODABET[paramArrayOfByte1[(paramInt1 + 3)]] << 24 >>> 24;

    paramArrayOfByte2[paramInt2] = (byte)(i >> 16);
    paramArrayOfByte2[(paramInt2 + 1)] = (byte)(i >> 8);
    paramArrayOfByte2[(paramInt2 + 2)] = (byte)i;
    return 3;
  }

  public static byte[] decode(String paramString)
  {
    byte[] arrayOfByte = paramString.getBytes();
    return decode(arrayOfByte, 0, arrayOfByte.length);
  }

  public static String decodeToString(String paramString)
  {
    return new String(decode(paramString));
  }

  public static Object decodeToObject(String paramString)
  {
    Object localObject2;
    byte[] arrayOfByte = decode(paramString);

    ByteArrayInputStream localByteArrayInputStream = null;
    ObjectInputStream localObjectInputStream = null;
    try
    {
      localByteArrayInputStream = new ByteArrayInputStream(arrayOfByte);
      localObjectInputStream = new ObjectInputStream(localByteArrayInputStream);

      Object localObject1 = localObjectInputStream.readObject();

      return localObject1;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      localObject2 = null;

      return localObject2;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      localClassNotFoundException.printStackTrace();
      localObject2 = null;

      return localObject2;
    }
    finally
    {
      try
      {
        localByteArrayInputStream.close(); } catch (Exception localException7) { }
      try { localObjectInputStream.close();
      }
      catch (Exception localException8)
      {
      }
    }
  }

  public static byte[] decode(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
  {
    int i = paramInt2 * 3 / 4;
    byte[] arrayOfByte1 = new byte[i];
    int j = 0;

    byte[] arrayOfByte2 = new byte[4];
    int k = 0;
    int l = 0;
    int i1 = 0;
    int i2 = 0;
    for (l = 0; l < paramInt2; ++l)
    {
      i1 = (byte)(paramArrayOfByte[l] & 0x7F);
      i2 = DECODABET[i1];

      if (i2 >= -5)
      {
        if (i2 < -1)
          return null;
        arrayOfByte2[(k++)] = (byte)i1;
        if (k <= 3)
          return null;
        j += decode4to3(arrayOfByte2, 0, arrayOfByte1, j);
        k = 0;

        if (i1 != 61) return null;
        break;
      }

      System.err.println("Bad Base64 input character at " + l + ": " + paramArrayOfByte[l] + "(decimal)");
      label160: return null;
    }

    byte[] arrayOfByte3 = new byte[j];
    System.arraycopy(arrayOfByte1, 0, arrayOfByte3, 0, j);
    return arrayOfByte3;
  }

  static byte[] access$000(byte[] paramArrayOfByte1, int paramInt1, int paramInt2, byte[] paramArrayOfByte2, int paramInt3)
  {
    return encode3to4(paramArrayOfByte1, paramInt1, paramInt2, paramArrayOfByte2, paramInt3); } 
  static byte[] access$100() { return DECODABET; } 
  static int access$200(byte[] paramArrayOfByte1, int paramInt1, byte[] paramArrayOfByte2, int paramInt2) { return decode4to3(paramArrayOfByte1, paramInt1, paramArrayOfByte2, paramInt2); } 
  static byte[] access$300(byte[] paramArrayOfByte, int paramInt) { return encode3to4(paramArrayOfByte, paramInt); } 
  static byte[] access$400(byte[] paramArrayOfByte) { return decode4to3(paramArrayOfByte);
  }

  public static class OutputStream extends FilterOutputStream
  {
    private boolean encode;
    private int position;
    private byte[] buffer;
    private int bufferLength;
    private int lineLength;

    public OutputStream(OutputStream paramOutputStream)
    {
      this(paramOutputStream, true);
    }

    public OutputStream(OutputStream paramOutputStream, boolean paramBoolean)
    {
      super(paramOutputStream);
      this.encode = paramBoolean;
      this.bufferLength = ((paramBoolean) ? 3 : 4);
      this.buffer = new byte[this.bufferLength];
      this.position = 0;
      this.lineLength = 0;
    }

    public void write(int paramInt)
      throws IOException
    {
      this.buffer[(this.position++)] = (byte)paramInt;
      if (this.position >= this.bufferLength)
      {
        if (this.encode)
        {
          this.out.write(Base64.access$300(this.buffer, this.bufferLength));

          this.lineLength += 4;
          if (this.lineLength >= 76)
          {
            this.out.write(10);
            this.lineLength = 0;
          }
        }
        else {
          this.out.write(Base64.access$400(this.buffer));
        }
        this.position = 0;
      }
    }

    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      for (int i = 0; i < paramInt2; ++i)
      {
        write(paramArrayOfByte[(paramInt1 + i)]);
      }
    }

    public void flush()
      throws IOException
    {
      if (this.position > 0)
      {
        if (this.encode)
        {
          this.out.write(Base64.access$300(this.buffer, this.position));
        }
        else
        {
          throw new IOException("Base64 input not properly padded.");
        }
      }

      super.flush();
      this.out.flush();
    }

    public void close()
      throws IOException
    {
      flush();

      super.close();
      this.out.close();

      this.buffer = null;
      this.out = null;
    }
  }

  public static class InputStream extends FilterInputStream
  {
    private boolean encode;
    private int position;
    private byte[] buffer;
    private int bufferLength;
    private int numSigBytes;

    public InputStream(InputStream paramInputStream)
    {
      this(paramInputStream, false);
    }

    public InputStream(InputStream paramInputStream, boolean paramBoolean)
    {
      super(paramInputStream);
      this.encode = paramBoolean;
      this.bufferLength = ((paramBoolean) ? 4 : 3);
      this.buffer = new byte[this.bufferLength];
      this.position = -1;
    }

    public int read()
      throws IOException
    {
      if (this.position < 0)
      {
        byte[] arrayOfByte;
        int j;
        if (this.encode)
        {
          arrayOfByte = new byte[3];
          this.numSigBytes = 0;
          for (j = 0; j < 3; )
          {
            try
            {
              int k = this.in.read();

              if (k >= 0)
              {
                arrayOfByte[j] = (byte)k;
                this.numSigBytes += 1;
              }

            }
            catch (IOException localIOException)
            {
              if (j == 0)
                throw localIOException;
            }
            ++j;
          }

          if (this.numSigBytes > 0)
          {
            Base64.access$000(arrayOfByte, 0, this.numSigBytes, this.buffer, 0);
            this.position = 0;
          }

        }
        else
        {
          arrayOfByte = new byte[4];
          j = 0;
          for (j = 0; j < 4; ++j)
          {
            int l = 0;
            do l = this.in.read();
            while ((l >= 0) && (Base64.access$100()[(l & 0x7F)] < -5));

            if (l < 0)
              break;

            arrayOfByte[j] = (byte)l;
          }

          if (j == 4)
          {
            this.numSigBytes = Base64.access$200(arrayOfByte, 0, this.buffer, 0);
            this.position = 0;
          }

        }

      }

      if (this.position >= 0)
      {
        if (this.position >= this.numSigBytes)
          return -1;

        int i = this.buffer[(this.position++)];

        if (this.position >= this.bufferLength)
          this.position = -1;

        return i;
      }

      return -1;
    }

    public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
	  int i;
      for ( i = 0; i < paramInt2; ++i)
      {
        int j = read();

        if (j < 0)
          return -1;

        paramArrayOfByte[(paramInt1 + i)] = (byte)j;
      }
      return i;
    }
  }
}
public InputStream(InputStream paramInputStream, boolean paramBoolean)

Now I am just guessing here, but I think the paramInputStream parameter is of type Base64.InputStream .

Since you have conflicting names, I suggest you change that definition to :-

public InputStream(java.io.InputStream paramInputStream, boolean paramBoolean)

if you wish that InputStream refer to the InputStream from the java.io package.

BTW drop the SMS speak, you have a full keyboard in front of you so type the complete words.

OK, Thanks...that has removed the bug but now i got a new error
E:\j2sdk1.4.2_19\bin\JAR>java Training
Exception in thread "main" java.lang.NoSuchMethodError: main

Sorry for being rude, but have you done any programming at all in Java ???

If not then what are you doing with this code ??

Because the above exception is as clear as it gets, show some effort from your side and what have you done to solve this problem or some analysis on why you think this is happening, rather than just blindly copy pasting what is mentioned here and vomiting back what your system throws back at you.

Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at Base64.main(Base64.java:35)

any suggestions about this error

Not until you show us what effort or analysis you made in tracing that error.
And as I said before do not just vomit back what your system throws back at you, show us some analysis, some effort from your side.

**Also my instinct suggests this is not your code so better show some effort in at least diagnosing the error**

Not until you show us what effort or analysis you made in tracing that error.
And as I said before do not just vomit back what your system throws back at you, show us some analysis, some effort from your side.

**Also my instinct suggests this is not your code so better show some effort in at least diagnosing the error**

I would like to add something to stephen84s's comments. The error you get is quite clear but you didn't even bother reading it:

Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at Base64.main(Base64.java:35)

There is an error (NullPointerException) at line: 35 in the file: Base64.java inside the method: main

As the error says: at Base64.main(Base64.java:35)

This is a problem from the site www.mod-x.co.uk that he is trying to solve... he is meant to solve it himself lol but he is trying to get you guys to solve it... he has downloaded the .jar file and used a decompiler to get the code and has no clue about how to program java :-)

STOP CHEATING!

This is a problem from the site www.mod-x.co.uk that he is trying to solve... he is meant to solve it himself lol but he is trying to get you guys to solve it... he has downloaded the .jar file and used a decompiler to get the code and has no clue about how to program java :-)

STOP CHEATING!

Now that you mentioned it, when someone writes all this piece of code and doesn't know what this thing is: Exception in thread "main" java.lang.NoSuchMethodError: main then there is certainly something strange

first u dont need to write ur java program inside bin\jar..Its wrong.ok.If u want to run ur java program from any drive then u need to do following things..
To run form any drive
1) Right Click on MyComputer select properties then Advanced Setting then Environment Variable.
2) In user Variable select new..
in first line write path
2nd line %path%,D\.............\bin; then Ok
then select new
in first variable name write classpath
2nd box-> %classpath%,D\..........\lib;
press ok->ok....now come in any drive write javac if something comes with some help menu then u r ready to run ur program from any drive...otherwise do that once agian.

To run from any drive
write ur java program in any drive save it with filename.java
when want to compile then do one thing select the location like this E:\JDeveloper\jdev9034_win2000\jdk\lib;
then in console write
set classpath=%classpath%;E:\JDeveloper\jdev9034_win2000\jdk\lib; enter now ur able to compile as well as to run ur prog.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.