The project is to encoding decoding: abcdefghijklmnopqrstuvwxyz kngcadsxbvfhjtiumylzqropwe at first, program should asks the user to enter a key string like above. The program will then read the file and output to the console its encoded contents.Capital letters are mapped the same way as the lower case letters above, but remain capitalized.For example, with the key above, every 'A' becomes a 'K' when encoding a text. Numbers and other characters are not encoded and remain the same. For example, with the mapping above, every 'a' becomes a 'k' when encoding a text, and every 'k' becomes an 'a' when decoding.
Run 1: Enter encoding key: maxnrslkbpwfzjidouetchgvyq Enter the file name: sampleInput.txt ************** Encoded Contents **************** Grfxizr ti XE 20A! Xizdctrue mur liin mt siffigbjl bjetucxtbije, act jit mt urmnbjl yicu zbjn. Bs yic mctizmtr m zree, yic lrt mj mctizmtrn zree.
Good Bye!
I get error : Exception in thread "main" java.lang.NullPointerException
on line char outputFile= hmap.get(FileChar);
C:\Users.....\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
which I want assign input file to hash map get value.
is it the reason because I dont make key value about other characters except [a-z] in hashmap like“, ! ," etc, then it dont have this key value then make null exception?
Here is some code
for hashmap
:
HashMap<Character,Character>hmap = new HashMap<>();
for(int j =0; j<26; j++){
if(Character.isUpperCase(originalResult.charAt(j))){
hmap.put(originalResult.charAt(j),Character.toUpperCase(inputResult.charAt(j)));
}
else{
hmap.put(originalResult.charAt(j),inputResult.charAt(j));
}
}
Here is some code I think the problem:
while((Fileline =bin.readLine())!=null )
{
char[] FileArray = Fileline.toCharArray();
for(int j=0;j<Fileline.length();j++ )
{
FileChar =FileArray[j];
char outputFile= hmap.get(FileChar); ////here is the problem
}
System.out.println( String.valueOf(outputFile));
}
I think the problem might be the char when I print like:
while((Fileline =bin.readLine())!=null ){
char[] FileArray = Fileline.toCharArray();
for(int j=0;j<Fileline.length();j++ ){
FileChar =FileArray[j];
s = new String(String.valueOf(FileChar));
}
System.out.println(s);
the result is nothing:
y
.
but when I print in the loop,it looks each line only have one letter,and lots of line:
while((Fileline =bin.readLine())!=null ){
char[] FileArray = Fileline.toCharArray();
for(int j=0;j<Fileline.length();j++ ){
FileChar =FileArray[j];
s = new String(String.valueOf(FileChar));
System.out.println(s);
}