如何解决java.io.EOFException:在android 1的改造服务调用中第1行第1列路径1的输入结束?

时间:2018-03-06 13:24:10

标签: java php android retrofit

我是android新手。我不知道为什么会出现这个错误。  错误:java.io.EOFException:第1行第1行路径$的输入结束 W / System.err:在com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1393) 请帮忙。这是我的代码: 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);
    
  2. 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();
    }
    }
    

    提前致谢。

1 个答案:

答案 0 :(得分:0)

我有同样的问题,您的代码和数据没有错。问题出在您的服务器文件(.php)中。您必须将此添加到配置文件下

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

因此您的文件必须是这样的

<?php 
require "koneksi.php";

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

    $name = $_POST["name"];

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

} ?>