I develop a camera android application, it works correct but when I run it in android 7, it creates a message which says "The app has stopped"! I think the problem is from this file of my code, it's my gallery file:
public class Gallery extends Activity {
GridView gv;
ArrayList<File> list;
Context context;
private static VirtualFileSystem vfs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery2);
File f = new File("/myfiles.db");
list = imageReader(f);
gv = (GridView) findViewById(R.id.gridview);
gv.setAdapter(new GridAdapter());
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(getApplicationContext(), viewImage.class).putExtra("img", list.get(position).toString()));
}
});
}
class GridAdapter extends BaseAdapter {
public ImageView iv;
public Bitmap bmp = null;
public File file ;
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
class ViewHolder {
ImageView icon;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Log.e("sara" , "this part takes time");
LayoutInflater inflater = getLayoutInflater();
getLayoutInflater().inflate(R.layout.gallery_gridsq, parent, false);
convertView = getLayoutInflater().inflate(R.layout.gallery_gridsq, parent, false);
iv = (ImageView) convertView.findViewById(R.id.icon);
file = new File(Uri.parse(getItem(position).toString()).getPath());
new myTask(iv, file).execute();
return convertView;
}
private class myTask extends AsyncTask <Void , Void ,Bitmap> {
ImageView iv;
File file;
public myTask(ImageView iv, File file) {
this.iv=iv;
this.file= file;
}
@Override
protected Bitmap doInBackground(Void... params) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(new FileInputStream(file), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
options.inJustDecodeBounds = false;
options.inSampleSize = 2;
try {
bmp = BitmapFactory.decodeStream(new FileInputStream(file), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return bmp;
}
@Override
protected void onPostExecute(Bitmap aVoid) {
iv.setImageBitmap(aVoid);
}
}
}
ArrayList<File> imageReader ( File root) {
final ArrayList<File> a = new ArrayList<>();
File[] files = root.listFiles();
for (int i = files.length - 1; i >= 0; i--) {
if (files[i].isDirectory()) {
// input name directory to array list
a.addAll(imageReader(files[i]));
} else {
if (files[i].getName().endsWith(".jpg")) {
a.add(files[i]);
}
}
}
return a;
}
In that link it uses "getUriForFile" but I think it cannot help me in this case! Here is my logcat:
08-07 02:10:21.757 2343-2343/? E/memtrack: Couldn't load memtrack module (No such file or directory) 08-07 02:10:21.757 2343-2343/? E/android.os.Debug: failed to load memtrack module: -2 08-07 02:10:21.913 2349-2349/? E/memtrack: Couldn't load memtrack module (No such file or directory) 08-07 02:10:21.913 2349-2349/? E/android.os.Debug: failed to load memtrack module: -2 08-07 02:10:22.220 2370-2370/? E/cutils-trace: Error opening trace file: Permission denied (13) 08-07 02:10:23.334 2390-2390/? E/memtrack: Couldn't load memtrack module (No such file or directory) 08-07 02:10:23.334 2390-2390/? E/android.os.Debug: failed to load memtrack module: -2 08-07 02:10:23.708 2399-2415/? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found 08-07 02:10:23.802 2399-2399/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.zeinab.amndoorbin, PID: 2399 java.lang.NullPointerException: cancel() called with a null PendingIntent at android.app.AlarmManager.cancel(AlarmManager.java:890) at info.guardianproject.cacheword.CacheWordService.resetTimeout(CacheWordService.java:189) at info.guardianproject.cacheword.CacheWordService.attachSubscriber(CacheWordService.java:145) at info.guardianproject.cacheword.CacheWordHandler$2.onServiceConnected(CacheWordHandler.java:457) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1453) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1481) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 08-07 02:10:25.520 2399-2415/? E/EGL_emulation: tid 2415: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH) 08-07 02:10:25.612 706-1732/? E/EGL_emulation: tid 1732: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)