문제

I've been trying to recreate a simple Java program on my new Android device. Basically, I have a SpinnerView, the elements of which start a new Activity when selected. The individual Spinner Items correspond to .txt file names stored in the directory of

Master Sources/Russian/

When a spinner item is selected, a new activity is started and passed the item's text, which is the name of a txt file, once again. The new activity receives name of the file as well as the corresponding directory text, in this case "Master Sources/Russian/":

First Activity:

rusSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){

                Intent rusProgressionIntent = new Intent(LangMenuActivity.this, RecipientActivity_presentation.class);

                rusProgressionIntent.putExtra("fileName", ("Master Sources/Russian/" + rusSpinner.getSelectedItem().toString() + ".txt"));
                startActivity(rusProgressionIntent);
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0){}
    });

Here you can see I pass directory, plus the name of the file, which is the text of the Spinner entry, and the ".txt" extension.

Second Activity:

Intent toGet = getIntent();
    String fileName = toGet.getExtras().getString("fileName");
File referenceFile = new File(fileName);

For some reason this file cannot be found. I've checked tirelessly, the file is in that directory within the package explorer, properly setup, and the Spinner names match those of the files. The LogCat keeps returning that the file cannot be found, and corresponding null pointers follow.

Please, what could be wrong?

도움이 되었습니까?

해결책

Do not forget to: <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> permission in your manifest. It's mandatory now on Android 4.4 KitKat.

다른 팁

Make sure you have added read memory permission

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top