Answer the question
In order to leave comments, you need to log in
How to use InetAddress class in AndroidStudio?
I want to write a class that will send some data to the server.
I use the tutorial
But android studio does not allow to create class InetAddress, signaling
InetAddress () is not public in "Java.net.InetAddress". Cannot accessed from outside package.
The code:
import android.widget.TextView;
import java.io.IOException;
import java.net.InetAddress;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
public class Client {
private InetAddress inetAddress = null;
private SocketChannel socketChannel = null;
private ByteBuffer byteBuffer = null;
private TextView text = null;
public Client (String Ip, int Port, final TextView text) throws IOException {
this.text = text;
inetAddress = new InetAddress(Ip, Port);
}
private void Log (final String log){
StringBuilder message = new StringBuilder ();
message.append("System log: ");
message.append(log);
text.setText(message.toString());
}
}
Answer the question
In order to leave comments, you need to log in
It's strange, you talk about creating a class, but you indicate an error about calling a private constructor.
Хочешь написать класс для отправки данных и начал с сокетов? Возьми что попроще, OkHttp и вперёд.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question