1

I am new to android. I am not getting why this error is coming. Error : java.io.EOFException: End of input at line 1 column 1 path $ W/System.err:at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1393) Please help. This is my code : 1. Pojo

class ProfileEntity implements Parcelable {

@SerializedName("tag")
@Expose
private String tag;
@SerializedName("success")
@Expose
private Integer success;
@SerializedName("error")
@Expose
private Integer error;
@SerializedName("studentId")
@Expose
private String studentId;
@SerializedName("pic_id")
@Expose
private String picId;
@SerializedName("instUrl")
@Expose
private String instUrl;
@SerializedName("course_name")
@Expose
private String courseName;
@SerializedName("batch_name")
@Expose
private String batchName;
@SerializedName("semester_name")
@Expose
private Object semesterName;
@SerializedName("section_name")
@Expose
private String sectionName;
@SerializedName("first_name")
@Expose
private String firstName;
@SerializedName("last_name")
@Expose
private String lastName;
@SerializedName("username")
@Expose
private String username;
@SerializedName("groupname")
@Expose
private String groupname;
@SerializedName("mobile")
@Expose
private String mobile;
@SerializedName("email")
@Expose
private String email;
@SerializedName("dob")
@Expose
private String dob;
@SerializedName("address")
@Expose
private String address;
@SerializedName("dbname")
@Expose
private String dbname;
@SerializedName("Branch_id")
@Expose
private String branchId;
@SerializedName("org_id")
@Expose
private String orgId;
@SerializedName("cyear")
@Expose
private String cyear;
@SerializedName("url")
@Expose
private String url;
@SerializedName("password")
@Expose
private String password;
public final static Creator<ProfileEntity> CREATOR = new Creator<ProfileEntity>() {


    @SuppressWarnings({
            "unchecked"
    })
    public ProfileEntity createFromParcel(Parcel in) {
        return new ProfileEntity(in);
    }

    public ProfileEntity[] newArray(int size) {
        return (new ProfileEntity[size]);
    }
};

protected ProfileEntity(Parcel in) {
    this.tag = ((String) in.readValue((String.class.getClassLoader())));
    this.success = ((Integer) in.readValue((Integer.class.getClassLoader())));
    this.error = ((Integer) in.readValue((Integer.class.getClassLoader())));
    this.studentId = ((String) in.readValue((String.class.getClassLoader())));
    this.picId = ((String) in.readValue((String.class.getClassLoader())));
    this.instUrl = ((String) in.readValue((String.class.getClassLoader())));
    this.courseName = ((String) in.readValue((String.class.getClassLoader())));
    this.batchName = ((String) in.readValue((String.class.getClassLoader())));
    this.semesterName = ((Object) in.readValue((Object.class.getClassLoader())));
    this.sectionName = ((String) in.readValue((String.class.getClassLoader())));
    this.firstName = ((String) in.readValue((String.class.getClassLoader())));
    this.lastName = ((String) in.readValue((String.class.getClassLoader())));
    this.username = ((String) in.readValue((String.class.getClassLoader())));
    this.groupname = ((String) in.readValue((String.class.getClassLoader())));
    this.mobile = ((String) in.readValue((String.class.getClassLoader())));
    this.email = ((String) in.readValue((String.class.getClassLoader())));
    this.dob = ((String) in.readValue((String.class.getClassLoader())));
    this.address = ((String) in.readValue((String.class.getClassLoader())));
    this.dbname = ((String) in.readValue((String.class.getClassLoader())));
    this.branchId = ((String) in.readValue((String.class.getClassLoader())));
    this.orgId = ((String) in.readValue((String.class.getClassLoader())));
    this.cyear = ((String) in.readValue((String.class.getClassLoader())));
    this.url = ((String) in.readValue((String.class.getClassLoader())));
    this.password = ((String) in.readValue((String.class.getClassLoader())));
}

public ProfileEntity() {}

public String getCyear() {
    return cyear;
}

public void setCyear(String cyear) {
    this.cyear = cyear;
}

public String getUrl() {
    return url;
}

public void setUrl(String url) {
    this.url = url;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getOrgId() {
    return orgId;
}

public void setOrgId(String orgId) {
    this.orgId = orgId;
}

public String getBranchId() {
    return branchId;
}

public void setBranchId(String branchId) {
    this.branchId = branchId;
}

public String getDbname() {
    return dbname;
}

public void setDbname(String dbname) {
    this.dbname = dbname;
}

public String getTag() {
    return tag;
}

public void setTag(String tag) {
    this.tag = tag;
}

public Integer getSuccess() {
    return success;
}

public void setSuccess(Integer success) {
    this.success = success;
}

public Integer getError() {
    return error;
}

public void setError(Integer error) {
    this.error = error;
}

public String getStudentId() {
    return studentId;
}

public void setStudentId(String studentId) {
    this.studentId = studentId;
}

public String getPicId() {
    return picId;
}

public void setPicId(String picId) {
    this.picId = picId;
}

public String getInstUrl() {
    return instUrl;
}

public void setInstUrl(String instUrl) {
    this.instUrl = instUrl;
}

public String getCourseName() {
    return courseName;
}

public void setCourseName(String courseName) {
    this.courseName = courseName;
}

public String getBatchName() {
    return batchName;
}

public void setBatchName(String batchName) {
    this.batchName = batchName;
}

public Object getSemesterName() {
    return semesterName;
}

public void setSemesterName(Object semesterName) {
    this.semesterName = semesterName;
}

public String getSectionName() {
    return sectionName;
}

public void setSectionName(String sectionName) {
    this.sectionName = sectionName;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getGroupname() {
    return groupname;
}

public void setGroupname(String groupname) {
    this.groupname = groupname;
}

public String getMobile() {
    return mobile;
}

public void setMobile(String mobile) {
    this.mobile = mobile;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getDob() {
    return dob;
}

public void setDob(String dob) {
    this.dob = dob;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public void writeToParcel(Parcel dest, int flags) {
    dest.writeValue(tag);
    dest.writeValue(success);
    dest.writeValue(error);
    dest.writeValue(studentId);
    dest.writeValue(picId);
    dest.writeValue(instUrl);
    dest.writeValue(courseName);
    dest.writeValue(batchName);
    dest.writeValue(semesterName);
    dest.writeValue(sectionName);
    dest.writeValue(firstName);
    dest.writeValue(lastName);
    dest.writeValue(username);
    dest.writeValue(groupname);
    dest.writeValue(mobile);
    dest.writeValue(email);
    dest.writeValue(dob);
    dest.writeValue(address);
    dest.writeValue(dbname);
    dest.writeValue(branchId);
    dest.writeValue(orgId);
    dest.writeValue(cyear);
    dest.writeValue(url);
    dest.writeValue(password);
}

public int describeContents() {
    return 0;
}
}
  1. ApiInterface

        @Headers("Content-Type: application/json")
        @POST("profile.php")
     Call<ProfileEntity> getProfile(@Body ProfileEntity profileEntity);
    

3.Impl

@Override
public void profileCall(ProfileEntity profileEntity) {
 ApiInterface controller = ApiClient.getClient(null).create(ApiInterface.class);
 Call<ProfileEntity> call = controller.getProfile(profileEntity);
    call.enqueue(new Callback<ProfileEntity>() {
        @Override
        public void onResponse(Call<ProfileEntity> call, Response<ProfileEntity> response) {
            if (response.body() != null) {
                ProfileEntity entity = response.body();
                if (entity.getSuccess().toString().equalsIgnoreCase("1")) {
                    profilePresentor.onProfileSuccess(entity);
                } else {
                    profilePresentor.onLogFailedMessage(response.message());
                }

            } else {
                profilePresentor.onLogFailedMessage(response.message());
            }
        }

        @Override
        public void onFailure(Call<ProfileEntity> call, Throwable t) {
            Log.d("FAILURE....",t.toString());
            t.printStackTrace();
            profilePresentor.onProfileFailure(HttpURLConnection.HTTP_INTERNAL_ERROR,"Oops! Something went wrong. Please try again");
        }
    });
}
}

4.ApiClient

 class ApiClient {

public static String BASE_URL = "http://xxxx.xxxxxx.com/appAPI_v2/";

static Retrofit retrofit = null;

public static Retrofit getClient(Map<String, String> headerMap) {
    Gson gson = new GsonBuilder()
            .setLenient()
            .create();

    Retrofit.Builder builder = new Retrofit.Builder();
    builder.baseUrl(BASE_URL);
    builder.addConverterFactory(GsonConverterFactory.create(gson));

    if (headerMap != null) {
        builder.client(getHeader(headerMap));
    } else {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
        httpClient.readTimeout(60, TimeUnit.SECONDS);
        httpClient.connectTimeout(60, TimeUnit.SECONDS);
        if (BuildConfig.DEBUG)
            httpClient.addInterceptor(interceptor);
        builder.client(httpClient.build());
    }
    retrofit = builder.build();
    return retrofit;
}

@NonNull
private static OkHttpClient getHeader(final Map<String, String> header) {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()
            .setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Interceptor.Chain chain) throws IOException {
            Request original = chain.request();

            Request.Builder builder = original.newBuilder();
            for (Map.Entry<String, String> entry : header.entrySet()) {
                builder.addHeader(entry.getKey(), entry.getValue());
            }
            builder.method(original.method(), original.body());
            return chain.proceed(builder.build());
        }
    });
    if (BuildConfig.DEBUG) //hides exposing web service call in logcat when app is released
        httpClient.addInterceptor(interceptor);
    return httpClient.build();
}
}

Thanks in advance.

Risk
  • 23
  • 1
  • 7
  • What is your implementation method `profileCall()` supposed to do? It seems that inside it, you're calling your service declaration's getter (`ApiInterface.getProfile()`) by passing into it a ProfileEntity, which that method is supposed to get. You should probably make sure the call syntax matches the method signature first – kip2 Mar 06 '18 at 19:44
  • yes, I am passing ProfileEntity into my service impl class. I have updated my code. Still I am getting same error. – Risk Mar 07 '18 at 05:48
  • I'm just wondering why `getProfile()` needs a `ProfileEntity` argument when it's supposed to return one. It suggests to me a design flaw with that function, but maybe I don't fully understand your code – kip2 Mar 08 '18 at 04:30
  • Possible duplicate of [Retrofit2 error java.io.EOFException: End of input at line 1 column 1](https://stackoverflow.com/questions/35744795/retrofit2-error-java-io-eofexception-end-of-input-at-line-1-column-1) – Yousha Aleayoub Jan 15 '19 at 09:35

1 Answers1

0

I have the same problem, There is nothing wrong with your code and your data. The problem is in your server file (.php). You must add this under the configuration file

if ($_SERVER['REQUEST_METHOD'] === 'POST') { // your query }

so your file must be like this

<?php 
require "koneksi.php";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $name = $_POST["name"];

    mysqli_query($koneksi,"insert into user (name) VALUES ('$name')");

} ?>