首先我要爲我的英語不好道歉,我是來自斯洛伐克)不讀文件
因此,有我的問題
我的朋友想創建一個非常簡單的翻譯aplication,非常非常很簡單。我們是爲Android編程的初學者,並且完全是用java編寫的。問題是,我們的apk在Eclipse中工作得很好,因此我們決定創建apk文件並將其安裝到我們的設備中。所以當我們安裝它並出現問題時,我們的apk中的設備不會讀取文件,我們的文字在哪裏。所以我們在eclipse模擬器中再次嘗試它,並且不起作用,但是在創建apk之前它已經完全工作。我們的文件是在res /生/字典
這裏是我們的代碼
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;
}
}
錯誤的logcat
error opening trace file: no such file or directory(2)
你在logcat中看到錯誤嗎?如果是這樣,請把它寫在你的問題上。 –
資產文件是否實際存在於您的資產目錄中? –
無論您認爲自己的問題是什麼,該錯誤消息與您的問題無關。 – CommonsWare