Room database exception in first time app install











up vote
0
down vote

favorite












I developed an Android app and using room database.
When U install the app for the first time, the app crashes, and the exception is



Fatal Exception: android.database.sqlite.SQLiteException
index index_LocationHistoryBean_address already exists (code 1): , while compiling: CREATE INDEX `index_LocationHistoryBean_address` ON `LocationHistoryBean` (`address`)


My dao file is



@Entity(indices = {@Index("address") , @Index("title")})
public class LocationHistoryBean extends BaseObservable implements Parcelable {
@PrimaryKey(autoGenerate = true)
private int id;
private String address;
private double latitude;
private double longitude;
private Date cacheDate;
private String icon;
private String title;
private boolean inTrafficZone;
private boolean inOddEvenZone;
private String category;
private Boolean isHistory = false;

public LocationHistoryBean() {
}


protected LocationHistoryBean(Parcel in) {
id = in.readInt();
address = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
icon = in.readString();
title = in.readString();
inTrafficZone = in.readByte() != 0;
inOddEvenZone = in.readByte() != 0;
category = in.readString();
byte tmpIsHistory = in.readByte();
isHistory = tmpIsHistory == 0 ? null : tmpIsHistory == 1;
}

public static final Creator<LocationHistoryBean> CREATOR = new Creator<LocationHistoryBean>() {
@Override
public LocationHistoryBean createFromParcel(Parcel in) {
return new LocationHistoryBean(in);
}

@Override
public LocationHistoryBean newArray(int size) {
return new LocationHistoryBean[size];
}
};

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Bindable
public String getAddress() {
return address;
}

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

@Bindable
public double getLatitude() {
return latitude;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
notifyPropertyChanged(BR.latitude);
}

@Bindable
public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {
this.longitude = longitude;
notifyPropertyChanged(BR.longitude);
}


public Date getCacheDate() {
return cacheDate;
}

public void setCacheDate(Date cacheDate) {
this.cacheDate = cacheDate;
}

@Bindable
public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
notifyPropertyChanged(BR.icon);
}

@Bindable
public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
notifyPropertyChanged(BR.title);
}

@Bindable
public boolean isInTrafficZone() {
return inTrafficZone;
}

public void setInTrafficZone(boolean inTrafficZone) {
this.inTrafficZone = inTrafficZone;
notifyPropertyChanged(BR.inTrafficZone);
}

@Bindable
public boolean isInOddEvenZone() {
return inOddEvenZone;
}

public void setInOddEvenZone(boolean inOddEvenZone) {
this.inOddEvenZone = inOddEvenZone;
notifyPropertyChanged(BR.inOddEvenZone);
}

@Bindable
public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
notifyPropertyChanged(BR.category);
}

@Bindable
public Boolean getHistory() {
return isHistory;
}

public void setHistory(Boolean history) {
isHistory = history;
notifyPropertyChanged(BR.history);
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(address);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeString(icon);
dest.writeString(title);
dest.writeByte((byte) (inTrafficZone ? 1 : 0));
dest.writeByte((byte) (inOddEvenZone ? 1 : 0));
dest.writeString(category);
dest.writeByte((byte) (isHistory == null ? 0 : isHistory ? 1 : 2));
}


public LatLng getLocationAsLatlng(){return new LatLng(getLatitude() , getLongitude());}
}









share|improve this question




























    up vote
    0
    down vote

    favorite












    I developed an Android app and using room database.
    When U install the app for the first time, the app crashes, and the exception is



    Fatal Exception: android.database.sqlite.SQLiteException
    index index_LocationHistoryBean_address already exists (code 1): , while compiling: CREATE INDEX `index_LocationHistoryBean_address` ON `LocationHistoryBean` (`address`)


    My dao file is



    @Entity(indices = {@Index("address") , @Index("title")})
    public class LocationHistoryBean extends BaseObservable implements Parcelable {
    @PrimaryKey(autoGenerate = true)
    private int id;
    private String address;
    private double latitude;
    private double longitude;
    private Date cacheDate;
    private String icon;
    private String title;
    private boolean inTrafficZone;
    private boolean inOddEvenZone;
    private String category;
    private Boolean isHistory = false;

    public LocationHistoryBean() {
    }


    protected LocationHistoryBean(Parcel in) {
    id = in.readInt();
    address = in.readString();
    latitude = in.readDouble();
    longitude = in.readDouble();
    icon = in.readString();
    title = in.readString();
    inTrafficZone = in.readByte() != 0;
    inOddEvenZone = in.readByte() != 0;
    category = in.readString();
    byte tmpIsHistory = in.readByte();
    isHistory = tmpIsHistory == 0 ? null : tmpIsHistory == 1;
    }

    public static final Creator<LocationHistoryBean> CREATOR = new Creator<LocationHistoryBean>() {
    @Override
    public LocationHistoryBean createFromParcel(Parcel in) {
    return new LocationHistoryBean(in);
    }

    @Override
    public LocationHistoryBean newArray(int size) {
    return new LocationHistoryBean[size];
    }
    };

    public int getId() {
    return id;
    }

    public void setId(int id) {
    this.id = id;
    }

    @Bindable
    public String getAddress() {
    return address;
    }

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

    @Bindable
    public double getLatitude() {
    return latitude;
    }

    public void setLatitude(double latitude) {
    this.latitude = latitude;
    notifyPropertyChanged(BR.latitude);
    }

    @Bindable
    public double getLongitude() {
    return longitude;
    }

    public void setLongitude(double longitude) {
    this.longitude = longitude;
    notifyPropertyChanged(BR.longitude);
    }


    public Date getCacheDate() {
    return cacheDate;
    }

    public void setCacheDate(Date cacheDate) {
    this.cacheDate = cacheDate;
    }

    @Bindable
    public String getIcon() {
    return icon;
    }

    public void setIcon(String icon) {
    this.icon = icon;
    notifyPropertyChanged(BR.icon);
    }

    @Bindable
    public String getTitle() {
    return title;
    }

    public void setTitle(String title) {
    this.title = title;
    notifyPropertyChanged(BR.title);
    }

    @Bindable
    public boolean isInTrafficZone() {
    return inTrafficZone;
    }

    public void setInTrafficZone(boolean inTrafficZone) {
    this.inTrafficZone = inTrafficZone;
    notifyPropertyChanged(BR.inTrafficZone);
    }

    @Bindable
    public boolean isInOddEvenZone() {
    return inOddEvenZone;
    }

    public void setInOddEvenZone(boolean inOddEvenZone) {
    this.inOddEvenZone = inOddEvenZone;
    notifyPropertyChanged(BR.inOddEvenZone);
    }

    @Bindable
    public String getCategory() {
    return category;
    }

    public void setCategory(String category) {
    this.category = category;
    notifyPropertyChanged(BR.category);
    }

    @Bindable
    public Boolean getHistory() {
    return isHistory;
    }

    public void setHistory(Boolean history) {
    isHistory = history;
    notifyPropertyChanged(BR.history);
    }

    @Override
    public int describeContents() {
    return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(id);
    dest.writeString(address);
    dest.writeDouble(latitude);
    dest.writeDouble(longitude);
    dest.writeString(icon);
    dest.writeString(title);
    dest.writeByte((byte) (inTrafficZone ? 1 : 0));
    dest.writeByte((byte) (inOddEvenZone ? 1 : 0));
    dest.writeString(category);
    dest.writeByte((byte) (isHistory == null ? 0 : isHistory ? 1 : 2));
    }


    public LatLng getLocationAsLatlng(){return new LatLng(getLatitude() , getLongitude());}
    }









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I developed an Android app and using room database.
      When U install the app for the first time, the app crashes, and the exception is



      Fatal Exception: android.database.sqlite.SQLiteException
      index index_LocationHistoryBean_address already exists (code 1): , while compiling: CREATE INDEX `index_LocationHistoryBean_address` ON `LocationHistoryBean` (`address`)


      My dao file is



      @Entity(indices = {@Index("address") , @Index("title")})
      public class LocationHistoryBean extends BaseObservable implements Parcelable {
      @PrimaryKey(autoGenerate = true)
      private int id;
      private String address;
      private double latitude;
      private double longitude;
      private Date cacheDate;
      private String icon;
      private String title;
      private boolean inTrafficZone;
      private boolean inOddEvenZone;
      private String category;
      private Boolean isHistory = false;

      public LocationHistoryBean() {
      }


      protected LocationHistoryBean(Parcel in) {
      id = in.readInt();
      address = in.readString();
      latitude = in.readDouble();
      longitude = in.readDouble();
      icon = in.readString();
      title = in.readString();
      inTrafficZone = in.readByte() != 0;
      inOddEvenZone = in.readByte() != 0;
      category = in.readString();
      byte tmpIsHistory = in.readByte();
      isHistory = tmpIsHistory == 0 ? null : tmpIsHistory == 1;
      }

      public static final Creator<LocationHistoryBean> CREATOR = new Creator<LocationHistoryBean>() {
      @Override
      public LocationHistoryBean createFromParcel(Parcel in) {
      return new LocationHistoryBean(in);
      }

      @Override
      public LocationHistoryBean newArray(int size) {
      return new LocationHistoryBean[size];
      }
      };

      public int getId() {
      return id;
      }

      public void setId(int id) {
      this.id = id;
      }

      @Bindable
      public String getAddress() {
      return address;
      }

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

      @Bindable
      public double getLatitude() {
      return latitude;
      }

      public void setLatitude(double latitude) {
      this.latitude = latitude;
      notifyPropertyChanged(BR.latitude);
      }

      @Bindable
      public double getLongitude() {
      return longitude;
      }

      public void setLongitude(double longitude) {
      this.longitude = longitude;
      notifyPropertyChanged(BR.longitude);
      }


      public Date getCacheDate() {
      return cacheDate;
      }

      public void setCacheDate(Date cacheDate) {
      this.cacheDate = cacheDate;
      }

      @Bindable
      public String getIcon() {
      return icon;
      }

      public void setIcon(String icon) {
      this.icon = icon;
      notifyPropertyChanged(BR.icon);
      }

      @Bindable
      public String getTitle() {
      return title;
      }

      public void setTitle(String title) {
      this.title = title;
      notifyPropertyChanged(BR.title);
      }

      @Bindable
      public boolean isInTrafficZone() {
      return inTrafficZone;
      }

      public void setInTrafficZone(boolean inTrafficZone) {
      this.inTrafficZone = inTrafficZone;
      notifyPropertyChanged(BR.inTrafficZone);
      }

      @Bindable
      public boolean isInOddEvenZone() {
      return inOddEvenZone;
      }

      public void setInOddEvenZone(boolean inOddEvenZone) {
      this.inOddEvenZone = inOddEvenZone;
      notifyPropertyChanged(BR.inOddEvenZone);
      }

      @Bindable
      public String getCategory() {
      return category;
      }

      public void setCategory(String category) {
      this.category = category;
      notifyPropertyChanged(BR.category);
      }

      @Bindable
      public Boolean getHistory() {
      return isHistory;
      }

      public void setHistory(Boolean history) {
      isHistory = history;
      notifyPropertyChanged(BR.history);
      }

      @Override
      public int describeContents() {
      return 0;
      }

      @Override
      public void writeToParcel(Parcel dest, int flags) {
      dest.writeInt(id);
      dest.writeString(address);
      dest.writeDouble(latitude);
      dest.writeDouble(longitude);
      dest.writeString(icon);
      dest.writeString(title);
      dest.writeByte((byte) (inTrafficZone ? 1 : 0));
      dest.writeByte((byte) (inOddEvenZone ? 1 : 0));
      dest.writeString(category);
      dest.writeByte((byte) (isHistory == null ? 0 : isHistory ? 1 : 2));
      }


      public LatLng getLocationAsLatlng(){return new LatLng(getLatitude() , getLongitude());}
      }









      share|improve this question















      I developed an Android app and using room database.
      When U install the app for the first time, the app crashes, and the exception is



      Fatal Exception: android.database.sqlite.SQLiteException
      index index_LocationHistoryBean_address already exists (code 1): , while compiling: CREATE INDEX `index_LocationHistoryBean_address` ON `LocationHistoryBean` (`address`)


      My dao file is



      @Entity(indices = {@Index("address") , @Index("title")})
      public class LocationHistoryBean extends BaseObservable implements Parcelable {
      @PrimaryKey(autoGenerate = true)
      private int id;
      private String address;
      private double latitude;
      private double longitude;
      private Date cacheDate;
      private String icon;
      private String title;
      private boolean inTrafficZone;
      private boolean inOddEvenZone;
      private String category;
      private Boolean isHistory = false;

      public LocationHistoryBean() {
      }


      protected LocationHistoryBean(Parcel in) {
      id = in.readInt();
      address = in.readString();
      latitude = in.readDouble();
      longitude = in.readDouble();
      icon = in.readString();
      title = in.readString();
      inTrafficZone = in.readByte() != 0;
      inOddEvenZone = in.readByte() != 0;
      category = in.readString();
      byte tmpIsHistory = in.readByte();
      isHistory = tmpIsHistory == 0 ? null : tmpIsHistory == 1;
      }

      public static final Creator<LocationHistoryBean> CREATOR = new Creator<LocationHistoryBean>() {
      @Override
      public LocationHistoryBean createFromParcel(Parcel in) {
      return new LocationHistoryBean(in);
      }

      @Override
      public LocationHistoryBean newArray(int size) {
      return new LocationHistoryBean[size];
      }
      };

      public int getId() {
      return id;
      }

      public void setId(int id) {
      this.id = id;
      }

      @Bindable
      public String getAddress() {
      return address;
      }

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

      @Bindable
      public double getLatitude() {
      return latitude;
      }

      public void setLatitude(double latitude) {
      this.latitude = latitude;
      notifyPropertyChanged(BR.latitude);
      }

      @Bindable
      public double getLongitude() {
      return longitude;
      }

      public void setLongitude(double longitude) {
      this.longitude = longitude;
      notifyPropertyChanged(BR.longitude);
      }


      public Date getCacheDate() {
      return cacheDate;
      }

      public void setCacheDate(Date cacheDate) {
      this.cacheDate = cacheDate;
      }

      @Bindable
      public String getIcon() {
      return icon;
      }

      public void setIcon(String icon) {
      this.icon = icon;
      notifyPropertyChanged(BR.icon);
      }

      @Bindable
      public String getTitle() {
      return title;
      }

      public void setTitle(String title) {
      this.title = title;
      notifyPropertyChanged(BR.title);
      }

      @Bindable
      public boolean isInTrafficZone() {
      return inTrafficZone;
      }

      public void setInTrafficZone(boolean inTrafficZone) {
      this.inTrafficZone = inTrafficZone;
      notifyPropertyChanged(BR.inTrafficZone);
      }

      @Bindable
      public boolean isInOddEvenZone() {
      return inOddEvenZone;
      }

      public void setInOddEvenZone(boolean inOddEvenZone) {
      this.inOddEvenZone = inOddEvenZone;
      notifyPropertyChanged(BR.inOddEvenZone);
      }

      @Bindable
      public String getCategory() {
      return category;
      }

      public void setCategory(String category) {
      this.category = category;
      notifyPropertyChanged(BR.category);
      }

      @Bindable
      public Boolean getHistory() {
      return isHistory;
      }

      public void setHistory(Boolean history) {
      isHistory = history;
      notifyPropertyChanged(BR.history);
      }

      @Override
      public int describeContents() {
      return 0;
      }

      @Override
      public void writeToParcel(Parcel dest, int flags) {
      dest.writeInt(id);
      dest.writeString(address);
      dest.writeDouble(latitude);
      dest.writeDouble(longitude);
      dest.writeString(icon);
      dest.writeString(title);
      dest.writeByte((byte) (inTrafficZone ? 1 : 0));
      dest.writeByte((byte) (inOddEvenZone ? 1 : 0));
      dest.writeString(category);
      dest.writeByte((byte) (isHistory == null ? 0 : isHistory ? 1 : 2));
      }


      public LatLng getLocationAsLatlng(){return new LatLng(getLatitude() , getLongitude());}
      }






      java android android-room






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 12:23









      Zoe

      10.6k73575




      10.6k73575










      asked Nov 11 at 12:22









      Alireza Khosroabadi

      11




      11





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248714%2froom-database-exception-in-first-time-app-install%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248714%2froom-database-exception-in-first-time-app-install%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine