如何在 Google App Engine 中正确初始化/定义文本 Class 的对象?
How do I properly initialize / define an object of the Text Class in Google App Engine?
我正在为一个项目使用 Google App 引擎。它使用的 classes 之一称为 "Text" class。 (Link 文档在此处:https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Text)
我无法弄清楚如何正确初始化变量,因为我使用的参数之一要求我传入一个 Text 对象,无论我做什么,我都只能用 null 初始化它,这当然是创建一个空指针错误。
我试过以下但没有成功:
//Code
Text text = new Text(); //Cannot be initialized this way
Text text; //This will work, but it will say it is not initialized and will create a null pointer
Text text = "stuff"; //Nope
Text text = newInstance(); //Nope
我想要完成的是用 null 以外的东西初始化对象,然后用它把它传递给一个单独的方法。
也许我读错了文档,只是需要一双新的眼睛。有人对这些 Text class 对象有任何经验吗?
在您链接的文档中,构造函数需要一个字符串。
所以你必须这样尝试:
Text text = new Text("stuff");
我正在为一个项目使用 Google App 引擎。它使用的 classes 之一称为 "Text" class。 (Link 文档在此处:https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Text)
我无法弄清楚如何正确初始化变量,因为我使用的参数之一要求我传入一个 Text 对象,无论我做什么,我都只能用 null 初始化它,这当然是创建一个空指针错误。
我试过以下但没有成功:
//Code
Text text = new Text(); //Cannot be initialized this way
Text text; //This will work, but it will say it is not initialized and will create a null pointer
Text text = "stuff"; //Nope
Text text = newInstance(); //Nope
我想要完成的是用 null 以外的东西初始化对象,然后用它把它传递给一个单独的方法。
也许我读错了文档,只是需要一双新的眼睛。有人对这些 Text class 对象有任何经验吗?
在您链接的文档中,构造函数需要一个字符串。 所以你必须这样尝试:
Text text = new Text("stuff");