. Length Cannot Be Resolved or Is Not a Field

I have tried really hard to solve this with previous similar answers, but am still nto able to see my problem, hope you can help. My code looks like this:

String MyContent =" ";
String nextline = " ";

InputStream in = new FileInputStream(f);

BufferedInputStream bin = new BufferedInputStream(in);

DataInputStream din = new DataInputStream(bin);

    while(din.available()>1)
    {
    nextline = din.readLine();

    //Filter out XML headers which are not browser compliant
    if (nextline.length > 4)
        {
        if (nextline.substring(1,5) != "<?xml")
            {
            MyContent=MyContent+ nextline;
            }
        }   
    }

    out.print (MyContent);

in.close();
bin.close();
din.close();

And I am getting an error:

An error occurred at line: 25 in the jsp file: /MaxiSunReports/DisplayXMLFile.jsp
nextline.length cannot be resolved or is not a field
22:     nextline = din.readLine();
23:     nextline = "THISISATEST";
24:     //Filter out XML headers which are not browser compliant
25:     if (nextline.length > 4)
26:         {
27:         if (nextline.substring(1,5) != "<?xml")
1

3 Answers

First, the method readLine() in DataInputStream is deprecated.

Second, this method returns a String, which doesn't have a field length. It only has the method length(). length is a property of arrays.

length is not an field. It is a function, so you have to call nextline.length() > 4

0

length is not a property, it is a method..

Use

while(din.available()>1)
{
nextline = din.readLine();

//Filter out XML headers which are not browser compliant
if (nextline.length() > 4)
    {
    if (nextline.substring(1,5) != "<?xml")
        {
        MyContent=MyContent+ nextline;
        }
    }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest