here is my entire code. now, the only problem I have stumbled upon is in the last method, getRow, where i have to extract a row from an array of string. could anyone please help me with this, i've been stuck for hours, not knowing why it calls "missing return statement", when i clearly do it -.-' thank you in advance

import java.util.ArrayList;

public class Photograph
{
    
    private String[] photograph;
    
    public Photograph(String[] photograph)
    {
        if (photograph == null)
            photograph = new String[] {""};
        else this.photograph = photograph;
    }

    public int getWidth()
    {
        return (photograph[0]).length();
    }

    public int getHeight()
    {
        return photograph.length;
    }
   

    /**
     * @null if the index is out of bounds.
     */
    public String getLine(int index)
    {
        if (index < 0 || index >= getHeight())
            return null;
        return photograph[index];
    }
    
    public String getRow(int index)
    {
        if (index < 0 || index >= getWidth())
            return null; 
        for (int row = 0; row < getHeight(); row++) 
             return photograph[row].substring(index, index + 1);  
    }
    
}

Both of your returns are in conditional statements. The compiler requires a guaranteed return value for all possible conditions.

Add a default return value at the end to cover the case of your other conditions not being satisfied.

thank you very much for the quick response! but i dont think i completely understand what you mean.. to me the getLine and getRow methods function in principally the same way, and that's why i don't see why it wouldn't work..

getLine has a guaranteed return even if the if() statement is false.

getRow() has two returns but one is in if() and the other in for(). You need a return in case those do not execute.

getLine has a guaranteed return even if the if() statement is false.

getRow() has two returns but one is in if() and the other in for(). You need a return in case those do not execute.

Ahh, thank you very much, now i get it!

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.