Java 如何从公共类调用私有类
我有以下私人课程:Java 如何从公共类调用私有类,java,android,Java,Android,我有以下私人课程: 我该怎么做呢?你呼叫的班级是否公开并不重要。 如果sendReportePeriodico类不在另一个类中,则无法调用它 私有类是无用的,除非它们位于另一个类中。在这种情况下,它被称为内部类 即使是反射也不起作用,因为私有类使用反射将outter类的实例作为参数 解决方案是将类sendReportePeriodico设置为公共的或受保护的,或将类移动到要从中调用它的类中。私有类和方法是否在同一个类中?如果不是,那么就不能这样做。Java中允许顶级私有类吗? private c
我该怎么做呢?你呼叫的班级是否公开并不重要。 如果sendReportePeriodico类不在另一个类中,则无法调用它 私有类是无用的,除非它们位于另一个类中。在这种情况下,它被称为内部类 即使是反射也不起作用,因为私有类使用反射将outter类的实例作为参数
解决方案是将类sendReportePeriodico设置为公共的或受保护的,或将类移动到要从中调用它的类中。私有类和方法是否在同一个类中?如果不是,那么就不能这样做。Java中允许顶级私有类吗?
private class sendReportePeriodico extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
socket = null;
SocketAddress address = new InetSocketAddress(server_address, server_port);
socket = new Socket();
try {
socket.connect(address, 3000);
} catch (IOException e) {
e.printStackTrace();
}
try {
socket.setSoTimeout(3000);
} catch (SocketException e) {
e.printStackTrace();
return "Can't Connect";
}
OutputStream out = null;
try {
out = socket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
PrintWriter output = new PrintWriter(out);
output.print(texto);
output.flush();
return null;
}
}
public void onLocationChanged(Location location) {
Log.d("LogXXX","Visualizando gps");
texto = "GPS: " + location.getLatitude() + ", " + location.getLongitude();
tvMensaje.setText(texto);
mapa(location.getLatitude(), location.getLongitude());
new sendReportePeriodico();
HERE I NEED TO CALL THE PRIVATE CLASS;
}