Firebase数据上传导致Android应用程序崩溃
我正在收集信号数据并将其上传到数据库 我有几个函数,在尝试实现其余函数之前做了一些测试。当我上传我想要使用的类,但不上传测试用例时,它崩溃了 以下是类、方法和初始化的代码: 初始化数据库Firebase数据上传导致Android应用程序崩溃,android,firebase,firebase-realtime-database,telephonymanager,Android,Firebase,Firebase Realtime Database,Telephonymanager,我正在收集信号数据并将其上传到数据库 我有几个函数,在尝试实现其余函数之前做了一些测试。当我上传我想要使用的类,但不上传测试用例时,它崩溃了 以下是类、方法和初始化的代码: 初始化数据库 FirebaseDatabase database; DatabaseReference myRef; 课程: package com.example.mike.maps_example; /** * Created by Mike on 3/10/2017. */ public class Wcdm
FirebaseDatabase database;
DatabaseReference myRef;
课程:
package com.example.mike.maps_example;
/**
* Created by Mike on 3/10/2017.
*/
public class WcdmaSignalEntry {
Double Latitude, Longitude;
String dBm;
String Cid;
String Lac;
String Mcc;
String Mnc;
String Psc;
String Uarfcn;
String connectionType = "WCDMA";
public WcdmaSignalEntry(){
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public WcdmaSignalEntry(double Latitude, double Longitude, String dBm, String Cid, String Lac, String Mcc, String Mnc, String Psc, String Uarfcn){
this.Latitude = Latitude;
this.Longitude = Longitude;
this.dBm = dBm;
this.Cid = Cid;
this.Lac = Lac;
this.Mcc = Mcc;
this.Mnc = Mnc;
this.Psc = Psc;
this.Uarfcn = Uarfcn;
}
}
以下是测试类的代码:
package com.example.mike.maps_example;
/**
* Created by Mike on 28/9/2017.
*/
public class CellSignalEntry {
public double Latitude;
public double Longitude;
public String dBm;
public String CI; //cell identity
public String LAC; //Location Area Code
public String PSC; //primary scrambling code
public String TA; //timing advance
public String PCI_LTE; //physical cell identifier for LTE
public String PCI_GSM; //physical cell identifier for GSM
public CellSignalEntry() {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public CellSignalEntry(String dBm, String CI, String LAC, String PSC, String TA, String PCI_LTE, String PCI_GSM, double Latitude, double Longitude) {
this.dBm = dBm;
this.CI = CI;
this.LAC = LAC;
this.PSC = PSC;
this.TA = TA;
this.PCI_GSM = PCI_GSM;
this.PCI_LTE = PCI_LTE;
this.Latitude = Latitude;
this.Longitude = Longitude;
}
}
我有两种方法
private void writeNewWcdmaEntry(double lon, double lat, String dBm, String Cid, String Lac, String Mcc, String Mnc,String Psc, String Uarfcn, long entry){
WcdmaSignalEntry newEntry = new WcdmaSignalEntry(lon, lat, dBm, Cid, Lac, Mcc, Mnc, Psc, Uarfcn);
tvView.setText(newEntry.dBm);
tvView.setText(newEntry.Cid);
//myRef.child("Entry").child(Long.toString(entry)).setValue(newEntry);
}
及
当我运行第二个方法时,我的应用程序运行良好,但当我运行第一个方法时,如果我取消注释此行,则在将数据上载到firebase数据库时,它会崩溃:
//myRef.child("Entry").child(Long.toString(entry)).setValue(newEntry);
我完全被难住了。非常感谢您的帮助
编辑:在发布这篇文章之后,我就明白了。我不知道为什么,但将WcdmaSignalEntry类中的所有变量都设置为“public”解决了这个问题,但我不确定为什么,我对java非常陌生,因此最好给出一个解释:) Java说:
如果一个类没有修饰符(默认值,也称为包私有),那么它只在它自己的包中可见
如果这两个方法(来自您的问题)不在类WcdmaSignalEntry
所在的同一个包内,即com.example.mike.maps\u example
内,则您无法访问这些变量,除非它们是公共的
有关java中访问修饰符的更多信息,请参阅。这两种方法在同一个包中的何处?
//myRef.child("Entry").child(Long.toString(entry)).setValue(newEntry);