Java 错误:不兼容的类型:<;空>;如果使用android room(!\u cursor.isNull(null))则无法转换为int

Java 错误:不兼容的类型:<;空>;如果使用android room(!\u cursor.isNull(null))则无法转换为int,java,android,sql,database,android-room,Java,Android,Sql,Database,Android Room,我正在使用我的android数据库空间。在这里,我在Customer和ServiceProvider类之间有一个多对多关系,我曾经这样做过,但在编译之后,我收到了以下错误: /home/omid/IntelliJIDEAProjects/Accounting/app/build/generated/ap_generated_sources/debug/out/com/omidsl/Accounting/db/CustomerDAO_Impl.java:69:错误:不兼容的类型:无法转换为int

我正在使用我的android数据库空间。在这里,我在Customer和ServiceProvider类之间有一个多对多关系,我曾经这样做过,但在编译之后,我收到了以下错误:

/home/omid/IntelliJIDEAProjects/Accounting/app/build/generated/ap_generated_sources/debug/out/com/omidsl/Accounting/db/CustomerDAO_Impl.java:69:错误:不兼容的类型:无法转换为int 如果(!\u cursor.isNull(null)){

这段代码提到了CustomerDAO_Impl.java(由编译器创建):

CustomerDAO.java:

package com.omidmsl.accounting.models;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity(tableName = "Customer")
public class Customer {

    public static final String KEY_NAME = "customer_name";
    public static final String KEY_PHONE_NUMBER = "phone_number";

    @NonNull
    @PrimaryKey
    private String customerName;
    private String phoneNumber;

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
}
package com.omidmsl.accounting.db;

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import com.omidmsl.accounting.models.Customer;
import com.omidmsl.accounting.models.serviceprovider.CustomerOfServiceProvider;

import java.util.List;

@Dao
public interface CustomerDAO {

    @Query("SELECT * FROM Customer")
    public List<Customer> getCustomers();

    @Transaction
    @Query("SELECT * FROM Customer")
    public List<CustomerOfServiceProvider> getCustomersOfServiceProvider();

    @Query("SELECT * FROM Customer WHERE customerName = :cName")
    public List<Customer> getCustomer(String cName);
}

package com.omidmsl.accounting.models;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.*;


@Entity(tableName = "Business")
public class Business {

    public static final String KEY_TYPE = "type";
    public static final String KEY_NAME = "business_name";
    public static final String KEY_PHONE_NUMBER = "phone_number";

    private int type;
    @PrimaryKey
    @NonNull
    private String businessName;
    private String phoneNumber;
    @Ignore
    private long costs;
    @Ignore
    private long buys;

    public Business(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Business() {
        businessName = "";
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public long getCosts() {
        return costs;
    }

    public void setCosts(long costs) {
        this.costs = costs;
    }

    public long getBuys() {
        return buys;
    }

    public void setBuys(long buys) {
        this.buys = buys;
    }
}

package com.omidmsl.accounting.db;

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import com.omidmsl.accounting.models.serviceprovider.ServiceProviderOfCustomer;

import java.util.List;

@Dao
public interface ServiceProviderDAO {
    @Transaction
    @Query("SELECT * FROM Business")
    public List<ServiceProviderOfCustomer> getServiceProvidersOfCustomer();
}
package com.omidmsl.accounting.models.serviceprovider;

import androidx.room.*;
import com.omidmsl.accounting.models.Business;
import com.omidmsl.accounting.models.Customer;

import java.util.List;

public class CustomerOfServiceProvider {
    @Embedded
    private Business serviceProvider;
    @Relation(
            parentColumn = "businessName",
            entityColumn = "customerName",
            associateBy = @Junction(Service.class)
    )
    private List<Customer> customers;

    public Business getServiceProvider() {
        return serviceProvider;
    }

    public void setServiceProvider(Business serviceProvider) {
        this.serviceProvider = serviceProvider;
    }

    public List<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }
}
ServiceProviderDAO.java:

package com.omidmsl.accounting.models;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity(tableName = "Customer")
public class Customer {

    public static final String KEY_NAME = "customer_name";
    public static final String KEY_PHONE_NUMBER = "phone_number";

    @NonNull
    @PrimaryKey
    private String customerName;
    private String phoneNumber;

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
}
package com.omidmsl.accounting.db;

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import com.omidmsl.accounting.models.Customer;
import com.omidmsl.accounting.models.serviceprovider.CustomerOfServiceProvider;

import java.util.List;

@Dao
public interface CustomerDAO {

    @Query("SELECT * FROM Customer")
    public List<Customer> getCustomers();

    @Transaction
    @Query("SELECT * FROM Customer")
    public List<CustomerOfServiceProvider> getCustomersOfServiceProvider();

    @Query("SELECT * FROM Customer WHERE customerName = :cName")
    public List<Customer> getCustomer(String cName);
}

package com.omidmsl.accounting.models;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.*;


@Entity(tableName = "Business")
public class Business {

    public static final String KEY_TYPE = "type";
    public static final String KEY_NAME = "business_name";
    public static final String KEY_PHONE_NUMBER = "phone_number";

    private int type;
    @PrimaryKey
    @NonNull
    private String businessName;
    private String phoneNumber;
    @Ignore
    private long costs;
    @Ignore
    private long buys;

    public Business(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Business() {
        businessName = "";
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public long getCosts() {
        return costs;
    }

    public void setCosts(long costs) {
        this.costs = costs;
    }

    public long getBuys() {
        return buys;
    }

    public void setBuys(long buys) {
        this.buys = buys;
    }
}

package com.omidmsl.accounting.db;

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import com.omidmsl.accounting.models.serviceprovider.ServiceProviderOfCustomer;

import java.util.List;

@Dao
public interface ServiceProviderDAO {
    @Transaction
    @Query("SELECT * FROM Business")
    public List<ServiceProviderOfCustomer> getServiceProvidersOfCustomer();
}
package com.omidmsl.accounting.models.serviceprovider;

import androidx.room.*;
import com.omidmsl.accounting.models.Business;
import com.omidmsl.accounting.models.Customer;

import java.util.List;

public class CustomerOfServiceProvider {
    @Embedded
    private Business serviceProvider;
    @Relation(
            parentColumn = "businessName",
            entityColumn = "customerName",
            associateBy = @Junction(Service.class)
    )
    private List<Customer> customers;

    public Business getServiceProvider() {
        return serviceProvider;
    }

    public void setServiceProvider(Business serviceProvider) {
        this.serviceProvider = serviceProvider;
    }

    public List<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }
}
package com.omidsl.accounting.db;
导入androidx.room.Dao;
导入androidx.room.Query;
导入androidx.room.Transaction;
导入com.omidsl.accounting.models.serviceprovider.ServiceProviderOfCustomer;
导入java.util.List;
@刀
公共接口服务提供者DAO{
@交易
@查询(“从业务中选择*)
公共列表getServiceProvidersOfCustomer();
}
CustomersOfServiceProvider.java:

package com.omidmsl.accounting.models;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity(tableName = "Customer")
public class Customer {

    public static final String KEY_NAME = "customer_name";
    public static final String KEY_PHONE_NUMBER = "phone_number";

    @NonNull
    @PrimaryKey
    private String customerName;
    private String phoneNumber;

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
}
package com.omidmsl.accounting.db;

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import com.omidmsl.accounting.models.Customer;
import com.omidmsl.accounting.models.serviceprovider.CustomerOfServiceProvider;

import java.util.List;

@Dao
public interface CustomerDAO {

    @Query("SELECT * FROM Customer")
    public List<Customer> getCustomers();

    @Transaction
    @Query("SELECT * FROM Customer")
    public List<CustomerOfServiceProvider> getCustomersOfServiceProvider();

    @Query("SELECT * FROM Customer WHERE customerName = :cName")
    public List<Customer> getCustomer(String cName);
}

package com.omidmsl.accounting.models;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.*;


@Entity(tableName = "Business")
public class Business {

    public static final String KEY_TYPE = "type";
    public static final String KEY_NAME = "business_name";
    public static final String KEY_PHONE_NUMBER = "phone_number";

    private int type;
    @PrimaryKey
    @NonNull
    private String businessName;
    private String phoneNumber;
    @Ignore
    private long costs;
    @Ignore
    private long buys;

    public Business(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Business() {
        businessName = "";
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public long getCosts() {
        return costs;
    }

    public void setCosts(long costs) {
        this.costs = costs;
    }

    public long getBuys() {
        return buys;
    }

    public void setBuys(long buys) {
        this.buys = buys;
    }
}

package com.omidmsl.accounting.db;

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.Transaction;
import com.omidmsl.accounting.models.serviceprovider.ServiceProviderOfCustomer;

import java.util.List;

@Dao
public interface ServiceProviderDAO {
    @Transaction
    @Query("SELECT * FROM Business")
    public List<ServiceProviderOfCustomer> getServiceProvidersOfCustomer();
}
package com.omidmsl.accounting.models.serviceprovider;

import androidx.room.*;
import com.omidmsl.accounting.models.Business;
import com.omidmsl.accounting.models.Customer;

import java.util.List;

public class CustomerOfServiceProvider {
    @Embedded
    private Business serviceProvider;
    @Relation(
            parentColumn = "businessName",
            entityColumn = "customerName",
            associateBy = @Junction(Service.class)
    )
    private List<Customer> customers;

    public Business getServiceProvider() {
        return serviceProvider;
    }

    public void setServiceProvider(Business serviceProvider) {
        this.serviceProvider = serviceProvider;
    }

    public List<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }
}
package com.omidsl.accounting.models.serviceprovider;
导入androidx.room.*;
导入com.omidsl.accounting.models.Business;
导入com.omidsl.accounting.models.Customer;
导入java.util.List;
公共类CustomerOfServiceProvider{
@嵌入
私营企业服务提供商;
@关系(
parentColumn=“businessName”,
entityColumn=“customerName”,
associateBy=@Junction(Service.class)
)
私人名单客户;
公共业务getServiceProvider(){
返回服务提供商;
}
公共作废设置服务提供者(业务服务提供者){
this.serviceProvider=serviceProvider;
}
公共列表getCustomers(){
返回客户;
}
公共客户(列出客户){
这是。顾客=顾客;
}
}
请帮帮我

谢谢。问题解决了!。
CustomerDAO文件中,我发现了以下问题:

@Transaction
    @Query("SELECT * FROM Customer")
    public List<CustomerOfServiceProvider> getCustomersOfServiceProvider();
@事务
@查询(“从客户中选择*)
public List getCustomersOfServiceProvider();
此列表的类型必须是ServiceProvidersOfCustomer:

@Transaction
    @Query("SELECT * FROM Customer")
    public List<ServiceProviderOfCustomer> getServiceProvidersOfCustomer();
@事务
@查询(“从客户中选择*)
公共列表getServiceProvidersOfCustomer();
谢谢。问题解决了!。
CustomerDAO文件中,我发现了以下问题:

@Transaction
    @Query("SELECT * FROM Customer")
    public List<CustomerOfServiceProvider> getCustomersOfServiceProvider();
@事务
@查询(“从客户中选择*)
public List getCustomersOfServiceProvider();
此列表的类型必须是ServiceProvidersOfCustomer:

@Transaction
    @Query("SELECT * FROM Customer")
    public List<ServiceProviderOfCustomer> getServiceProvidersOfCustomer();
@事务
@查询(“从客户中选择*)
公共列表getServiceProvidersOfCustomer();

您可以包含您的
CustomerOfServiceProvider
类吗?这就是它试图为您的
GetCustomerOfServiceProvider()创建的内容
返回类型。我添加了它。tnx是否可以包含
CustomerOfServiceProvider
类?这就是它试图填充的内容,以创建
GetCustomerOfServiceProvider()
返回类型。我添加了它。tnx