OpenMapLayer extends StringLayer ...
else if(layer instanceof StringLayer)
{
System.out.println(layer.getName()+" turned on");
StringLayer layer1 = (StringLayer) layer; //this is fine
OpenMapLayer oml = (OpenMapLayer)layer1; //this line gives the error
}
This means that layer is an instance of StringLayer hence the cast to StringLayer works fine. However just because it's an instanceof StringLayer it does not mean it's an instance of OpenMapLayer. Every OpenMapLayer will be an instance of StringLayer but not every instance of StringLayer is going to be of type OpenMapLayer.