500 Error code with “Internal server Error” message, while doing POST method using MVVM and API in android application

June 01, 2021, at 05:00 AM

For API confirmation, I have tried in POSTMAN app, But response is getting properly and the data has been inserted successfully. Below is the result of POSTMAN.

As am new to android application. this is my first program using API with MVVM concepts. Here is the code which I tried. Please guide me find the issue.

// Base URL

public class ApiClient {
    private static Retrofit retrofit;
    public static Retrofit getRetrofit() {
        if(retrofit == null) {
            Retrofit.Builder builder = new Retrofit.Builder()
            retrofit = builder.build();
        return retrofit;


public interface ApiService {
    Call<AddResponse> AddCourse(
            @Field("course_title") String course_title,
            @Field("course_desc") String course_desc,
            @Field("course_fees") String course_fees
public class AddResponse {
   public Integer status;
   public String message;


public class AddCourseViewModel extends ViewModel {
    ActivityMainBinding binding;
    Retrofit retrofit;
    ApiService addService;
    public AddCourseViewModel(ApiService apiService) {
        this.addService = apiService;
    public void AddingCourse() {
        String Course_desc = binding.etCourseDescription.getText().toString();
        String  Course_Title = binding.etCourseTitle.getText().toString();
        String Course_Fees = binding.etCourseFee.getText().toString();
        MutableLiveData<String> msg = new MutableLiveData<>("");
        Call<AddResponse> call = addService.AddCourse(Course_Title,Course_desc,Course_Fees);
        call.enqueue(new Callback<AddResponse>() {
         public void onResponse(Call<AddResponse> call, Response<AddResponse> response) {
             if (response.isSuccessful()) {
                 AddResponse addRes = response.body();
                 if (addRes.status == 0) {
                     msg.postValue("Successfully added");
                 } else {
                     msg.postValue("Failure 1");
             else {
                 msg.postValue("Failure 2"+response.code() + "Message " +response.message());

         public void onFailure(Call<AddResponse> call, Throwable t) {
              msg.postValue(t.getMessage() +"Failure 3");
public class AddCourseVMFactory extends ViewModelProvider.NewInstanceFactory {
    private ApiService apiService;
    public AddCourseVMFactory(ApiService apiService) {
        this.apiService = apiService;
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        AddCourseViewModel viewModel = new AddCourseViewModel(apiService);
        return ((T)viewModel);
public class MainActivity extends AppCompatActivity {
     ActivityMainBinding binding;
     Retrofit retrofit;
     ApiService addService;
    AddCourseVMFactory factory;
    AddCourseViewModel viewModel;
    protected void onCreate(Bundle savedInstanceState) {
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        retrofit = ApiClient.getRetrofit();
        addService = retrofit.create(ApiService.class);
        factory = new AddCourseVMFactory(addService);
        viewModel = new ViewModelProvider(this, factory).get(AddCourseViewModel.class);
        binding.btnAddCourse.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
Rent Charter Buses Company
How do I get the value of useState from component A to component B

How do I get the value of useState from component A to component B

I'm relatively new to JS and React as a whole, I delved into React and started making some projects with Django backendI have a list of items in the ProductList component in react,

Node application crashes due to mysql error &#39;PROTOCOL_PACKETS_OUT_OF_ORDER&#39;

Node application crashes due to mysql error 'PROTOCOL_PACKETS_OUT_OF_ORDER'

I am running a nodejs application (web service using express) on RHEL v8, using node v16

Javascript and jquery I can&#39;t read value from array index

Javascript and jquery I can't read value from array index

I have a list of numbers (ex"20,145") that returns from an ajax call and I am pushing them to a js array

I want to filter the clients of every agent individually. Django

I want to filter the clients of every agent individually. Django

I'm creating a view where I can show all the clients of specific agents via there PK