Results 1 to 13 of 13
  1. #1
    kswapnadevi is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default Java & shell scripting

    My input files 't1.det' and t1.rnaml' are in different directories as shown in hierarchy. All these 'dir's are in 'mfold' directory. Each time 2 inputs from each directory are taken and executing two shell scripts 't1prog' and 't2prog' and the outputs 't1out' and 't2out' are going back into their directories. These outputs are taking as input to a java program and after execution the final output is redirected to 'MIRNA.out' This process has to be repeated for all directories inputs and final output is in MIRNA.out file. When I run these script I am getting errors in Java program which are given below. Pls correct those errors. THANKS IN ADVANCE.


    Java Code:
    |-- dir1
    |   |-- t1.det
    |   `-- t1.rnaml
    |-- dir2
    |   |-- t1.det
    |   `-- t1.rnaml
    |-- dir3
    |   |-- t1.det
    |   `-- t1.rnaml
    |-- dir4
    |   |-- t1.det
    |   `-- t1.rnaml
    `-- dir5
        |-- t1.det
        `-- t1.rnam

    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class RNA
    {
    	public static final String inputFile1 = "t1out";
    	public static final String inputFile2 = "t2out";
    	public static final String outputfile = "/Users/rsankar/rna/MIRNA.out";
    
    
    	private Hashtable rangeTable = new Hashtable();
    	private ArrayList multiloopList = new ArrayList();
    	private ArrayList hairPinList = new ArrayList();
    	private int STARTRANGE = -1;
    	private int DEFAULTSTARTRANGE = 40;
    
    	private static final boolean DEBUG = false;
    
    
    	public RNA()
    	{
    	}
    
    	public RNA(int STARTRANGE)
    	{
    
    		this.STARTRANGE = STARTRANGE;
    		if(STARTRANGE == -1) this.STARTRANGE = DEFAULTSTARTRANGE;
    	}
    
    
    	private void init() throws IOException
    	{
    		FileReader fileReaderObj = new FileReader(inputFile2);
    		BufferedReader bufferReaderObj = new BufferedReader(fileReaderObj);
    
    		String line = null;
    		line = bufferReaderObj.readLine();
    		String saveLine = null;
    		boolean advanced = false;
    		while(line != null)
    		{
    			advanced = false;
    
    			if (line.trim().startsWith("-"))
    			{
    
    				saveLine = line.trim();
    				String multiloop = new String();
    				if(DEBUG) System.out.println(saveLine);
    
    				while (((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("Hairpin loop:"))
    				{
    					if (line.trim().equals("Multi-loop:"))
    					{
    						multiloop = bufferReaderObj.readLine();
    						multiloopList = new ArrayList();
    						multiloopList.add("Multi-loop:");
    						multiloopList.add(multiloop);
    						if(DEBUG) System.out.println("multiloop--->"+multiloop);
    
    					}
    				}
    
    				[QUOTE][B][COLOR="Blue"]if(line.trim().equals("Hairpin loop:"))	[/COLOR][/B][/QUOTE]			{
    					multiloopList.add("Hairpin loop:");
    					while (((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("-"))
    					{
    						advanced = true;
    						if(line.trim().length() > 0)multiloopList.add(line);
    						if(DEBUG) System.out.println("Hairpin loop--->"+line);
    
    
    					}
    					if(DEBUG) System.out.println("Hairpin loop size--->"+multiloopList.size());
    
    				}
    
    
    
    			}
    			if(saveLine !=null && multiloopList != null) rangeTable.put(saveLine,multiloopList);
    			if(!advanced )
    			{
    				line = bufferReaderObj.readLine();
    				//System.out.println("advance-->"+line);
    
    			}
    		}
    
    	}
    
    
    	public void compare() throws IOException
    	{
    		FileReader fileReaderObj = new FileReader(inputFile1);
    		BufferedReader bufferReaderObj = new BufferedReader(fileReaderObj);
    		BufferedWriter writer = new BufferedWriter(new FileWriter(outputfile,true));
    		boolean advanced = false;
    		String line = null;
    		line = bufferReaderObj.readLine();
    
    		while(line != null)
    		{
    			advanced = false;
    			 //System.out.println(line);
    			if(line.trim().startsWith("-"))
    			{
    				List list = (ArrayList)rangeTable.get(line.trim());
    				while(((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("-"))
    				{
    
    					String []result = line.trim().split("-");
    					int left = Integer.parseInt(result[0].trim());
    					int right = Integer.parseInt(result[1].trim());
    					if(left > STARTRANGE && (right - left) > 20)
    					{
    						String multiLoopRange = (String)list.get(1);
    						String []result1 = multiLoopRange.trim().split("-");
    						int multiLoopLeft = Integer.parseInt(result1[0].trim());
    						int multiLoopRight = Integer.parseInt(result1[1].trim());
    
    						if(left > multiLoopLeft)
    						{
    							for(int i = 3; i < list.size(); i++)
    							{
    
    								String hairPinValue = (String)list.get(i);
    								String []hairPinresult = hairPinValue.trim().split("-");
    								int hairPinleft = Integer.parseInt(hairPinresult[0].trim());
    								int hairPinRight = Integer.parseInt(hairPinresult[1].trim());
    
    								if(left < hairPinleft && right > hairPinRight)
    								{
    
    									int microRNAleft = left + 21;
    
    									if (microRNAleft <= hairPinleft)
    									{
    										if(DEBUG) System.out.println("MIRNA--"+ left +":"+microRNAleft);
    										writer.write(left +":" + microRNAleft);
    										writer.newLine();
    									}
    									int microRNAright = hairPinRight + 1 + 21;
    
    									if(microRNAright <= right)
    									{
    										if(DEBUG) System.out.println("MIRNA--"+ (hairPinRight+1)+":"+microRNAright);
    										writer.write((hairPinRight) +":" + microRNAright);
    										writer.newLine();
    
    									}
    
    								}
    							}
    
    						}
    
    
    					}
    					advanced = true;
    				}
    			}
    
    			if(!advanced) line = bufferReaderObj.readLine();
    		}
    		bufferReaderObj.close();
    		fileReaderObj.close();
    		writer.close();
    		
    	}
    
    	public static void main(String []r) throws Exception
    	{
    		//System.out.println("Enter the Starting Micro RNA range to be computed...");
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    		String sInputRange = r[0];
    		int inputRange = -1;
    		try
    			{
    
    				inputRange = Integer.parseInt(sInputRange);
    			}
    			catch(Exception e)
    			{
    				System.out.println("Invalid input...computing with DEFAULT Micro RNA Range 40.");
    				inputRange = -1;
    			}
    		RNA rna = new RNA(inputRange);
    		[B][B][QUOTE][COLOR="blue"]rna.init();[/COLOR][/QUOTE][/B]B]	
    	rna.compare();
    
    	}
    
    }
    Java Code:
    Errors: (because 3 directories are there now; so 3 times error reported)
    Exception in thread "main" java.lang.NullPointerException
            at RNA.init(RNA.java:65)
            at RNA.main(RNA.java:191)
    Exception in thread "main" java.lang.NullPointerException
            at RNA.init(RNA.java:65)
            at RNA.main(RNA.java:191)
    Exception in thread "main" java.lang.NullPointerException
            at RNA.init(RNA.java:65)
            at RNA.main(RNA.java:191)
    Last edited by kswapnadevi; 11-20-2010 at 07:08 PM. Reason: 65th & 191 line line in bold; MOD EDIT: CODE TAGS ADDED

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Could you say which line 65 is?
    Last edited by pbrockway2; 11-20-2010 at 07:28 AM.

  3. #3
    kswapnadevi is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    Could you say which line 65 is?
    65th line was placed in bold case.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Moderator edit: quote tags changed to code tags so that formatting doesn't get lost.

    To the OP, since you're checking your line after the while loop has completed, looks like you've run into the end of file and line is null.

  5. #5
    kswapnadevi is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    I placed line 65 and 191 in code tags with blue color.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by kswapnadevi View Post
    I placed line 65 and 191 in code tags with blue color.
    What? don't do that as it makes it harder to read your code.

  7. #7
    kswapnadevi is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default

    What can I do sir to get the solution ? U pls tell me. Help me sir.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by kswapnadevi View Post
    What can I do sir to get the solution ? U pls tell me. Help me sir.
    Again, delete those misplaced quote tags in your code post, they don't belong and are quite distracting.

    Again, as I mentioned previously your program logic suggests that you are going through a text file in the while loop, that you finish going through the file and the String variable "line" becomes null, and then you try to call a method on it. Don't do that. Have you tested what line is before using it (I'm talking about where the NPE occurs)? If not, some debugging code in there would help you and us out immensely.

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    some debugging code in there would help you and us out immensely

    I agree.

    A good place to start looking is the first line of your code that is mentioned in the runtime stack trace:

    Java Code:
    Exception in thread "main" java.lang.NullPointerException
            at RNA.init(RNA.java:65)
            at RNA.main(RNA.java:191)

    That would be line 65. (The other line is the place that called the method containing line 65.)

    So, put some code just before line 65 to see what's going on:

    Java Code:
    // ...
    saveLine = line.trim();
    String multiloop = new String();
    if (DEBUG) {
        System.out.println(saveLine);
        System.out.println("before while loop line=" + line);
    }
    
    while (((line = bufferReaderObj.readLine()) != null) 
            && !line.trim().startsWith("Hairpin loop:")) {
        if (line.trim().equals("Multi-loop:")) {
            multiloop = bufferReaderObj.readLine();
            multiloopList = new ArrayList();
            multiloopList.add("Multi-loop:");
            multiloopList.add(multiloop);
           if (DEBUG) {
                System.out.println("multiloop--->" + multiloop);
           }
    
        }
    }
    if (DEBUG) {
        System.out.println("just before if statement line=" + line);
    }
    
    if (line.trim().equals("Hairpin loop:")) {  // <-- line 65
        // ...

    Can you tell from the output which variable is null when it shouldn't be?

    If you can look back through the code for the place where that variable changes value (is assigned to) and try to see why it got a null value.

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

    What can I do sir to get the solution ? U pls tell me. Help me sir.

    It is really important that you figure out what is causing the null pointer exception. You need to focus on "what" for a start because only then can you figure out how to avoid the exception.

    You'll get all the help you need here, but it has to be you for a couple of reasons: first as you program you find (or I do) that null pointer exceptions don't go away. I find I have no choice but to deal with them as they arise. The second reason is that in this case the solution may lie in the code, or it may lie in the data file you are reading (which only you know about).

    Anyway run the debugging code and say what you see, and what it tells you.

  10. #10
    kswapnadevi is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default Java program problem

    After adding those lines when I am compiling, these errors are coming. The input files ‘t1out’ and ‘t2out’ also I am giving here. I am comparing these two files. Each file consists of four sequences starting with ‘-‘ i.e., -50.00, -49.20, -49.20, -47.60. In both the files the sequence order is same.

    The java program compares the sequence number in two files; if matched it go for further conditions. In ‘t2out’ for some sequences the ‘multi-loop’ containing ‘0-0’ values. I think that is null pointing. I am giving the java program also after inserting the code given by you. PLS HELP ME

    1. WARNING in RNA.java (at line 12)
    private ArrayList hairPinList = new ArrayList();
    ^^^^^^^^^^^
    The field RNA.hairPinList is never read locally
    ----------
    2. ERROR in RNA.java (at line 63)
    String multiloop = new String();
    ^^^^^^^^^
    Duplicate local variable multiloop
    ----------
    3. WARNING in RNA.java (at line 143)
    int multiLoopRight = Integer.parseInt(result1[1].trim());
    ^^^^^^^^^^^^^^
    The local variable multiLoopRight is never read
    ----------
    3 problems (1 error, 2 warnings)
    1 import java.io.*;
    2 import java.util.*;
    3
    4 public class RNA
    5 {
    6 public static final String inputFile1 = "t1out";
    7 public static final String inputFile2 = "t2out";
    8
    9
    10 private Hashtable rangeTable = new Hashtable();
    11 private ArrayList multiloopList = new ArrayList();
    12 private ArrayList hairPinList = new ArrayList();
    13 private int STARTRANGE = -1;
    14 private int DEFAULTSTARTRANGE = 40;
    15
    16 private static final boolean DEBUG = false;
    17
    18
    19 public RNA()
    20 {
    21 }
    22
    23 public RNA(int STARTRANGE)
    24 {
    25
    26 this.STARTRANGE = STARTRANGE;
    27 if(STARTRANGE == -1) this.STARTRANGE = DEFAULTSTARTRANGE;
    28 }
    29
    30
    31 private void init() throws IOException
    32 {
    33 FileReader fileReaderObj = new FileReader(inputFile2);
    34 BufferedReader bufferReaderObj = new BufferedReader(fileReaderObj);
    35
    36 String line = null;
    37 line = bufferReaderObj.readLine();
    38 String saveLine = null;
    39 boolean advanced = false;
    40 while(line != null)
    41 {
    42 advanced = false;
    43
    44 if (line.trim().startsWith("-"))
    45 {
    46
    47 saveLine = line.trim();
    48 String multiloop = new String();
    49 if(DEBUG) System.out.println(saveLine);
    50
    51 while (((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("Hairpin loop:"))
    52 {
    53 if (line.trim().equals("Multi-loop:"))
    54 {
    55 multiloop = bufferReaderObj.readLine();
    56 multiloopList = new ArrayList();
    57 multiloopList.add("Multi-loop:");
    58 multiloopList.add(multiloop);
    59 if(DEBUG) System.out.println("multiloop--->"+multiloop);
    60 }
    61 }
    62 saveLine = line.trim();
    63 String multiloop = new String();
    64 if (DEBUG) {
    65 System.out.println(saveLine);
    66 System.out.println("before while loop line=" + line);
    67 }
    68
    69 while (((line = bufferReaderObj.readLine()) != null)
    70 && !line.trim().startsWith("Hairpin loop:")) {
    71 if (line.trim().equals("Multi-loop:")) {
    72 multiloop = bufferReaderObj.readLine();
    73 multiloopList = new ArrayList();
    74 multiloopList.add("Multi-loop:");
    75 multiloopList.add(multiloop);
    76 if (DEBUG) {
    77 System.out.println("multiloop--->" + multiloop);
    78 }
    79
    80 }
    81 }
    82 if (DEBUG) {
    83 System.out.println("just before if statement line=" + line);
    84 }
    85
    86 if (line.trim().equals("Hairpin loop:"))
    87
    88 {
    89 multiloopList.add("Hairpin loop:");
    90 while (((line = bufferReaderObj.readLine()) != null) &&
    !line.trim().startsWith("-"))
    91 {
    92 advanced = true;
    93 if(line.trim().length() > 0)multiloopList.add(line);
    94 if(DEBUG) System.out.println("Hairpin loop--->"+line);
    95
    96
    97 }
    98 if(DEBUG) System.out.println("Hairpin loop size->"+multiloopList.size());
    99
    100 }
    101
    102
    103
    104 }
    105 rangeTable.put(saveLine,multiloopList);
    106 if(!advanced )
    107 {
    108 line = bufferReaderObj.readLine();
    //System.out.println("advance-->"+line);
    110
    111 }
    112 }
    113
    114 }
    115
    116
    117 public void compare() throws IOException
    118 {
    119 FileReader fileReaderObj = new FileReader(inputFile1);
    120 BufferedReader bufferReaderObj = new BufferedReader(fileReaderObj);
    121 boolean advanced = false;
    122 String line = null;
    123 line = bufferReaderObj.readLine();
    124
    125 while(line != null)
    126 {
    127 advanced = false;
    128 System.out.println(line);
    129 if(line.trim().startsWith("-"))
    130 {
    131 List list = (ArrayList)rangeTable.get(line.trim());
    132 while(((line = bufferReaderObj.readLine()) != null) && !line.trim().startsWith("-"))
    133 {
    134
    135 String []result = line.trim().split("-");
    136 int left = Integer.parseInt(result[0].trim());
    137 int right = Integer.parseInt(result[1].trim());
    138 if(left > STARTRANGE && (right - left) > 20)
    139 {
    140 String multiLoopRange = (String)list.get(1);
    141 String []result1 = multiLoopRange.trim().split("-");
    142 int multiLoopLeft = Integer.parseInt(result1[0].trim());
    143 int multiLoopRight = Integer.parseInt(result1[1].trim());
    144
    145 if(left > multiLoopLeft)
    146 {
    147 for(int i = 3; i < list.size(); i++)
    148 {
    149
    150 String hairPinValue = (String)list.get(i);
    151 String []hairPinresult = hairPinValue.trim().split("-");
    152 int hairPinleft = Integer.parseInt(hairPinresult[0].trim());
    153 int hairPinRight = Integer.parseInt(hairPinresult[1].trim());
    154
    155 if(left < hairPinleft && right > hairPinRight)
    156 {
    157
    158 int microRNAleft = left + 21;
    159
    160 if (microRNAleft <= hairPinleft)
    161 {
    162 System.out.println("MIRNA--"+ left +":"+microRNAleft);
    163 }
    164 int microRNAright = hairPinRight + 1 + 21;
    165
    166 if(microRNAright <= right)
    167 {
    168 System.out.println("MIRNA--"+ (hairPinRight+1)+":"+microRNAright);
    169
    170 }
    171
    172 }
    173 }
    174
    175 }
    176
    177
    178 }
    179 advanced = true;
    180 }
    181 }
    182
    183 if(!advanced) line = bufferReaderObj.readLine();
    184 }
    185 }
    186
    187 public static void main(String []r) throws Exception
    188 {
    189 System.out.println("Enter the Starting Micro RNA range to be computed...");
    190 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    191 String sInputRange = in.readLine();
    192 int inputRange = -1;
    193 try
    194 {
    194 {
    195
    196 inputRange = Integer.parseInt(sInputRange);
    197 }
    198 catch(Exception e)
    199 {
    200 System.out.println("Invalid input...computing with DEFAULT Micro RNA Range 40.");
    201 inputRange = -1;
    202 }
    203 RNA rna = new RNA(inputRange);
    204 rna.init();
    205 rna.compare();
    206
    207 }
    208
    209 }
    210
    T1out

    -50.00
    5 - 126
    9 - 120
    11 - 113
    17 - 108
    23 - 102
    29 - 97
    34 - 92
    53 - 63
    65 - 72
    129 - 144
    -49.20
    5 - 126
    9 - 120
    11 - 113
    17 - 108
    23 - 102
    29 - 97
    34 - 92
    55 - 76
    61 - 72
    129 - 144
    -49.20
    5 - 126
    17 - 108
    23 - 102
    29 - 97
    34 - 92
    53 - 63
    65 - 72
    109 - 120
    129 - 144
    -47.60
    5 - 126
    9 - 120
    11 - 113
    17 - 108
    23 - 102
    29 - 97
    34 - 92
    50 - 71
    54 - 66
    129 - 144
    ‘T2out’

    -50.00

    Multi-Loop:
    49-77
    Hairpin Loop:
    132-141
    66-71
    55-61


    -49.20

    Multi-Loop:
    0-0
    Hairpin Loop:
    132-141
    64-69


    -49.20

    Multi-Loop:
    49-77
    Hairpin Loop:
    132-141
    112-117
    66-71
    55-61


    -47.60

    Multi-Loop:
    0-0
    Hairpin Loop:
    132-141
    56-64



    Quote Originally Posted by pbrockway2 View Post
    I agree.

    A good place to start looking is the first line of your code that is mentioned in the runtime stack trace:

    Java Code:
    Exception in thread "main" java.lang.NullPointerException
            at RNA.init(RNA.java:65)
            at RNA.main(RNA.java:191)

    That would be line 65. (The other line is the place that called the method containing line 65.)

    So, put some code just before line 65 to see what's going on:

    Java Code:
    // ...
    saveLine = line.trim();
    String multiloop = new String();
    if (DEBUG) {
        System.out.println(saveLine);
        System.out.println("before while loop line=" + line);
    }
    
    while (((line = bufferReaderObj.readLine()) != null) 
            && !line.trim().startsWith("Hairpin loop:")) {
        if (line.trim().equals("Multi-loop:")) {
            multiloop = bufferReaderObj.readLine();
            multiloopList = new ArrayList();
            multiloopList.add("Multi-loop:");
            multiloopList.add(multiloop);
           if (DEBUG) {
                System.out.println("multiloop--->" + multiloop);
           }
    
        }
    }
    if (DEBUG) {
        System.out.println("just before if statement line=" + line);
    }
    
    if (line.trim().equals("Hairpin loop:")) {  // <-- line 65
        // ...

    Can you tell from the output which variable is null when it shouldn't be?

    If you can look back through the code for the place where that variable changes value (is assigned to) and try to see why it got a null value.

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




    It is really important that you figure out what is causing the null pointer exception. You need to focus on "what" for a start because only then can you figure out how to avoid the exception.

    You'll get all the help you need here, but it has to be you for a couple of reasons: first as you program you find (or I do) that null pointer exceptions don't go away. I find I have no choice but to deal with them as they arise. The second reason is that in this case the solution may lie in the code, or it may lie in the data file you are reading (which only you know about).

    Anyway run the debugging code and say what you see, and what it tells you.

  11. #11
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    It appears that you have just copy/pasted the code I posted into your program to add another while loop. That wasn't the intention - what I meant was for you to add just a few lines of code to what you already had.

    Go back to the code you originally posted and add the few lines shown below (only add the lines shown, the others are only there to show the location of the added lines):

    Java Code:
    // ...
    saveLine = line.trim();
    String multiloop = new String();
    //if(DEBUG) System.out.println(saveLine);                  /* REMOVE THIS*/
    if (DEBUG) {                                               /* ADD THIS */
        System.out.println(saveLine);                          /* ADD THIS */
        System.out.println("before while loop line=" + line);  /* ADD THIS */
    }                                                          /* ADD THIS */
    
    while (((line = bufferReaderObj.readLine()) != null) 
            && !line.trim().startsWith("Hairpin loop:")) {
        if (line.trim().equals("Multi-loop:")) {
            multiloop = bufferReaderObj.readLine();
            multiloopList = new ArrayList();
            multiloopList.add("Multi-loop:");
            multiloopList.add(multiloop);
           if (DEBUG) {
                System.out.println("multiloop--->" + multiloop);
           }
    
        }
    }
    if (DEBUG) {                                                      /* ADD THIS */
        System.out.println("just before if statement line=" + line);  /* ADD THIS */
    }                                                                 /* ADD THIS */
    
    if (line.trim().equals("Hairpin loop:")) {  // <-- line 65
        // ...

    Making only the changes indicated the code does compile. Run it.

    Can you see which variable is null and hence causing the null pointer exception?

    There is just one place that this variable is being assigned to between the two if(DEBUG) blocks. Which line is that?

  12. #12
    kswapnadevi is offline Member
    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    Default java program

    Respected sir, I am getting the following warnings; after running I am getting the following errors; Can I give my server id; username and password ? U can directly see the result.



    1. WARNING in RNA.java (at line 12)
    private ArrayList hairPinList = new ArrayList();
    ^^^^^^^^^^^
    The field RNA.hairPinList is never read locally
    ----------
    2. WARNING in RNA.java (at line 126)
    int multiLoopRight = Integer.parseInt(result1[1].trim());
    ^^^^^^^^^^^^^^
    The local variable multiLoopRight is never read
    ----------
    2 problems (2 warnings)[rsankar@mirna temp]$ java RNA
    Enter the Starting Micro RNA range to be computed...
    40
    Exception in thread "main" java.lang.NullPointerException
    at RNA.init(RNA.java:69)
    at RNA.main(RNA.java:187)
    Quote Originally Posted by pbrockway2 View Post
    It appears that you have just copy/pasted the code I posted into your program to add another while loop. That wasn't the intention - what I meant was for you to add just a few lines of code to what you already had.

    Go back to the code you originally posted and add the few lines shown below (only add the lines shown, the others are only there to show the location of the added lines):

    Java Code:
    // ...
    saveLine = line.trim();
    String multiloop = new String();
    //if(DEBUG) System.out.println(saveLine);                  /* REMOVE THIS*/
    if (DEBUG) {                                               /* ADD THIS */
        System.out.println(saveLine);                          /* ADD THIS */
        System.out.println("before while loop line=" + line);  /* ADD THIS */
    }                                                          /* ADD THIS */
    
    while (((line = bufferReaderObj.readLine()) != null) 
            && !line.trim().startsWith("Hairpin loop:")) {
        if (line.trim().equals("Multi-loop:")) {
            multiloop = bufferReaderObj.readLine();
            multiloopList = new ArrayList();
            multiloopList.add("Multi-loop:");
            multiloopList.add(multiloop);
           if (DEBUG) {
                System.out.println("multiloop--->" + multiloop);
           }
    
        }
    }
    if (DEBUG) {                                                      /* ADD THIS */
        System.out.println("just before if statement line=" + line);  /* ADD THIS */
    }                                                                 /* ADD THIS */
    
    if (line.trim().equals("Hairpin loop:")) {  // <-- line 65
        // ...

    Making only the changes indicated the code does compile. Run it.

    Can you see which variable is null and hence causing the null pointer exception?

    There is just one place that this variable is being assigned to between the two if(DEBUG) blocks. Which line is that?

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Could you please post the code you are using?

    You do not get that output when you use the code you first posted with the changes I suggested. (Mind you, you do not get the exceptions you claimed with that code either...)

    When you post code put [CODE] at the start and [/CODE] at the end. Do not post code that has line numbers embedded in it as that is unusable.

Similar Threads

  1. Java Applet Shell script
    By karthikm897 in forum Java Applets
    Replies: 5
    Last Post: 08-18-2009, 04:42 AM
  2. Replies: 4
    Last Post: 06-24-2009, 06:34 AM
  3. Shell Sort in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 07:44 PM
  4. P~ 0.9 : Java-friendly scripting with powerful regex
    By p7eregex in forum Java Software
    Replies: 0
    Last Post: 12-17-2007, 08:10 PM
  5. Replies: 0
    Last Post: 05-24-2007, 10:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •