Java 错误:Listitem(字符串,字符串)在Listitem中不是公共的;无法从包外部访问
我得到了下面的错误 错误:(91,37)错误:Listitem(String,String)在中不是公共的 清单项目;无法从包外部访问 我有两个包裹 这是Listitem.javaJava 错误:Listitem(字符串,字符串)在Listitem中不是公共的;无法从包外部访问,java,android,Java,Android,我得到了下面的错误 错误:(91,37)错误:Listitem(String,String)在中不是公共的 清单项目;无法从包外部访问 我有两个包裹 这是Listitem.java public class Listitem implements Parcelable { String id; //String name; String url; Listitem(Parcel in){ this.id = in.readString();
public class Listitem implements Parcelable {
String id;
//String name;
String url;
Listitem(Parcel in){
this.id = in.readString();
// this.name = in.readString();
this.url = in.readString();
}
Listitem(String name, String url) {
this.id = id;
this.url = url;
}
@Override
public int describeContents() {
return 0;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
// dest.writeString(this.name);
dest.writeString(this.url);
}
public static final Parcelable.Creator<Listitem> CREATOR = new Parcelable.Creator<Listitem>() {
public Listitem createFromParcel(Parcel in) {
return new Listitem(in);
}
public Listitem[] newArray(int size) {
return new Listitem[size];
}
};
}
public类Listitem实现可包裹{
字符串id;
//字符串名;
字符串url;
Listitem(中的包裹){
this.id=in.readString();
//this.name=in.readString();
this.url=in.readString();
}
Listitem(字符串名称、字符串url){
this.id=id;
this.url=url;
}
@凌驾
公共int描述内容(){
返回0;
}
公共void setUrl(字符串url){
this.url=url;
}
公共字符串getUrl(){
返回url;
}
公共无效集合id(字符串id){
this.id=id;
}
公共字符串getId(){
返回id;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
dest.writeString(此.id);
//目的地记录(此名称);
dest.writeString(this.url);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共列表项createFromParcel(地块中){
返回新的列表项(在中);
}
公共列表项[]新数组(整数大小){
返回新的Listitem[大小];
}
};
}
数据库处理程序
List<Listitem> Objectslist = new ArrayList<Listitem>();
SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "SELECT "+OBJECT_ID+" ,"+OBJECT_NAME+" ,"+OBJECT_URL +" FROM " + TABLE_OBJECTS;
Cursor cursor = db.rawQuery(selectQuery, null);
DatabaseUtils.dumpCursorToString(cursor);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Listitem object = new Listitem("1","b");
List Objectslist=new ArrayList();
SQLiteDatabase db=this.getWritableDatabase();
String selectQuery=“从“+表对象”中选择“+对象ID+”、“+对象名称+”、“+对象URL+”;
Cursor Cursor=db.rawQuery(selectQuery,null);
DatabaseUtils.dumpCursorToString(游标);
//循环遍历所有行并添加到列表
if(cursor.moveToFirst()){
做{
Listitem对象=新的Listitem(“1”、“b”);
为什么会出现错误?Listitem已经是公共的,我缺少什么?如果您这样声明构造函数:
Listitem(String name, String url) {
然后,他们将获得仅包的可见性…因此,为了使其在其他包中可访问,您还需要将构造函数公开:
public Listitem(String name, String url) {
this.id = id;
this.url = url;
}
哦,我试着在包裹上加公共物品,而不是构造器,谢谢