My app crashes after a few image clicks - why?












0















I am making an app that calls the builtin camera intent to click an image and to upload it to Firebase Firestore. But after clicking 2 or more shots, the app is crashing. I am using a navigation drawer called MainActivity.java and I have a fragment to Provide some buttons. In the fragment there is a listview.



MainActivity.java



public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,OnFragmentInteractionListener{

private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;
FirebaseFirestore db = FirebaseFirestore.getInstance();
@Override
public void onFragmentInteraction(Uri uri){

}
@Override
protected void onCreate(Bundle savedInstanceState) {
//uploadImage.doInBackground("ABCD");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(false);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();
mStorageRef = FirebaseStorage.getInstance().getReference();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

//FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

Fragment fragment = new TakeAttendance();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment = null;
Class fragmentClass;


int id = item.getItemId();

if (id == R.id.take_attendance) {
fragment = new TakeAttendance();
} else if (id == R.id.nav_gallery) {

} else if (id == R.id.nav_slideshow) {

} else if (id == R.id.nav_manage) {

} else if (id == R.id.account_settings) {
fragment = new AccountSettings();
} else if (id == R.id.logout) {
fragment = new TakeAttendance();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signOut();
Intent intent = new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
finish();
}

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode,data);
Log.d("myMSG","cammmeeee22");
if(requestCode == 100 && resultCode == RESULT_OK){
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
StorageReference ref = mStorageRef.child("taken_images/"+Globals.course_id+".jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
int qualityFactor=100;

byte uploadData = bytes.toByteArray();

uploadData = bytes.toByteArray();

String imageString = Base64.encodeToString(uploadData,Base64.DEFAULT);
Toast.makeText(MainActivity.this,"ASDF",Toast.LENGTH_SHORT).show();

}

}
}


TakeAttendance.java



public class TakeAttendance extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;
private ArrayList<Course> arr = new ArrayList<>();
private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;

private OnFragmentInteractionListener mListener;
private ListView listView;
private View inflatedView;
FirebaseFirestore db;
public TakeAttendance() {
// Required empty public constructor
}


public static TakeAttendance newInstance(String param1, String param2) {
TakeAttendance fragment = new TakeAttendance();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
private ArrayList<String> courseIds = new ArrayList<>();
private TakeAttendanceCustomAdapter adap;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

inflatedView = inflater.inflate(R.layout.fragment_take_attendance, container, false);
builder = new AlertDialog.Builder(getContext());
builder.setCancelable(false);
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();

listView = (ListView)inflatedView.findViewById(R.id.listView);
db = FirebaseFirestore.getInstance();
dialog.show();
Log.d("myMSG",getActivity().getIntent().getStringExtra("uid"));
db.collection("teacher_course").document(getActivity().getIntent().getStringExtra(Constants.uid_parameter)).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Log.d("myMSG","Success");
Map<String,Object> map = documentSnapshot.getData();
Log.d("myMSG",new Integer(map.size()).toString());
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Log.d("myMSG","entered");
Map.Entry pair = (Map.Entry)it.next();
Log.d("myMSG",pair.getKey().toString());
final String courseId = pair.getKey().toString();
db.collection("courses").document(courseId).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Map <String, Object> map = documentSnapshot.getData();
arr.add(new Course(map.get(Constants.course_name).toString(),map.get(Constants.course_number).toString(),courseId));
adap = new TakeAttendanceCustomAdapter(arr,getContext(),getActivity());

listView.setAdapter(adap);

}
}
);
it.remove();
}

dialog.hide();
Log.d("myMSG",new Integer(arr.size()).toString());




}
}
);







return inflatedView;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement com.example.redwanulsourav.attendance.OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/

}


TakeAttendanceCustomAdapter.java



    public class TakeAttendanceCustomAdapter extends ArrayAdapter<Course>{
private ArrayList<Course> dataSet;
Context mContext;
Activity mActivity;

public TakeAttendanceCustomAdapter(ArrayList < Course> data, Context context, Activity activity){
super(context,0,data);
this.dataSet = data;
this.mContext=context;
mActivity = activity;
}


@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent){
View listItem = convertView;
if(listItem == null){
listItem = LayoutInflater.from(mContext).inflate(R.layout.take_picture_list_single_element,parent,false);

}

final Course currentCourse = dataSet.get(position);

TextView tv = (TextView)listItem.findViewById(R.id.course_name);
tv.setText(currentCourse.getCourse_name());

tv = (TextView)listItem.findViewById(R.id.course_number);
tv.setText(currentCourse.getCourse_number());

Button btn = (Button)listItem.findViewById(R.id.take_picture_button);
Button btn2 = (Button)listItem.findViewById(R.id.browse);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(mActivity, new String { Manifest.permission.CAMERA }, 0);
}
else{
Log.d("Message","Already has permissions");
}
Globals.course_id = currentCourse.getCourse_id();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mActivity.startActivityForResult(intent, 100);
}
});

btn2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
mActivity.startActivityForResult(intent,200);
}
}
);
return listItem;

}
}

**Course.java**

package com.example.redwanulsourav.attendance;

public class Course {
public String getCourse_number() {
return course_number;
}

public void setCourse_number(String course_number) {
this.course_number = course_number;
}

public String getCourse_name() {
return course_name;
}

public void setCourse_name(String course_name) {
this.course_name = course_name;
}

private String course_number;
private String course_name;

public String getCourse_id() {
return course_id;
}

public void setCourse_id(String course_id) {
this.course_id = course_id;
}

private String course_id;

public Course(String _course_name, String _course_number, String _course_id){
this.course_name = _course_name;
this.course_number = _course_number;
this.course_id=_course_id;
}

public Course(){


}


}


Logcat is firing the following exceptions



Logcat



2018-11-24 21:02:16.833 1115-2308/? E/Watchdog: Failed to write to /sys/kernel/hungtask/vm_heart
java.io.FileNotFoundException: /sys/kernel/hungtask/vm_heart (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:287)
at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
at com.android.server.Watchdog.writeHungtask(Watchdog.java:790)
at com.android.server.Watchdog.run(Watchdog.java:542)


The camera intent is being called from TakeAttendance.java










share|improve this question

























  • Post the stack trace

    – Mike Speed
    Nov 24 '18 at 14:28











  • I cannot generate the same behavior again. It is working now :|

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:37











  • When I am connected with my PC with data cable, the app works finely. When I disconnect it, it crashes. Pretty annoying. Also, as it works perfectly when I am connected with PC, I cannot post the stack trace.

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:40











  • I found the exception. I am editing the question now

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:02
















0















I am making an app that calls the builtin camera intent to click an image and to upload it to Firebase Firestore. But after clicking 2 or more shots, the app is crashing. I am using a navigation drawer called MainActivity.java and I have a fragment to Provide some buttons. In the fragment there is a listview.



MainActivity.java



public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,OnFragmentInteractionListener{

private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;
FirebaseFirestore db = FirebaseFirestore.getInstance();
@Override
public void onFragmentInteraction(Uri uri){

}
@Override
protected void onCreate(Bundle savedInstanceState) {
//uploadImage.doInBackground("ABCD");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(false);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();
mStorageRef = FirebaseStorage.getInstance().getReference();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

//FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

Fragment fragment = new TakeAttendance();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment = null;
Class fragmentClass;


int id = item.getItemId();

if (id == R.id.take_attendance) {
fragment = new TakeAttendance();
} else if (id == R.id.nav_gallery) {

} else if (id == R.id.nav_slideshow) {

} else if (id == R.id.nav_manage) {

} else if (id == R.id.account_settings) {
fragment = new AccountSettings();
} else if (id == R.id.logout) {
fragment = new TakeAttendance();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signOut();
Intent intent = new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
finish();
}

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode,data);
Log.d("myMSG","cammmeeee22");
if(requestCode == 100 && resultCode == RESULT_OK){
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
StorageReference ref = mStorageRef.child("taken_images/"+Globals.course_id+".jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
int qualityFactor=100;

byte uploadData = bytes.toByteArray();

uploadData = bytes.toByteArray();

String imageString = Base64.encodeToString(uploadData,Base64.DEFAULT);
Toast.makeText(MainActivity.this,"ASDF",Toast.LENGTH_SHORT).show();

}

}
}


TakeAttendance.java



public class TakeAttendance extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;
private ArrayList<Course> arr = new ArrayList<>();
private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;

private OnFragmentInteractionListener mListener;
private ListView listView;
private View inflatedView;
FirebaseFirestore db;
public TakeAttendance() {
// Required empty public constructor
}


public static TakeAttendance newInstance(String param1, String param2) {
TakeAttendance fragment = new TakeAttendance();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
private ArrayList<String> courseIds = new ArrayList<>();
private TakeAttendanceCustomAdapter adap;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

inflatedView = inflater.inflate(R.layout.fragment_take_attendance, container, false);
builder = new AlertDialog.Builder(getContext());
builder.setCancelable(false);
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();

listView = (ListView)inflatedView.findViewById(R.id.listView);
db = FirebaseFirestore.getInstance();
dialog.show();
Log.d("myMSG",getActivity().getIntent().getStringExtra("uid"));
db.collection("teacher_course").document(getActivity().getIntent().getStringExtra(Constants.uid_parameter)).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Log.d("myMSG","Success");
Map<String,Object> map = documentSnapshot.getData();
Log.d("myMSG",new Integer(map.size()).toString());
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Log.d("myMSG","entered");
Map.Entry pair = (Map.Entry)it.next();
Log.d("myMSG",pair.getKey().toString());
final String courseId = pair.getKey().toString();
db.collection("courses").document(courseId).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Map <String, Object> map = documentSnapshot.getData();
arr.add(new Course(map.get(Constants.course_name).toString(),map.get(Constants.course_number).toString(),courseId));
adap = new TakeAttendanceCustomAdapter(arr,getContext(),getActivity());

listView.setAdapter(adap);

}
}
);
it.remove();
}

dialog.hide();
Log.d("myMSG",new Integer(arr.size()).toString());




}
}
);







return inflatedView;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement com.example.redwanulsourav.attendance.OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/

}


TakeAttendanceCustomAdapter.java



    public class TakeAttendanceCustomAdapter extends ArrayAdapter<Course>{
private ArrayList<Course> dataSet;
Context mContext;
Activity mActivity;

public TakeAttendanceCustomAdapter(ArrayList < Course> data, Context context, Activity activity){
super(context,0,data);
this.dataSet = data;
this.mContext=context;
mActivity = activity;
}


@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent){
View listItem = convertView;
if(listItem == null){
listItem = LayoutInflater.from(mContext).inflate(R.layout.take_picture_list_single_element,parent,false);

}

final Course currentCourse = dataSet.get(position);

TextView tv = (TextView)listItem.findViewById(R.id.course_name);
tv.setText(currentCourse.getCourse_name());

tv = (TextView)listItem.findViewById(R.id.course_number);
tv.setText(currentCourse.getCourse_number());

Button btn = (Button)listItem.findViewById(R.id.take_picture_button);
Button btn2 = (Button)listItem.findViewById(R.id.browse);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(mActivity, new String { Manifest.permission.CAMERA }, 0);
}
else{
Log.d("Message","Already has permissions");
}
Globals.course_id = currentCourse.getCourse_id();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mActivity.startActivityForResult(intent, 100);
}
});

btn2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
mActivity.startActivityForResult(intent,200);
}
}
);
return listItem;

}
}

**Course.java**

package com.example.redwanulsourav.attendance;

public class Course {
public String getCourse_number() {
return course_number;
}

public void setCourse_number(String course_number) {
this.course_number = course_number;
}

public String getCourse_name() {
return course_name;
}

public void setCourse_name(String course_name) {
this.course_name = course_name;
}

private String course_number;
private String course_name;

public String getCourse_id() {
return course_id;
}

public void setCourse_id(String course_id) {
this.course_id = course_id;
}

private String course_id;

public Course(String _course_name, String _course_number, String _course_id){
this.course_name = _course_name;
this.course_number = _course_number;
this.course_id=_course_id;
}

public Course(){


}


}


Logcat is firing the following exceptions



Logcat



2018-11-24 21:02:16.833 1115-2308/? E/Watchdog: Failed to write to /sys/kernel/hungtask/vm_heart
java.io.FileNotFoundException: /sys/kernel/hungtask/vm_heart (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:287)
at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
at com.android.server.Watchdog.writeHungtask(Watchdog.java:790)
at com.android.server.Watchdog.run(Watchdog.java:542)


The camera intent is being called from TakeAttendance.java










share|improve this question

























  • Post the stack trace

    – Mike Speed
    Nov 24 '18 at 14:28











  • I cannot generate the same behavior again. It is working now :|

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:37











  • When I am connected with my PC with data cable, the app works finely. When I disconnect it, it crashes. Pretty annoying. Also, as it works perfectly when I am connected with PC, I cannot post the stack trace.

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:40











  • I found the exception. I am editing the question now

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:02














0












0








0








I am making an app that calls the builtin camera intent to click an image and to upload it to Firebase Firestore. But after clicking 2 or more shots, the app is crashing. I am using a navigation drawer called MainActivity.java and I have a fragment to Provide some buttons. In the fragment there is a listview.



MainActivity.java



public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,OnFragmentInteractionListener{

private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;
FirebaseFirestore db = FirebaseFirestore.getInstance();
@Override
public void onFragmentInteraction(Uri uri){

}
@Override
protected void onCreate(Bundle savedInstanceState) {
//uploadImage.doInBackground("ABCD");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(false);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();
mStorageRef = FirebaseStorage.getInstance().getReference();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

//FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

Fragment fragment = new TakeAttendance();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment = null;
Class fragmentClass;


int id = item.getItemId();

if (id == R.id.take_attendance) {
fragment = new TakeAttendance();
} else if (id == R.id.nav_gallery) {

} else if (id == R.id.nav_slideshow) {

} else if (id == R.id.nav_manage) {

} else if (id == R.id.account_settings) {
fragment = new AccountSettings();
} else if (id == R.id.logout) {
fragment = new TakeAttendance();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signOut();
Intent intent = new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
finish();
}

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode,data);
Log.d("myMSG","cammmeeee22");
if(requestCode == 100 && resultCode == RESULT_OK){
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
StorageReference ref = mStorageRef.child("taken_images/"+Globals.course_id+".jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
int qualityFactor=100;

byte uploadData = bytes.toByteArray();

uploadData = bytes.toByteArray();

String imageString = Base64.encodeToString(uploadData,Base64.DEFAULT);
Toast.makeText(MainActivity.this,"ASDF",Toast.LENGTH_SHORT).show();

}

}
}


TakeAttendance.java



public class TakeAttendance extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;
private ArrayList<Course> arr = new ArrayList<>();
private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;

private OnFragmentInteractionListener mListener;
private ListView listView;
private View inflatedView;
FirebaseFirestore db;
public TakeAttendance() {
// Required empty public constructor
}


public static TakeAttendance newInstance(String param1, String param2) {
TakeAttendance fragment = new TakeAttendance();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
private ArrayList<String> courseIds = new ArrayList<>();
private TakeAttendanceCustomAdapter adap;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

inflatedView = inflater.inflate(R.layout.fragment_take_attendance, container, false);
builder = new AlertDialog.Builder(getContext());
builder.setCancelable(false);
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();

listView = (ListView)inflatedView.findViewById(R.id.listView);
db = FirebaseFirestore.getInstance();
dialog.show();
Log.d("myMSG",getActivity().getIntent().getStringExtra("uid"));
db.collection("teacher_course").document(getActivity().getIntent().getStringExtra(Constants.uid_parameter)).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Log.d("myMSG","Success");
Map<String,Object> map = documentSnapshot.getData();
Log.d("myMSG",new Integer(map.size()).toString());
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Log.d("myMSG","entered");
Map.Entry pair = (Map.Entry)it.next();
Log.d("myMSG",pair.getKey().toString());
final String courseId = pair.getKey().toString();
db.collection("courses").document(courseId).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Map <String, Object> map = documentSnapshot.getData();
arr.add(new Course(map.get(Constants.course_name).toString(),map.get(Constants.course_number).toString(),courseId));
adap = new TakeAttendanceCustomAdapter(arr,getContext(),getActivity());

listView.setAdapter(adap);

}
}
);
it.remove();
}

dialog.hide();
Log.d("myMSG",new Integer(arr.size()).toString());




}
}
);







return inflatedView;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement com.example.redwanulsourav.attendance.OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/

}


TakeAttendanceCustomAdapter.java



    public class TakeAttendanceCustomAdapter extends ArrayAdapter<Course>{
private ArrayList<Course> dataSet;
Context mContext;
Activity mActivity;

public TakeAttendanceCustomAdapter(ArrayList < Course> data, Context context, Activity activity){
super(context,0,data);
this.dataSet = data;
this.mContext=context;
mActivity = activity;
}


@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent){
View listItem = convertView;
if(listItem == null){
listItem = LayoutInflater.from(mContext).inflate(R.layout.take_picture_list_single_element,parent,false);

}

final Course currentCourse = dataSet.get(position);

TextView tv = (TextView)listItem.findViewById(R.id.course_name);
tv.setText(currentCourse.getCourse_name());

tv = (TextView)listItem.findViewById(R.id.course_number);
tv.setText(currentCourse.getCourse_number());

Button btn = (Button)listItem.findViewById(R.id.take_picture_button);
Button btn2 = (Button)listItem.findViewById(R.id.browse);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(mActivity, new String { Manifest.permission.CAMERA }, 0);
}
else{
Log.d("Message","Already has permissions");
}
Globals.course_id = currentCourse.getCourse_id();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mActivity.startActivityForResult(intent, 100);
}
});

btn2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
mActivity.startActivityForResult(intent,200);
}
}
);
return listItem;

}
}

**Course.java**

package com.example.redwanulsourav.attendance;

public class Course {
public String getCourse_number() {
return course_number;
}

public void setCourse_number(String course_number) {
this.course_number = course_number;
}

public String getCourse_name() {
return course_name;
}

public void setCourse_name(String course_name) {
this.course_name = course_name;
}

private String course_number;
private String course_name;

public String getCourse_id() {
return course_id;
}

public void setCourse_id(String course_id) {
this.course_id = course_id;
}

private String course_id;

public Course(String _course_name, String _course_number, String _course_id){
this.course_name = _course_name;
this.course_number = _course_number;
this.course_id=_course_id;
}

public Course(){


}


}


Logcat is firing the following exceptions



Logcat



2018-11-24 21:02:16.833 1115-2308/? E/Watchdog: Failed to write to /sys/kernel/hungtask/vm_heart
java.io.FileNotFoundException: /sys/kernel/hungtask/vm_heart (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:287)
at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
at com.android.server.Watchdog.writeHungtask(Watchdog.java:790)
at com.android.server.Watchdog.run(Watchdog.java:542)


The camera intent is being called from TakeAttendance.java










share|improve this question
















I am making an app that calls the builtin camera intent to click an image and to upload it to Firebase Firestore. But after clicking 2 or more shots, the app is crashing. I am using a navigation drawer called MainActivity.java and I have a fragment to Provide some buttons. In the fragment there is a listview.



MainActivity.java



public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,OnFragmentInteractionListener{

private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;
FirebaseFirestore db = FirebaseFirestore.getInstance();
@Override
public void onFragmentInteraction(Uri uri){

}
@Override
protected void onCreate(Bundle savedInstanceState) {
//uploadImage.doInBackground("ABCD");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
builder = new AlertDialog.Builder(MainActivity.this);
builder.setCancelable(false);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();
mStorageRef = FirebaseStorage.getInstance().getReference();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

//FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

Fragment fragment = new TakeAttendance();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment = null;
Class fragmentClass;


int id = item.getItemId();

if (id == R.id.take_attendance) {
fragment = new TakeAttendance();
} else if (id == R.id.nav_gallery) {

} else if (id == R.id.nav_slideshow) {

} else if (id == R.id.nav_manage) {

} else if (id == R.id.account_settings) {
fragment = new AccountSettings();
} else if (id == R.id.logout) {
fragment = new TakeAttendance();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signOut();
Intent intent = new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
finish();
}

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content,fragment).commit();


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode,data);
Log.d("myMSG","cammmeeee22");
if(requestCode == 100 && resultCode == RESULT_OK){
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
StorageReference ref = mStorageRef.child("taken_images/"+Globals.course_id+".jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
int qualityFactor=100;

byte uploadData = bytes.toByteArray();

uploadData = bytes.toByteArray();

String imageString = Base64.encodeToString(uploadData,Base64.DEFAULT);
Toast.makeText(MainActivity.this,"ASDF",Toast.LENGTH_SHORT).show();

}

}
}


TakeAttendance.java



public class TakeAttendance extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

private String mParam1;
private String mParam2;
private ArrayList<Course> arr = new ArrayList<>();
private StorageReference mStorageRef;
AlertDialog.Builder builder;
LayoutInflater inflater;
View vv;

private AlertDialog dialog;

private OnFragmentInteractionListener mListener;
private ListView listView;
private View inflatedView;
FirebaseFirestore db;
public TakeAttendance() {
// Required empty public constructor
}


public static TakeAttendance newInstance(String param1, String param2) {
TakeAttendance fragment = new TakeAttendance();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
private ArrayList<String> courseIds = new ArrayList<>();
private TakeAttendanceCustomAdapter adap;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

inflatedView = inflater.inflate(R.layout.fragment_take_attendance, container, false);
builder = new AlertDialog.Builder(getContext());
builder.setCancelable(false);
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vv = inflater.inflate(R.layout.layout_logging_in_dialog,null);
builder.setView(vv);
dialog = builder.create();

listView = (ListView)inflatedView.findViewById(R.id.listView);
db = FirebaseFirestore.getInstance();
dialog.show();
Log.d("myMSG",getActivity().getIntent().getStringExtra("uid"));
db.collection("teacher_course").document(getActivity().getIntent().getStringExtra(Constants.uid_parameter)).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Log.d("myMSG","Success");
Map<String,Object> map = documentSnapshot.getData();
Log.d("myMSG",new Integer(map.size()).toString());
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Log.d("myMSG","entered");
Map.Entry pair = (Map.Entry)it.next();
Log.d("myMSG",pair.getKey().toString());
final String courseId = pair.getKey().toString();
db.collection("courses").document(courseId).get().addOnSuccessListener(
new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
Map <String, Object> map = documentSnapshot.getData();
arr.add(new Course(map.get(Constants.course_name).toString(),map.get(Constants.course_number).toString(),courseId));
adap = new TakeAttendanceCustomAdapter(arr,getContext(),getActivity());

listView.setAdapter(adap);

}
}
);
it.remove();
}

dialog.hide();
Log.d("myMSG",new Integer(arr.size()).toString());




}
}
);







return inflatedView;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement com.example.redwanulsourav.attendance.OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/

}


TakeAttendanceCustomAdapter.java



    public class TakeAttendanceCustomAdapter extends ArrayAdapter<Course>{
private ArrayList<Course> dataSet;
Context mContext;
Activity mActivity;

public TakeAttendanceCustomAdapter(ArrayList < Course> data, Context context, Activity activity){
super(context,0,data);
this.dataSet = data;
this.mContext=context;
mActivity = activity;
}


@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent){
View listItem = convertView;
if(listItem == null){
listItem = LayoutInflater.from(mContext).inflate(R.layout.take_picture_list_single_element,parent,false);

}

final Course currentCourse = dataSet.get(position);

TextView tv = (TextView)listItem.findViewById(R.id.course_name);
tv.setText(currentCourse.getCourse_name());

tv = (TextView)listItem.findViewById(R.id.course_number);
tv.setText(currentCourse.getCourse_number());

Button btn = (Button)listItem.findViewById(R.id.take_picture_button);
Button btn2 = (Button)listItem.findViewById(R.id.browse);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(mActivity, new String { Manifest.permission.CAMERA }, 0);
}
else{
Log.d("Message","Already has permissions");
}
Globals.course_id = currentCourse.getCourse_id();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mActivity.startActivityForResult(intent, 100);
}
});

btn2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
mActivity.startActivityForResult(intent,200);
}
}
);
return listItem;

}
}

**Course.java**

package com.example.redwanulsourav.attendance;

public class Course {
public String getCourse_number() {
return course_number;
}

public void setCourse_number(String course_number) {
this.course_number = course_number;
}

public String getCourse_name() {
return course_name;
}

public void setCourse_name(String course_name) {
this.course_name = course_name;
}

private String course_number;
private String course_name;

public String getCourse_id() {
return course_id;
}

public void setCourse_id(String course_id) {
this.course_id = course_id;
}

private String course_id;

public Course(String _course_name, String _course_number, String _course_id){
this.course_name = _course_name;
this.course_number = _course_number;
this.course_id=_course_id;
}

public Course(){


}


}


Logcat is firing the following exceptions



Logcat



2018-11-24 21:02:16.833 1115-2308/? E/Watchdog: Failed to write to /sys/kernel/hungtask/vm_heart
java.io.FileNotFoundException: /sys/kernel/hungtask/vm_heart (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:287)
at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
at com.android.server.Watchdog.writeHungtask(Watchdog.java:790)
at com.android.server.Watchdog.run(Watchdog.java:542)


The camera intent is being called from TakeAttendance.java







java android android-fragments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 16:42









Fantômas

32.4k156388




32.4k156388










asked Nov 24 '18 at 14:17









Redwanul Haque SouraveRedwanul Haque Sourave

30019




30019













  • Post the stack trace

    – Mike Speed
    Nov 24 '18 at 14:28











  • I cannot generate the same behavior again. It is working now :|

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:37











  • When I am connected with my PC with data cable, the app works finely. When I disconnect it, it crashes. Pretty annoying. Also, as it works perfectly when I am connected with PC, I cannot post the stack trace.

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:40











  • I found the exception. I am editing the question now

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:02



















  • Post the stack trace

    – Mike Speed
    Nov 24 '18 at 14:28











  • I cannot generate the same behavior again. It is working now :|

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:37











  • When I am connected with my PC with data cable, the app works finely. When I disconnect it, it crashes. Pretty annoying. Also, as it works perfectly when I am connected with PC, I cannot post the stack trace.

    – Redwanul Haque Sourave
    Nov 24 '18 at 14:40











  • I found the exception. I am editing the question now

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:02

















Post the stack trace

– Mike Speed
Nov 24 '18 at 14:28





Post the stack trace

– Mike Speed
Nov 24 '18 at 14:28













I cannot generate the same behavior again. It is working now :|

– Redwanul Haque Sourave
Nov 24 '18 at 14:37





I cannot generate the same behavior again. It is working now :|

– Redwanul Haque Sourave
Nov 24 '18 at 14:37













When I am connected with my PC with data cable, the app works finely. When I disconnect it, it crashes. Pretty annoying. Also, as it works perfectly when I am connected with PC, I cannot post the stack trace.

– Redwanul Haque Sourave
Nov 24 '18 at 14:40





When I am connected with my PC with data cable, the app works finely. When I disconnect it, it crashes. Pretty annoying. Also, as it works perfectly when I am connected with PC, I cannot post the stack trace.

– Redwanul Haque Sourave
Nov 24 '18 at 14:40













I found the exception. I am editing the question now

– Redwanul Haque Sourave
Nov 24 '18 at 15:02





I found the exception. I am editing the question now

– Redwanul Haque Sourave
Nov 24 '18 at 15:02












1 Answer
1






active

oldest

votes


















1














To solve your problem
In manifest add this line under application tag.



android:largeHeap="true"





share|improve this answer


























  • I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:08











  • I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459069%2fmy-app-crashes-after-a-few-image-clicks-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














To solve your problem
In manifest add this line under application tag.



android:largeHeap="true"





share|improve this answer


























  • I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:08











  • I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:09
















1














To solve your problem
In manifest add this line under application tag.



android:largeHeap="true"





share|improve this answer


























  • I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:08











  • I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:09














1












1








1







To solve your problem
In manifest add this line under application tag.



android:largeHeap="true"





share|improve this answer















To solve your problem
In manifest add this line under application tag.



android:largeHeap="true"






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 15:23









Lekr0

334110




334110










answered Nov 24 '18 at 14:59









Jawad AhmedJawad Ahmed

796




796













  • I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:08











  • I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:09



















  • I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:08











  • I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

    – Redwanul Haque Sourave
    Nov 24 '18 at 15:09

















I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

– Redwanul Haque Sourave
Nov 24 '18 at 15:08





I was thinking like maybe the android's system stack was getting overflowed? But I did not know how to do that. However, I followed your answer and did that. It crashed for the first time. But now it is not crashing any more.

– Redwanul Haque Sourave
Nov 24 '18 at 15:08













I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

– Redwanul Haque Sourave
Nov 24 '18 at 15:09





I think the issue is fixed for now. It was driving me crazy. Thanks. Will late you know the update.

– Redwanul Haque Sourave
Nov 24 '18 at 15:09


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459069%2fmy-app-crashes-after-a-few-image-clicks-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks