3

在嘗試做下面的教程:使用Android工作室AndroidStudio/gradle這個找不到javax.persistence包

https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial/

,我創建了一個Android Studio項目,並與下面的內容添加CheckIn.java類:

import java.util.Date; 
import com.google.appengine.api.datastore.Key; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 

@Entity 
public class CheckIn { 
@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private java.security.Key key; 
private String placeId; 
private String userEmail; 
private Date checkinDate; 

public java.security.Key getKey() { 
    return key; 
} 

public String getPlaceId() { 
    return placeId; 
} 
public void setPlaceId(String placeId) { 
    this.placeId = placeId; 
} 

public String getUserEmail() { 
    return userEmail; 
} 
public void setUserEmail(String userEmail) { 
    this.userEmail = userEmail; 
} 

public Date getCheckinDate() { 
    return checkinDate; 
} 
public void setCheckinDate(Date date) { 
    checkinDate = date; 
} 

}

但是當我嘗試建立該項目在我的Android Studion/gradle這個項目,我得到以下錯誤:

Error:(6, 25) error: package javax.persistence does not exist 
Error:(7, 25) error: package javax.persistence does not exist 
Error:(8, 25) error: package javax.persistence does not exist 
Error:(9, 25) error: package javax.persistence does not exist 
Error:(11, 2) error: cannot find symbol class Entity 
Error:(14, 6) error: cannot find symbol class Id 
Error:(15, 6) error: cannot find symbol class GeneratedValue 
Error:(6, 25) error: package javax.persistence does not exist 
Error:(7, 25) error: package javax.persistence does not exist 
Error:(8, 25) error: package javax.persistence does not exist 
Error:(9, 25) error: package javax.persistence does not exist 
Error:(11, 2) error: cannot find symbol class Entity 
Error:(14, 6) error: cannot find symbol class Id 
Error:(15, 6) error: cannot find symbol class GeneratedValue 
+0

我的猜測是,您正嘗試將GAE程序構建爲Android應用程序,因爲Android沒有列出您錯誤中列出的內容。 – CommonsWare 2014-12-10 21:36:42

回答

2

當我加入這讓固定:

compile group: 'javax.persistence', name: 'persistence-api', version: '1.0' 

我gradle這個依賴。如所述here

+0

你已經救了我的一天,非常感謝! – RobertoAllende 2015-09-01 20:18:43

+0

你已經保存了我的一天,非常感謝! – RobertoAllende 2015-09-01 20:19:07

+0

謝謝達斯。您可以將您的答案標記爲已接受。 – 2016-09-16 05:40:28