Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的应用程序在点击几次图像后崩溃-为什么?_Java_Android_Android Fragments - Fatal编程技术网

Java 我的应用程序在点击几次图像后崩溃-为什么?

Java 我的应用程序在点击几次图像后崩溃-为什么?,java,android,android-fragments,Java,Android,Android Fragments,我正在制作一个应用程序,调用内置摄像头,以便单击图像并将其上载到Firebase Firestore。但在点击两个或更多快照后,应用程序正在崩溃。我正在使用一个名为MainActivity.java的导航抽屉,我有一个片段来提供一些按钮。在片段中有一个listview MainActivity.java TakeAttention.java TakeAttendanceCustomAdapter.java Logcat正在触发以下异常 Logcat 正在从TakeAttention.java调用

我正在制作一个应用程序,调用内置摄像头,以便单击图像并将其上载到Firebase Firestore。但在点击两个或更多快照后,应用程序正在崩溃。我正在使用一个名为MainActivity.java的导航抽屉,我有一个片段来提供一些按钮。在片段中有一个listview

MainActivity.java

TakeAttention.java

TakeAttendanceCustomAdapter.java

Logcat正在触发以下异常

Logcat

正在从TakeAttention.java调用camera intent来解决您的问题 在清单中,在应用程序标记下添加此行

android:largeHeap="true"

堆栈后跟踪无法再次生成相同的行为。它现在正在工作:|当我用数据线连接我的电脑时,该应用程序运行良好。当我断开它时,它崩溃了。真烦人。另外,当我与PC连接时,它工作正常,我无法发布堆栈跟踪。我发现了异常。我现在正在编辑这个问题,我想也许android的系统堆栈已经溢出了?但我不知道该怎么做。然而,我按照你的回答做了。它第一次坠毁了。但是现在它不再崩溃了。我认为这个问题现在已经解决了。它快把我逼疯了。谢谢你会知道最新情况吗。
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.
        */

}
    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(){


    }


}
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)
android:largeHeap="true"