Firebase错误无法进入数据库

时间:2017-05-22 06:37:12

标签: android firebase firebase-realtime-database

//error here
private FirebaseDatabase database = FirebaseDatabase.getInstance();
private DatabaseReference myRef = database.getReference("Runtime");

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ping);

    btn1 = (Button) findViewById(R.id.ping);
    lstPing = (ListView) findViewById(R.id.listPing);
    editText = (EditText) findViewById(R.id.edit_query);

    // Write a message to the database

}

public void fExecutePing (View view) {

    Editable host = editText.getText();
    List<String> listResponsPing = new ArrayList<String>();
    ArrayAdapter<String> adapterList = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listResponsPing);

    try {

        String cmdPing = "ping -c 2 "+host;
        Runtime r = Runtime.getRuntime();
        Process p = r.exec(cmdPing);
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String inputLine;
        String time_part = "";
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        while ((inputLine = in.readLine())!= null){
            for(String time:listResponsPing){
                if(time.contains("time=")){
                    String[] parts = time.split("time\\=");
                    time_part = parts[1];
                    myRef.push().setValue(time_part + " " + dateFormat.format(date));
                }
            }
            listResponsPing.add(inputLine);
            lstPing.setAdapter(adapterList);

        }

        Toast.makeText(this, " Command Execute Success", Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        Toast.makeText(this, " Error: "+e.getMessage().toString(),        Toast.LENGTH_SHORT).show();


    }

}

}

我是firebase和android的新手。我的应用程序是关于网络测试。我的PingActivity有问题。我无法将ping活动的结果插入Firebase。我已经尝试了我找到的所有解决方案。但它不起作用。请帮忙。谢谢。 我评论的代码中的错误。

0 个答案:

没有答案