私は、人のリストを取得して表示しようとしている Android プロジェクトに取り組んでいます。Person クラスには profilePhoto が String として含まれており、DB に保存されていることを確認できます。Person のリストを取得した後、Log.d に出力できます。しかし、Skia のことは、Factory が null であると言っています。
同じ件名の他の質問があることは知っていますが、画像だけを取得するのではなく、人物のリストを取得しており、画像はその中の単なる変数です。
エラーが発生する理由:
画像保存コード:
public class AddPhotoForUser extends Activity {
private static final int CAMERA_PIC_REQUEST = 22;
Button BtnSelectImage;
private ImageView ImgPhoto;
private static volatile Bitmap photo;
private static volatile ByteArrayOutputStream stream = new ByteArrayOutputStream();
final PersonServiceImpl personService = new PersonServiceImpl();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upload_user_photo);
Button uploadImageButton = (Button) findViewById(R.id.uploadUserImageButton);
uploadImageButton.setVisibility(View.INVISIBLE);
ImgPhoto = (ImageView) findViewById(R.id.userPhotoImageView);
BtnSelectImage = (Button) findViewById(R.id.userPhotoButtonSelect);
BtnSelectImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Couldn't load photo", Toast.LENGTH_LONG).show();
}
}
});
uploadImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!(v == null)) {
uploadImage();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent intent = new Intent(AddPhotoForUser.this, RestaurantList.class);
startActivity(intent);
finish();
}
}
});
}
@Override
public void onBackPressed() {
Intent intent = new Intent(AddPhotoForUser.this, Login.class);
startActivity(intent);
finish();
}
@Override
public void onActivityResult(final int requestCode, int resultCode, Intent data) {
try {
switch (requestCode) {
case CAMERA_PIC_REQUEST:
if (resultCode == RESULT_OK) {
try {
photo = (Bitmap) data.getExtras().get("data");
if (!(photo == null)) {
ImgPhoto.setImageBitmap(photo);
Button uploadImageButton = (Button) findViewById(R.id.uploadUserImageButton);
uploadImageButton.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
Toast.makeText(this, "Couldn't load photo", Toast.LENGTH_LONG).show();
}
}
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void uploadImage() {
if (!(photo == null)) {
photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
personService.addUserProfilePhoto(Base64.encodeToString(byteArray, Base64.DEFAULT));
}
}
}
以下は、ユーザーのリストを取得し、それをアダプターに結び付ける場所です。
public class OtherUsers extends Activity {
private PersonServiceImpl personService = new PersonServiceImpl();
private static volatile List<RestPerson> restPersonList = new ArrayList<>();
public static final String firstName = "firstname";
public static final String userImage = "userimage";
static final String userId = "0";
ListView listView;
UserAdapter userAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.displayuserlist);
restPersonList = this.personService.getOtherUsers();
ArrayList<HashMap<String, String>> usersArrayHashList = new ArrayList<>();
for (RestPerson restPerson : restPersonList) {
HashMap<String, String> restDisplay = new HashMap<>();
restDisplay.put(userId, String.valueOf(restPerson.getUserId()));
restDisplay.put(firstName, restPerson.getFirstName());
restDisplay.put(userImage, restPerson.getProfilePhoto());
usersArrayHashList.add(restDisplay);
}
listView = (ListView) findViewById(R.id.usersdisplaylist);
userAdapter = new UserAdapter(this, usersArrayHashList);
listView.setAdapter(userAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.d("Item", "wasclicked");
Long userid = restPersonList.get(position).getUserId();
Log.d("Userid is ", String.valueOf(userid));
}
});
}
}
ここに私のアダプターがあります:
public class UserAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public UserAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null)
view = inflater.inflate(R.layout.userprofiles, null);
TextView username = (TextView) view.findViewById(R.id.userName);
ImageView userImage = (ImageView) view.findViewById(R.id.userImage);
HashMap<String, String> usersList = new HashMap<>();
usersList = data.get(position);
username.setText(usersList.get(OtherUsers.firstName));
byte [] encodeByte=Base64.decode(usersList.get(OtherUsers.userImage).getBytes(), Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
userImage.setImageBitmap(bitmap);
Log.d("Image is ",usersList.get(OtherUsers.userImage));
return view;
}
}
下部の Log.d に注目してください。これは、Image is、それはイメージを印刷していることを示しています。ここに出力があります。
08-24 15:55:34.767 28131-28131/internetlegion.com.gradlecheck D/skia﹕ --- SkImageDecoder::Factory returned null
08-24 15:55:34.767 28131-28131/internetlegion.com.gradlecheck D/Image is﹕ ImlWQk9SdzBLR2dvQUFBQU5TVWhFVWdBQUFLQUFBQUI0Q0FJQUFBRDZ3RzQ0QUFBQUEzTkNTVlFJ
Q0FqYjRVL2dBQUFFSkVsRVFWUjRcbm5PMmRRV3ZjUmhpR3YyODBhMHpCeDlCZ3JVOU9RdWlsbElE
c2t3Mmg1NURrdi9nSGhmNk4zTHNTZFVySUtjZUVGWmdlQzZYQkhzM1hcblE0SnRnck1hN1VycTV0
WDczTHorOU02c0hxMW04Vmd6dXJ1N0syMFVSWEYwZE5SYWRrMVZWV1ZacHRjemY3aDhsMzRZK1I2
aFlIQW9cbkdCd0tCb2VDd2FGZ2NDZ1lIQW9HaDRMQm9XQndLQmdjQ2dhSGdzRkpGYXlxblhMTnJG
TTk4d2ZLMTdPenM5YnFxcW9XaTBWNkcwVlJcbkh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NhVFh2ZzZcbnV6NjZUUXhs
aUZtSStkV3ZqMG5EdGVjN0dNN0FjQWFHTXpDY2dlRU1ER2RndURDZFRxc1hRbmo5UUJsamVMeDZ2
Qy91RzlpdEYvdi9cbmd3Yy9Qd3grWENZOTkyRC9qNzFXak1qNWVkMko1WU1McjhzWXc4WGxSYWY0
RDIvNjdYYjdhZkk1NlNsdHVURDkzUFBiY1loTy9YWFdcblhqc0M2NThaR003QWNBYUdNekNjZ2VF
TURHZGdPQVBER1JqT3dIQUdoak13M09tM2o1WXhodWYrODFQMjFNQnUvYVhmNzFOdjd6ejNcbi9O
RHRWbCt3dmxnc1hqOXc1TUwzYy9qend2ZHZYMjZTbm51dy8wZXNWaXZrL0x3dHAxclB2Wi9VK2Y0
TmhqTXduSUhoREF4bllEZ0Rcbnd4a1l6c0J3Qm9Zek1KeUI0UXdNWjJDNDB6OG5xNU5sV2ZGUUZB
OUY1Zks1YjZlOHliNG5iYThYZWQwUHVpMzN2enIvN2ZrZW91RU1cbkRHZGdPQVBER1JqT3dIQUdo
ak13bklIaERBeG5ZRGdEd3hrWXpzQnd0ZWVEVXovZk9KWHptNW52RjBURDUvc0YwZkQ1L2cyR016
Q2NcbmdlRU1ER2RnT0FQREdSak93SEFHaGpNd25JSGhEQXhuWURnRHc0WFpiRmE1UVAzQzVQYzJQ
eCtQeDVVTGJibkIyZmx2ei9jUURXZGdcbk9BUERHUmpPd0hBR2hqTXduSUhoREF4bllEZ0R3eGtZ
enNCd0JvYno5bEg0L05EcjlTb1hxT2RIMzl0OEQ5RndCb1l6TUp5QjRRd01cbloyQTRBOE1aR003
QWNBYUdNekNjZ2VFTURQY2JUQ1lhZzYwTHNwNEFBQUFBU1VWT1JLNUNZSUk9XG4i
08-24 15:55:34.767 28131-28131/internetlegion.com.gradlecheck D/skia﹕ --- SkImageDecoder::Factory returned null
08-24 15:55:34.767 28131-28131/internetlegion.com.gradlecheck D/Image is﹕ ImlWQk9SdzBLR2dvQUFBQU5TVWhFVWdBQUFLQUFBQUI0Q0FJQUFBRDZ3RzQ0QUFBQUEzTkNTVlFJ
Q0FqYjRVL2dBQUFFSkVsRVFWUjRcbm5PMmRRV3ZjUmhpR3YyODBhMHpCeDlCZ3JVOU9RdWlsbElE
では、SkiaImageFactory のことで一体何をすればよいのでしょうか。どんな助けでもいいでしょう。単一の画像を取得するのではなく、サーバーから Person クラス全体を取得していることに注意してください。