读取文本文件时传递变量时出错

时间:2019-04-03 15:31:15

标签: java android

想要使用if语句的结果来解密将读取的文本文件,并尝试将变量作为i传递,该变量将根据if语句进行更改。我将此错误传递回this.getResources()。openRawResource(R.raw.i)

已经尝试分配变量,但是已经在范围内

public void Read(String i){
        InputStream is =  this.getResources().openRawResource(R.raw.i);

        StringBuffer abuffer = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        try {
            while((Resource = reader.readLine())!= null){
                abuffer.append(Resource + "n");

            }
            is.close();

            String resourcePass;                // assing abuffer from textfile read
            resourcePass = abuffer.toString();  //StringBuffer is a peer class of String that provides much of the functionality of strings.
                                                // String represents fixed-length, immutable character sequences while StringBuffer represents
                                                // growable and writable character sequences.
            Intent intent = new Intent(StudentActivity.this, ResourceActivity.class);
            intent.putExtra("r", resourcePass);
            startActivity(intent);
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.FilterGoBtn:
                if (Resource == "Communication and Homeostasis") ;
                String i = ("communicationAndHomeostasis");
                Read(i);

                if (Resource.equals("Excretion")) ;
                i = ("Excretion");
                Read(i);
                if (Resource.equals("Neuronal Communication")) ;
                i = ("NeuronalCommunication");
                Read(i);
                if (Resource.equals("Hormonal Communication")) ;
                i = ("hormonalCommunication");
                Read(i);
                if (Resource.equals("Plant and Animal response")) ;
                i = ("plantAndAnimalResponse");
                Read(i);
                if (Resource.equals("Photosynthesis")) ;
                i = ("Photosynthesis");
                Read(i);
                if (Resource.equals("Respiration")) ;
                i = ("Respiration");
                Read(i);
                break;
            case R.id.newResourceBtn:
              Intent intent2 = new Intent(StudentActivity.this, CardsorNotesActivity.class);
                startActivity(intent2);
                break;
            default:
                break;
        }
    }
}

我需要将其转换回字符串ehich,然后将其作为多余的内容传递给下一个活动

0 个答案:

没有答案