所以我正在尝试使用setText函数将文本从parseobject添加到TextView。 我已经将我想添加的内容转换为字符串,但程序一直在崩溃,我没有找到其他人遇到这个问题所以我想我会发布在这里。
无论如何,这里是有问题的代码:
String text = (String)object.get("Text");
Log.d("Recept", "text: " + text);
int time = (int)object.get("Time");
Log.d("Recept", "time: " + time);
ParseFile image = (ParseFile)object.get("Picture");
TextView recipeText = (TextView) findViewById(R.id.recipeText);
recipeText.setText(text);
TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
recipeTime.setText(time);
Log.d("Recept", "The text was fine");
ParseImageView recipeImage = (ParseImageView) findViewById(R.id.recipeImage);
recipeImage.setParseFile(image);
日志记录所有内容,“文本很好”并返回我想要添加的字符串,所以我知道在此之前代码没有任何可疑之处。
我将在此之前添加部分,以防万一:
public class RecipePage extends AppCompatActivity{
//ListView lv;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
//ParseQueryAdapter<ParseObject> mainAdapter;
Log.d("Recept", "Recipe on it's way!");
super.onCreate(savedInstanceState);
setContentView(R.layout.recipe_page);
Log.d("Recept", "I made it in!");
//int key2 = 2;
String key = getIntent().getStringExtra("key");
String label = getIntent().getStringExtra("Title");
Log.d("Recept", "The found key was: " + key);
//lv = (ListView) findViewById(R.id.listView2);
setTitle(label);
//Begin search
ParseQuery<ParseObject> query = ParseQuery.getQuery("Recept");
query.getInBackground(key, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
Log.d("Recept", "I got this far");
if (e == null) {
Log.d("Recept", "I'm happy!");
} else {
Log.d("Recept", "Error, something went wrong: " + e);
}
String text = (String)object.get("Text");
Log.d("Recept", "text: " + text);
int time = (int)object.get("Time");
Log.d("Recept", "time: " + time);
ParseFile image = (ParseFile)object.get("Picture");
TextView recipeText = (TextView) findViewById(R.id.recipeText);
recipeText.setText(text);
TextView recipeTime = (TextView) findViewById(R.id.recipeTime);
recipeTime.setText(time);
Log.d("Recept", "The text was fine");
ParseImageView recipeImage = (ParseImageView) findViewById(R.id.recipeImage);
recipeImage.setParseFile(image);
}
});
对不起日志,使用它们尝试进行故障排除。
答案 0 :(得分:0)
所以我发现问题是
recipeTime.setText(time);
不起作用,因为我试图传递一个int应该是一个字符串。
而是写recipeTime.setText(time + "");
。 :)
答案 1 :(得分:0)
替换 String text =(String)object.get(“Text”);
要 String text = object.getString(“Text”);
我希望这会对你有所帮助。