메시지를 여러 번 표시하기 위해 안드로이드에서 토스트를 사용했지만 전혀 문제가 없었습니다. 그러나 컴파일러가 어떤 이유로이 시간에 작동하도록 허용하지 않습니다. 토스트가이 방법의 내부에 놓이는 것을 허용하지 않는 이유는 무엇입니까?안드로이드 자바 메소드 내에서 토스트 메시지 컴파일 오류가 발생했습니다
이 코드에서는 "ThumbnailsActivity.class"와 "this"두 가지 유형의 컨텍스트를 모두 시도했습니다.
decodeSampleBitmapFromResource 메소드는 Activity를 확장하는 Android 클래스 ThumbnailsActivity.java 안에 있습니다. 여기에는 특별한 것이 없습니다.
public static Bitmap decodeSampledBitmapFromResource(String fileName, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(fileName, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(fileName, options);
// both of the toasts shown here have compile errors
Toast.makeText(ThumbnailsActivity.class, "TEST",Toast.LENGTH_LONG).show();
Toast.makeText(this, "TEST",Toast.LENGTH_LONG).show();
}//end decodeSampledBitmapfromresource method
사용 getApplicationContext() .. :) –
시도'ThumbnailsActivity.this' : –