Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

FileNotFoundException

Can someone explain a FileNotFoundException in android app? The documentation confuses me and I've looked at StackOverflow and this doesn't help me either. I have an android app where I keep getting this error and I think it's because I haven't specified the full path but I don't know how I would do this. Here is the code and I swear all the locations referenced exist. It worked fine until I added in the if and else statement that checked if it matched up.

public class GameActivity extends AppCompatActivity {

private Game game;
private ImageView gameImageView;
private TextView gameTextView;
private Button submitButton;
private TextView pointsTextView;
private int points;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    gameImageView = (ImageView) findViewById(R.id.gameImageView);
    gameTextView = (TextView) findViewById(R.id.gameTextView);
    pointsTextView = (TextView) findViewById(R.id.pointsTextView);
    submitButton = (Button) findViewById(R.id.submitButton);
    game = new Game();
    loadPage(0);
    specialCondition(0);
}


private void loadPage(final int pageNumber) {

    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            specialCondition(pageNumber);
        }
    });

}

private void specialCondition(int pageNumber) {
    final Page page = game.getPage(pageNumber);
    if (pageNumber == 20) {
        startSubmit();
    }
    else if (pageNumber < 20) {
        Drawable image = ContextCompat.getDrawable(this, page.getImageId());
        gameImageView.setImageDrawable(image);
        String gameAnswer = getString(game.getPage(pageNumber).getAnswerId());

        String pageText = getString(page.getTextId());
        gameTextView.setText(pageText);

        String pointsText = String.format("%1$s", points);
        pointsTextView.setText(pointsText);

        String gameEditText = ((EditText) findViewById(R.id.gameSquare)).getText().toString();

        if (gameEditText == gameAnswer.toLowerCase()) {
            points++;
        } else if (gameEditText != gameAnswer.toLowerCase()) {
            points--;
        }

        int nextPage = page.getNextPage();
        loadPage(nextPage);
    }
}

private void startSubmit() {
 Intent submitIntent = new Intent(this, SubmitActivity.class);
    startActivity(submitIntent);
}

}

Joshua Douce
Joshua Douce
13,120 Points

Hi Kenneth,

Would you be able to paste in the stack trace?

1 Answer

I'm not sure exactly what stack trace is but after looking it up I think it's this. If not just tell me what you're looking for:

10-08 20:40:27.428 1364-1364/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-nb.pat.txt java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-nb.pat.txt: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:452) at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207) at libcore.io.IoUtils.readFileAsString(IoUtils.java:114) at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96) at android.text.Hyphenator.init(Hyphenator.java:154) at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207) at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438) at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207)  at libcore.io.IoUtils.readFileAsString(IoUtils.java:114)  at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96)  at android.text.Hyphenator.init(Hyphenator.java:154)  at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207)  at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 

10-08 20:40:27.428 1364-1364/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-nn.pat.txt java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-nn.pat.txt: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:452) at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207) at libcore.io.IoUtils.readFileAsString(IoUtils.java:114) at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96) at android.text.Hyphenator.init(Hyphenator.java:154) at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207) at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438) at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207)  at libcore.io.IoUtils.readFileAsString(IoUtils.java:114)  at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96)  at android.text.Hyphenator.init(Hyphenator.java:154)  at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207)  at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 

10-08 20:40:27.428 1364-1364/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-sa.pat.txt java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-sa.pat.txt: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:452) at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207) at libcore.io.IoUtils.readFileAsString(IoUtils.java:114) at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96) at android.text.Hyphenator.init(Hyphenator.java:154) at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207) at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438) at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207)  at libcore.io.IoUtils.readFileAsString(IoUtils.java:114)  at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96)  at android.text.Hyphenator.init(Hyphenator.java:154)  at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207)  at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)  10-08 20:40:27.428 1364-1364/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-und-ethi.pat.txt

                                         java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-und-ethi.pat.txt: open failed: ENOENT (No such file or directory)
                                             at libcore.io.IoBridge.open(IoBridge.java:452)
                                             at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207)
                                             at libcore.io.IoUtils.readFileAsString(IoUtils.java:114)
                                             at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96)
                                             at android.text.Hyphenator.init(Hyphenator.java:154)
                                             at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207)
                                             at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186)
                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
                                          Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                             at libcore.io.Posix.open(Native Method)
                                             at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
                                             at libcore.io.IoBridge.open(IoBridge.java:438)
                                             at libcore.io.IoUtils$FileReader.<init>(IoUtils.java:207) 
                                             at libcore.io.IoUtils.readFileAsString(IoUtils.java:114) 
                                             at android.text.Hyphenator.loadHyphenator(Hyphenator.java:96) 
                                             at android.text.Hyphenator.init(Hyphenator.java:154) 
                                             at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:207) 
                                             at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:186) 
                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 

I know this is really messy but I separated it the best I could.Thanks again for helping me last time and just tell me if you need something else.