-1

As an aspiring Android developer, I successfully created a simple MVVM dictionary app, leveraging the power of popular tools such as Retrofit for API calls, Dagger Hilt for dependency injection, and Jetpack Compose for crafting an intuitive UI. Additionally, I integrated an external library to facilitate network response handling, and I'm pleased to say that my code is free of errors. However, during the testing phase, I encountered a persistent issue where the network response consistently indicated "no internet connection," despite granting the necessary internet permissions in the app's manifest file.

Since I am relatively new to Android development, I am seeking the expertise of experienced developers to assist me in identifying the root cause of this problem and finding an effective solution. Any assistance, feedback, or suggestions from the community would be immensely appreciated, as my goal is to create a fully functional and reliable dictionary app.

For those interested in reviewing the code and providing guidance, the project can be accessed via the following GitHub link: [DictionaryAPP GitHub Repository]

(https://github.com/CUBE2003/DictionaryAPP).

Thank you in advance to all experienced Android developers who can lend a helping hand in resolving this issue and making this project a success. Your support will be invaluable to me as I continue to grow and learn in the world of Android development.

CUBE
  • 1

1 Answers1

1

i checked your base URL of your API server using Postman. You provided the URL https://api.dectionaryapi.dev/ which is incorrect, the correct URL is https://api.dictionaryapi.dev/, change the code in hilt module to :

@Provides
@Singleton
fun provideRetrofitInstance(): Retrofit {
    return Retrofit.Builder()
        .baseUrl("https://api.dictionaryapi.dev/")
        .addCallAdapterFactory(NetworkResponseAdapterFactory())
        .addConverterFactory(GsonConverterFactory.create())
        .client(logingInterceptror())
        .build()
}

when dealing with network requests with a server i recommended to always use Postman and test the API before using it in your project because it might have internal errors that you cant handle. This way, you can ensure your endpoints are correct and that the server is responding as expected. also it's critical to handle all possible HTTP responses and not just success cases. Retrofit provides mechanisms for this, such as handling IOException for network errors or not successful HTTP responses. The error message "check your internet connection" usually arises due to a network error (like IOException), so it's important to handle this in your code.

make sure to rebuild your project to regenerate hilt dependencies.

I hope this helps you debug and solve your issue! Remember, when dealing with network operations, proper error handling is key.

Mado
  • 329
  • 3
  • 16
  • Thank you so much, learned a lot, yes will definitely use postman to check API from now on. – CUBE Jul 20 '23 at 13:19