我一直在關注玩框架1.1.1 YABE添加評論教程,然後結束了這個問題。幫助無法調用播放框架控制器中的非靜態方法模型?
的問題是這樣的錯誤信息出現
編譯錯誤
文件/app/controllers/Application.java無法編譯。提出錯誤是:不能讓從類型的靜態引用非靜態方法addComment(字符串,字符串,布爾值,字符串)Permainan
這是我Application.java控制器內容
package controllers;
import play.*;
import play.mvc.*;
import play.libs.*;
import java.util.*;
import models.*;
public class Application extends Controller {
public static void permainanKomentar(Long permainanId, String author, String email, boolean showEmail, String content) {
Permainan permainan = Permainan.findById(permainanId);
Permainan.addComment(author, email, showEmail, content); >> (this line)
show(permainanId);
}
}
和Permainan.java模型
package models;
import java.util.*;
import javax.persistence.*;
import play.data.binding.*;
import play.db.jpa.*;
import play.data.validation.*;
@Entity
public class Permainan extends Model {
@Required
public String nama;
@Required
@MaxSize(5000)
@Lob
public String deskripsi;
@MaxSize(2000)
@Lob
public String material;
@MaxSize(4000)
@Lob
public String syair;
public Date postedAt;
@OneToMany(mappedBy="permainan", cascade=CascadeType.ALL)
public List<Komentar> komentar;
@ManyToMany(cascade=CascadeType.PERSIST)
public Set<Tag> tags;
public Permainan(String nama, String deskripsi, String material, String syair) {
this.komentar = new ArrayList<Komentar>();
this.tags = new TreeSet<Tag>();
this.nama = nama;
this.deskripsi = deskripsi;
this.material = material;
this.syair = syair;
this.postedAt = new Date();
}
public Permainan addComment(String author, String email, boolean showEmail, String content) {
Komentar newKomentar = new Komentar(this, author, email, showEmail, content).save();
this.komentar.add(newKomentar);
this.save();
return this;
}
}
嗨,大家好,這是我的錯誤 Permainan.addComment(author,email,showEmail,content); >>(this line) 肩膀被改爲 permainan.addComment(author,email,showEmail,content); >>(這一行) – angga 2011-05-29 03:27:08