[英]Is there a way to avoid size limit when using getResources().openRawResource()
[英]Error calling getResources().openRawResource()
我必須在java / eclipse / android上使用以下代碼讀取一個名為hello.txt
的文件:
import java.io.InputStream;
public class Tokenirzer {
public String ReadPath () {
InputStream inputStream = getResources().openRawResource(R.raw.hello);
}
}
但是我收到以下錯誤:
對於Tokenirzer類型,未定義方法getResources()
我究竟做錯了什么?
getResources()
是Context
一部分。 您可以像在Activity
那樣使用它,因為它是從Context
繼承的。 您需要傳遞活動的Context才能使用getResources
。
您的類Tokenirzr
不包含方法getResources()
。
我看到這個問題很老,但是我遇到了類似的情況,根據我的經驗,有兩種解決方案。 該類必須擴展Activity()或應從MainActivity()傳遞引用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.