I want to use IP2Location.io in my Android Studio app. I am starting with this program from their internet site. I am stuck on this error. I do not understand why this difficulty including java/net/http/HttpRequest. I researched many similar threads on Stackoverflow but did not find a resolution. I tried unsuccessfully to include other HttpRequest. Perhaps I do not know how to do that. Any ideas will be appreciated.
I started at... https://blog.ip2location.com/knowledge-base/using-ip2location-io-java-sdk-in-a-maven-project/ Using IP2Location.io Java SDK in a Maven project
I scrolled down to... Adding the IP2Location.io Java SDK into the Maven dependency
I worked thru to the end, adding the code to a new Android Studio "Empty Activity". I made changes as I went along to get rid of the "red errors" :) It took me most of a day. My last, most difficult error was the infamous red R. The program builds cleanly on Android studio. But here is the result..
E/AndroidRuntime: FATAL EXCEPTION: main
Process: gmd.com.mickwebsite.ip2locationion, PID: 1505
**java.lang.NoClassDefFoundError: Failed resolution of: Ljava/net/http/HttpRequest;**
at com.ip2location.IPGeolocation.Lookup(IPGeolocation.java:59)
at com.ip2location.IPGeolocation.Lookup(IPGeolocation.java:46)
at gmd.com.mickwebsite.ip2locationion.MainActivity.onCreate(MainActivity.java:30)
... Here is the complete code... Note this about half way: // <<--App hangs up here
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.JsonObject;
import com.ip2location.Configuration;
import com.ip2location.DomainWhois;
import com.ip2location.IPGeolocation;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView mainDisplay = findViewById(R.id.mainDisplay);
// Configures IP2Location.io API key
Configuration config = new Configuration();
// String apiKey = "API KEY"; // I used my personal API key
config.setApiKey(apiKey);
IPGeolocation ipl = new IPGeolocation(config);
// Lookup ip address geolocation data
JsonObject myObj;
// the language parameter is only available for Plus and Security plans
try {
myObj = ipl.Lookup("8.8.8.8"); **// <<--App hangs up here**
// java.lang.NoClassDefFoundError:
// Failed resolution of: Ljava/net/http/HttpRequest;
} catch (Exception e) {
mainDisplay.setText(String.valueOf(e));
throw new RuntimeException(e);
}
mainDisplay.setText(String.valueOf(myObj));
// I added the id for the textView in the xml
DomainWhois whois = new DomainWhois(config);
// Lookup domain information
JsonObject myObj2;
try {
myObj2 = whois.Lookup("locaproxy.com");
} catch (Exception e) {
mainDisplay.setText(String.valueOf(e));
throw new RuntimeException(e);
}
mainDisplay.setText(String.valueOf(myObj2));
} // protected void onCreate
} // public class MainActivity