I have been programming Java for the past two months, but I am an experienced programmer in python and C. I know that I am making mistakes because of this.
I come to this question to clear the warnings of my project in android studio.
I use the Singleton class with inner classes to keep all my configuration settings in one place and allow all other classes to access it with the need to pass the configuration.
Here is the base code of my Singleton
public class syscfg {
public List<CommData> Commlist;
public static CommConfigIP4 MyCommConfig;
private static syscfg instance = null;
private static boolean ConfigStat = false;
protected syscfg(){
if(ConfigStat == false){
Log.i("SD_app_log", "SYSCFG: Module Initialization");
ConfigStat = true;
MyCommConfig = new CommConfigIP4();
init_config();
}else{
Log.i("SD_app_log", "SYSCFG: Module Loaded");
}
}
public static syscfg getInstance(){
if(instance == null){
instance = new syscfg();
}
return instance;
}
public class CommConfigIP4{
public int discoveryPort = 30303;
public byte[] MyMAC;
public String MyType = "";
public String MyIP;
public byte[] getIPbytearray(){
try{
byte[] IPout = (InetAddress.getByName(MyIP)).getAddress();
return IPout;
}catch (Exception e){
return null;
}
}
In my java file / class post I have:
public class Communications {
private syscfg CFid ;
...
public Communications(Context ctx){
...
CFid = syscfg.getInstance();
init_comms();
}
private void whoami (){
...
CFid.MyCommConfig.MyType = netint.getName();
...
}
}
, (, ) syscfg, Android , . , . nullpointexception
CFid.MyCommConfig.MyType = netint.getName();
, CFid.MyCommConfig = null
singleton, syscfg , .
- , CommConfigIP4 static, , :
syscfg.MyCommConfig.MyType = netint.getName();
.
? ?
,