SD.open fail when in loop(), while pass in setup()

i'm very curious about this.
if i do SD.open("test.txt") in setup(), it's ok and read out all the data in test.txt. even i take this step at the end of setup().
but in loop(), it's fail, even in the beginning. i have no idea about this, ask for help.
many thanks.

It should work in the loop() as well. Can you show your sketch ?

Did you check if the return value of SD.open() is not NULL ?
Did you close the file ?
Which Arduino board do you use ? What else is connected to the Arduino board ?
Which SD module do you use ? It is an Ethernet Shield ?

thank you for your advice. i use uno and w5100 for the project.
i found the reason yesterday, the resource of the chip is run up.
when i compile the project, i got the warning that the SRAM of the chip runs up to 78%, but i don't take it seriously until SD.open fail in the loop().
after i remove the unused library and code, the used SRAM is about 68%, the bug is OK.
thanks again.

That is a common problem, the Arduino Uno will run out of memory very quick when the Ethernet and SD are used. Do you use 'PROGMEM' and the 'F()' macro ?

You might need an Arduino Mega 2560 board. If the Ethernet shield is a 'R3' version it will also work with a Arduino Due.

sorry, i'm a freshman on arduino, i don't how to config PROGMEN and F().
on my case, the PROGMEN and F() may not help, because my project need PN532, SD and Ethernet libraries. the only way out is mega 2560 in my opinion.
thanks for your suggestion.

Koepel:
That is a common problem, the Arduino Uno will run out of memory very quick when the Ethernet and SD are used. Do you use 'PROGMEM' and the 'F()' macro ?

You might need an Arduino Mega 2560 board. If the Ethernet shield is a 'R3' version it will also work with a Arduino Due.

PROGMEM and the 'F()' macro can be used when that data is not changed. The data can be stored in flash code only. Show us your sketch, and we can tell where to use them.

http://playground.arduino.cc/Learning/Memory

Do you use String objects ? Then you can run out of memory very quick. Try not to use them for an Arduino Uno.

Updating to an Arduino Mega 2560 is very good, but you might still look into the PROGMEM an 'F()' macro and avoiding String objects, to make it run smooth and reliable.

many thanks! i'll try it.
yes, i use a lot String object in my project, i'll try you suggestion, thanks.

Koepel:
PROGMEM and the 'F()' macro can be used when that data is not changed. The data can be stored in flash code only. Show us your sketch, and we can tell where to use them.
PROGMEM - Arduino Reference
Arduino Playground - HomePage

Do you use String objects ? Then you can run out of memory very quick. Try not to use them for an Arduino Uno.
Solving Memory Problems | Memories of an Arduino | Adafruit Learning System

Updating to an Arduino Mega 2560 is very good, but you might still look into the PROGMEM an 'F()' macro and avoiding String objects, to make it run smooth and reliable.