不活动,断开与服务的连接

时间:2017-08-03 18:24:05

标签: android

我正在尝试访问firebase数据库并从内部类中向其推送一些值。但应用程序崩溃,我有“不活动”,与服务断开连接。我不知道为什么会这样。我是Firebase的新手。请帮我。 谢谢! 下面是我内部类的代码:

 public static class WH_total extends android.support.v4.app.Fragment {

    public WH_total() {

    }

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


        return inflater.inflate(R.layout.fragment_total, container, false);


    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        LinearLayout layout = (LinearLayout) getActivity().findViewById(R.id.total);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(40, 300, 0, 0);
        final Animation move = AnimationUtils.loadAnimation(getActivity(),
                R.anim.move);
        final Animation bounce = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce);

        TextView score = new TextView(getActivity());
        layout.addView(score);
        score.setVisibility(View.VISIBLE);
        score.startAnimation(move);
        score.setLayoutParams(params);
        score.setText("Your score is :");
        score.setTextSize(30);
        score.setTextColor(Color.parseColor("#000000"));

        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params1.setMargins(40, 0, 0, 0);

        TextView score_display = new TextView(getActivity());
        layout.addView(score_display);
        score_display.setVisibility(View.VISIBLE);
        score_display.startAnimation(move);
        score_display.setText(String.valueOf(total));
        score_display.setTextSize(20);
        score_display.setTextColor(Color.parseColor("#125688"));
        score_display.setLayoutParams(params1);

        LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params2.setMargins(40, 0, 0, 0);


        TextView right_one = new TextView(getActivity());
        layout.addView(right_one);
        right_one.setVisibility(View.VISIBLE);
        right_one.startAnimation(move);
        right_one.setText("Right answers:");
        right_one.setTextColor(Color.parseColor("#000000"));
        right_one.setTextSize(30);
        right_one.setLayoutParams(params2);

        LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params3.setMargins(40, 0, 0, 0);

        TextView right_answers = new TextView(getActivity());
        layout.addView(right_answers);
        right_answers.setLayoutParams(params3);
        right_answers.setText("Qno: ");
        right_answers.setTextColor(Color.parseColor("#8BC34A"));
        for (int j = 0; j < i; j++) {
            if (j == 0) {
                right_answers.append(String.valueOf(right[j]) + ", ");
            } else if (j > 0 && j < i - 1) {
                right_answers.append(String.valueOf(right[j]) + ",  ");
            } else {
                right_answers.append(String.valueOf(right[j]) + ".");
            }
        }

        right_answers.setTextSize(20);
        right_answers.setVisibility(View.VISIBLE);
        right_answers.startAnimation(move);


        LinearLayout.LayoutParams params4 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params4.setMargins(40, 0, 0, 0);

        TextView wrong_one = new TextView(getActivity());
        layout.addView(wrong_one);
        wrong_one.setVisibility(View.VISIBLE);
        wrong_one.setAnimation(move);
        wrong_one.setText("Wrong answers :");
        wrong_one.setTextColor(Color.parseColor("#000000"));
        wrong_one.setTextSize(30);
        wrong_one.setLayoutParams(params4);

        LinearLayout.LayoutParams params5 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params5.setMargins(40, 0, 0, 0);

        TextView wrong_answers = new TextView((getActivity()));
        layout.addView(wrong_answers);
        wrong_answers.setLayoutParams(params5);
        wrong_answers.setVisibility(View.VISIBLE);
        wrong_answers.setAnimation(move);
        wrong_answers.setText("Qno:");
        wrong_answers.setTextColor(Color.parseColor("#ff7f7f"));
        for (int i = 0; i < j; i++) {
            if (i == 0) {
                wrong_answers.append(String.valueOf(wrong[i]) + ", ");
            } else if (i > 0 && i < j - 1) {
                wrong_answers.append(String.valueOf(wrong[i]) + ", ");
            } else {
                wrong_answers.append(String.valueOf(wrong[j]) + ".");
            }

        }


        wrong_answers.setTextSize(20);
        report newReport = new report(total,right);
        mFirebaseDatabase = FirebaseDatabase.getInstance();
        mreference = mFirebaseDatabase.getReference().child("user").child("report");

        mreference.push().setValue(newReport);
    }
}

这是android监视器中的错误:

  

08-03 23:45:34.359 2102-32468 /? V / FA-SVC:记录事件:origin = auto,name = screen_view(_vs),params = Bundle [{firebase_event_origin(_o)= auto,firebase_previous_class(_pc)= WaterHardness,firebase_previous_id(_ pi)= - 6258030923168432617,firebase_screen_class(_sc )= WaterHardness_viva,firebase_screen_id(_si)= - 6258030923168432616}]   08-03 23:45:34.385 2102-32468 /? V / FA-SVC:保存事件,名称,数据大小:screen_view(_vs),104   08-03 23:45:34.385 2102-32468 /? V / FA-SVC:事件记录:事件{appId =&#39; com.example.india.chemistry&#39;,name =&#39; screen_view(_vs)&#39;,params = Bundle [{firebase_event_origin( _o)= auto,firebase_previous_class(_pc)= WaterHardness,firebase_previous_id(_ pi)= - 6258030923168432617,firebase_screen_class(_sc)= WaterHardness_viva,firebase_screen_id(_si)= - 6258030923168432616}]}   08-03 23:45:34.395 2102-32468 /? V / FA-SVC:上传时间大约为ms:2380804   08-03 23:45:34.415 2102-32468 /? V / FA-SVC:取消作业。 JobID:812057698   08-03 23:45:34.419 2102-32468 /? V / FA-SVC:使用AlarmManager计划上传   08-03 23:45:34.421 2102-32468 /? V / FA-SVC:后台事件处理时间,ms:63   08-03 23:45:39.370 32422-32453 / com.example.india.chemistry V / FA:不活动,断开与服务的连接

0 个答案:

没有答案