2016-05-13 12 views
1

これは、自分のレルムデータベースに保存するクラスです。アプリをビルドするときには"Error:A default public constructor with no argument must be declared if a custom constructor is declared."が投げられますが、レルムを使用する前は問題ありませんでした。デフォルトのコンストラクタは必要ありませんでした。また、私はそのような警告を受けました:警告:(18、1)Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.エラーを解決するには?Project Lombokをインストールした後にRealmObjectを処理中にエラーが発生しました

import android.content.Context; 
import android.support.annotation.NonNull; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 

import java.util.ArrayList; 

import io.realm.RealmObject; 
import kg.zuber.aqe_android.R; 
import lombok.Data; 
import lombok.Getter; 

@Data 
public class Measure extends RealmObject { 
    @Getter 
    int id; 
    @NonNull 
    String name; 
    @Getter 
    @NonNull 
    String slug; 

    public Measure(int id, @NonNull String name, @NonNull String slug) { 
     super(); 
     this.id = id; 
     this.name = name; 
     this.slug = slug; 
    } 

    @Override 
    public String toString() { 
     return this.name; 
    } 

    public static class MeasureAdapter extends ArrayAdapter<Measure> { 
     private final Context mContext; 
     private ArrayList<Measure> measures; 

     public MeasureAdapter(Context context, ArrayList<Measure> mMeasures) { 
      super(context, R.layout.blue_spinner_item, mMeasures); 
      this.mContext = context; 
      measures = mMeasures; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      Measure device = measures.get(position); 
      if (convertView == null) { 
       convertView = LayoutInflater.from(getContext()) 
         .inflate(R.layout.blue_spinner_item, parent, false); 
      } 
      TextView textView = (TextView)convertView.findViewById(R.id.text); 
      textView.setText(device.name); 
      return convertView; 
     } 
    } 
} 
+0

Realmでは、デフォルトのコンストラクタが長い間要件として使用されていました。追加すると、エラーが修正されます。この警告は、何とかロンボクに関係しているようだ。 –

答えて

3

の代わりにのみ@Dataは、次のように使用することができます。

@Data 
@AllArgsConstructor 
@NoArgsConstructor 
@EqualsAndHashCode(callSuper=false) 

そして手書きのコンストラクタを削除します。

また、@Getter注釈は必要ありません。フィールドをNULLチェックするには、@lombok.NonNullを使用するか、android.support.annotation.NonNullの代わりにインポートする必要があります。

開示:私はロンボクの開発者です。

関連する問題