I have an app run normally in the emulator with API 28. But when I run the app in the emulator with API 29 it shows
It does not only show keeps stopping in the emulator. I tried to install it on mobile and it also shows the same error.
The log shows this error like this:
2020-02-14 19:48:12.922 20370-20370/? E/stickerappmake: Unknown bits set in runtime_flags: 0x8000
2020-02-14 19:48:15.326 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:15.326 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:15.385 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:15.385 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:17.138 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:17.139 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:17.243 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:17.243 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:19.984 20370-20464/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:19.984 20370-20464/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:20.048 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:20.048 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:20.059 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:20.063 20370-20454/com.testdev.appname E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef
2020-02-14 19:48:22.727 20370-20370/com.testdev.appname E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.testdev.appname, PID: 20370
java.lang.NullPointerException: Attempt to get length of null array
at com.testdev.appname.activities.CreateFragment.loadStickersCreated(CreateFragment.java:52)
at com.testdev.appname.activities.CreateFragment.onCreateView(CreateFragment.java:88)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1425)
at android.app.Activity.performStart(Activity.java:7825)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3294)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I see there some problems with the java code in CreateFragment.java. And the java code is like below: The CreateFragment.java code:
package com.devname.appname.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.support.v4.app.Fragment;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.facebook.drawee.view.SimpleDraweeView;
import com.devname.appname.helpers.Admob;
import com.sangcomz.fishbun.FishBun;
import com.sangcomz.fishbun.adapter.image.impl.GlideAdapter;
import com.sangcomz.fishbun.define.Define;
import com.devname.appname.R;
import com.devname.appname.backgroundRemover.CutOut;
import com.devname.appname.helpers.Constants;
import com.devname.appname.utils.FileUtils;
import com.devname.appname.utils.StickerPacksManager;
import java.io.File;
import java.util.ArrayList;
public class CreateFragment extends Fragment {
ImagesGridAdapter imagesGridAdapter;
View view;
public CreateFragment() {
// Required empty public constructor
}
public static ArrayList<Uri> loadStickersCreated() {
String directoryPath = Constants.STICKERS_CREATED_DIRECTORY_PATH;
File directory = new File(directoryPath);
ArrayList<Uri> images = new ArrayList<>();
if (directory.exists()) {
File[] stickersImages = directory.listFiles();
for (File f : stickersImages) {
if (f.isFile() && (f.getName().contains(".png") || f.getName().contains(".PNG"))) {
images.add(Uri.fromFile((f)));
}
}
} else {
directory.mkdir();
}
// verifyStickersCount();
return images;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_create, container, false);
Admob.createLoadBanner(getContext(), view);
view.findViewById(R.id.create_sticker).setOnClickListener(v -> FishBun.with(getActivity())
.setImageAdapter(new GlideAdapter())
.setMaxCount(1)
.exceptGif(true)
.setMinCount(1)
.setActionBarColor(getResources().getColor(R.color.colorPrimaryDark), getResources().getColor(R.color.colorPrimary), false)
.setActionBarTitleColor(Color.parseColor("#ffffff"))
.startAlbum());
RecyclerView gridview = view.findViewById(R.id.stickers_created_grid);
GridLayoutManager gridLayoutManager = new GridLayoutManager(view.getContext(), 3);
gridview.setLayoutManager(gridLayoutManager);
imagesGridAdapter = new ImagesGridAdapter(view.getContext(), loadStickersCreated());
gridview.setAdapter(imagesGridAdapter);
verifyStickersCount();
return view;
}
public void verifyStickersCount() {
View linearLayout = view.findViewById(R.id.no_stickers_icon);
if (imagesGridAdapter == null || imagesGridAdapter.getItemCount() == 0) {
linearLayout.setVisibility(View.VISIBLE);
} else {
linearLayout.setVisibility(View.GONE);
}
}
public static void addImageToGallery(final String filePath, final Context context) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA, filePath);
context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("TESTTTTTT",requestCode+"");
if (requestCode == CutOut.CUTOUT_ACTIVITY_REQUEST_CODE) {
Log.d("TESTTTTTT :::::",requestCode+"");
switch (resultCode) {
case Activity.RESULT_OK:
String imagePath_intent = data.getStringExtra("imagePath");
Uri imageUri = Uri.fromFile(new File(imagePath_intent));
Log.d("TESTTTTTT ::::: He",imageUri+"");
String stickerName = FileUtils.generateRandomIdentifier();
Uri imagePath = Uri.parse(Constants.STICKERS_CREATED_DIRECTORY_PATH + stickerName + ".PNG");
StickerPacksManager.createStickerImageFile(imageUri, imagePath, getActivity(), Bitmap.CompressFormat.PNG);
addImageToGallery(imagePath.getPath(), getActivity());
imagesGridAdapter.uries = loadStickersCreated();
imagesGridAdapter.notifyDataSetChanged();
Toast.makeText(getActivity(), "Sticker created", Toast.LENGTH_LONG).show();
verifyStickersCount();
break;
case CutOut.CUTOUT_ACTIVITY_RESULT_ERROR_CODE:
Exception ex = CutOut.getError(data);
Log.d("TESTTTTTT :::::",ex+"::DDD");
break;
default:
System.out.print("User cancelled the CutOut screen");
}
} else if (requestCode == Define.ALBUM_REQUEST_CODE) {
ArrayList<Uri> uries;
if (resultCode == Activity.RESULT_OK) {
uries = data.getParcelableArrayListExtra(Define.INTENT_PATH);
CutOut.activity().src(uries.get(0)).intro().start(getActivity());
}
}
}
public class ImagesGridAdapter extends RecyclerView.Adapter<ImageViewHolder> {
public ArrayList<Uri> uries = new ArrayList<>();
Context context;
public ImagesGridAdapter(Context context, ArrayList<Uri> uries) {
this.uries = uries;
this.context = context;
}
@NonNull
@Override
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
final Context context = viewGroup.getContext();
final LayoutInflater layoutInflater = LayoutInflater.from(context);
final View view = layoutInflater.inflate(R.layout.sticker_created_item, viewGroup, false);
return new ImageViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder imageAdapter, int index) {
imageAdapter.imageView.setImageURI(uries.get(index));
imageAdapter.imageView.setPadding(8, 8, 8, 8);
imageAdapter.imageView.setOnLongClickListener(v -> {
PopupMenu popupMenu = new PopupMenu(context, imageAdapter.imageView);
popupMenu.inflate(R.menu.sticker_menu);
popupMenu.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
/* case R.id.add_to_exist_stickerpack:
addToStickerPack(index);
break;*/
case R.id.delete_sticker:
this.deleteSticker(index);
break;
default:
break;
}
return false;
});
popupMenu.show();
return false;
});
}
void deleteSticker(int index) {
new AlertDialog.Builder(context)
.setTitle("Deleting")
.setMessage("Are you sure you want to delete this sticker?")
.setPositiveButton("Yes", (dialog, which) -> {
Uri uri = uries.get(index);
FileUtils.deleteFile(uri.getPath(),context);
uries.remove(index);
notifyItemRemoved(index);
notifyDataSetChanged();
Toast.makeText(context, "Deleted", Toast.LENGTH_SHORT).show();
verifyStickersCount();
})
.setNegativeButton("No", null)
.show();
}
void addToStickerPack(int index) {
Intent intent = new Intent(context, AddToStickerPackActivity.class);
intent.setData(uries.get(index));
startActivity(intent);
}
@Override
public int getItemCount() {
return uries.size();
}
}
class ImageViewHolder extends RecyclerView.ViewHolder {
SimpleDraweeView imageView;
public ImageViewHolder(@NonNull View itemView) {
super(itemView);
this.imageView = itemView.findViewById(R.id.sticker_created_image);
}
}
}
Let's read your error message:
java.lang.NullPointerException: Attempt to get length of null array
some array of you is null
and you still try to get the length
of it.
at com.testdev.appname.activities.CreateFragment.loadStickersCreated(CreateFragment.java:52)
and it even tells you, in which line you will find the error
File[] stickersImages = directory.listFiles();
stickerImages seems to be null.
for (File f : stickersImages) {/*...*/}
it tries to read from stickerImages
, which is null
and therefore this Exception
is thrown.
As per your comments these are your app permissions in your manifest :
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
you need to add read permissions to in order to get the files from directory so apply below permission to your manifest :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Also you should check this permission in run-time too because the user might deny it and this error will show again, you can do the check as below :
public boolean readExtertalStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int result = context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
}
return false;
}
For more details you can check here
The problem is in directory path in Constants.STICKERS_CREATED_DIRECTORY_PATH. In Constant.java there some codes like below:
public final static String STICKERS_CREATED_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + "/WA Stickers/My Created/";
then I specify the directory path
public final static String STICKERS_CREATED_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + "/storage/emulated/0/WA Stickers/My Created/";
It works. Thanks for your answers.
Edited: It works only in emulator. I tried installing in real device but the app force closed.
Edited: problem solved. I installed the apk with different apk signer from previous apk that is already installed. so everything runs normally with codes above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.