마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

raw폴더에서 text파일을 읽으려하는데 다른 클래스에서는 읽히는데 readTxext클래스에서는 에러가나요

0 추천
package com.example.comm118.osgumifood; import android.app.Activity; import android.os.Bundle; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream;

public class readTxext extends Activity {

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_food); }

public readTxext() { readText(); }

private String readText() { String data = null; InputStream inputStream = getResources().openRawResource(R.raw.text1) ; //여기서안됨

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i; try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } data = new String(byteArrayOutputStream.toByteArray(),"MS949"); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return data ; } public String readStringText() { return readText() ; } }

===============================================================

InputStream inputStream = getResources().openRawResource(R.raw.text1) ;

여기서 에러가 잡힙니다.

되는 클래스=====================================================

package com.example.comm118.osgumifood; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream;

public class FoodActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_food);

Food food = new Food();

toDay today = new toDay() ;

readTxext txt = new readTxext();//문제발생

TextView dateText = (TextView) findViewById(R.id.date) ;

TextView timeText = (TextView) findViewById(R.id.time1) ;

TextView foodText = (TextView) findViewById(R.id.food1) ; TextView timeText2 = (TextView) findViewById(R.id.time2) ; TextView foodText2 = (TextView) findViewById(R.id.food2) ; TextView timeText3 = (TextView) findViewById(R.id.time3) ; TextView foodText3 = (TextView) findViewById(R.id.food3) ; dateText.setText(food.toDateString()); timeText.setText(food.toTimeString()); foodText.setText(txt.readStringText()); timeText2.setText(food.toTimeString()); foodText2.setText(today.printDay()); timeText3.setText(food.toTimeString()); foodText3.setText(readTxt()); } private String readTxt() { String data = null; InputStream inputStream = getResources().openRawResource(R.raw.text1); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i; try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } data = new String(byteArrayOutputStream.toByteArray(),"MS949"); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return data; } }

 

여기서는 됩니다.
흔바생 (120 포인트) 님이 2016년 6월 9일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...