먼저 내 나쁜 영어에 대해 사과하고 싶은 파일을 읽을하지 않습니다 아주 간단합니다. 우리는 안드로이드 프로그래밍과 자바 프로그래밍에 초보자입니다. 문제는 우리 apk가 Eclipse에서 훌륭하게 작동하므로 apk 파일을 만들고이를 장치에 설치하기로 결정한 것입니다. 그래서 우리가 그것을 설치했을 때 문제가 있었는데, 우리의 APK 장치에서 우리의 단어가 어디 파일을 읽지 않습니다. 그래서 우리는 Eclipse 에뮬레이터에서 다시 시도해 보았지만 apk를 만들기 전에 완전히 작동했습니다. 우리의 파일이 여기에, 나는 슬로바키아에서 오전
고해상도/원료/사전에하는 것이 우리의 코드 openRawResource()는 고해상도의 파일위한 InputStream를 가져옵니다().
package com.example.dictionary;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView Vstup;
TextView Vystup;
Button presun;
String slovo;
String word;
String found;
Boolean click;
int i;
int j;
String sub;
String strf;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Vstup = (TextView)findViewById(R.id.editText1);
Vystup = (TextView)findViewById(R.id.textView2);
presun = (Button)findViewById(R.id.button1);
presun.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
slovo = Vstup.getText().toString();
InputStream is = getResources().openRawResource(R.raw.dictionary);
InputStreamReader inputStreamReader = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
while((strf = bufferedReader.readLine()) != null)
{
i = strf.indexOf(":"); // vrati prvu poziciu retazca
j = strf.indexOf(",");
sub = strf.substring(0,i); //vyberie zo stringu podretazec od indexu 0 po i
if(slovo.equals(sub))
{
found = strf.substring(i+1,j);
word = ("Výstup: " + found);
Vystup.setText(word.toString());
}
else {
word = ("Výstup: Word not found");
Vystup.setText(word.toString());
}
}
bufferedReader.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
오류
로그 캣error opening trace file: no such file or directory(2)
logcat에 오류가 있습니까? 그렇다면 귀하의 질문에 넣어주십시오. –
자산 파일이 실제로 자산 디렉토리에 있습니까? –
해당 오류 메시지는 문제가 무엇이든지간에 문제와 관련이 없습니다. – CommonsWare