用php文件数组连接Android微调器

问题描述

这是一个调用以在微调器中显示数据的函数

这是我得到的回应。 响应:引起:java.lang.NullPointerException:尝试在空对象引用上调用接口方法'retrofit2.Call co.ke.smartcare.apiutilities.ApiService.fetchDocs()'

功能: 公共无效 fetchDoctors(){

<?PHP 
    $sqlactive= "SELECT * from Tabule1 WHERE TabStatus LIKE '0'";
    $result = $conn->query($sqlactive);
    if ($result->num_rows > 0) {
        while ($row = $result-> fetch_assoc()) {
            echo "<tr>
            <td>" . $row["TabKlient"] . "</td>
            <td>" . $row["TabOsoba"] . "</td>
            <td>" . $row["TabItem"] . "</td>
            <td>" . $row["TabQty"] . "</td>
            <td>" . $row["TabNote"] . "</td>
            <td>" . $row["TabAddedBy"] . "</td>
            <td>" . $row["TabDate"] . "</td>"
            '<td><a href="edit.PHP?id='.$row['ID'].'"> test </a></td>' "</tr>";
          }
    }
?>

解决方法

在这种情况下,您的改造 api 调用接口不得正确初始化。 先将这些添加到你的 build.gradle 中。

implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'

然后将此添加到您的java代码中。

public static ApiInterface getClient() {
        if(retrofitServerOne==null) {
            HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .addNetworkInterceptor(loggingInterceptor)
                    .callTimeout(1,TimeUnit.MINUTES)
                    .connectTimeout(1,TimeUnit.MINUTES)
                    .build();
            retrofitServerOne=new Retrofit.Builder()
                    .baseUrl("Url u need")
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build().create(ApiInterface.class);
        }
        return retrofitServerOne;
    }

试试这种方式,它也会显示 api 调用的日志。 将 ApiInterface 替换为您的接口。