我正在尝试使用parse.com按照以下代码按照说明将数据发送到解析数据库。当我试图运行apk,并单击按钮时,它给了我这个错误:不幸的是,Appname已经停止
怎么办?我的错是什么?我甚至试过Try和catch语句仍然不起作用。 我要发送的是textview.getText()。toString()到数据库中的“foo”
这是我的代码:
TextView tv;
long ds;
TextView td;
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
public void onCreate() {
Parse.initialize(this, "ID", "ID");
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bx = (Button) findViewById(R.id.bcapture);
Button br = (Button) findViewById(R.id.brefresh);
Button bs = (Button) findViewById(R.id.bsubmit);
bs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "td.getText().toString()");
testObject.saveInBackground();
}
}
}
答案 0 :(得分:0)
据我所知,您尚未初始化TextView。此外,"td.getText().toString()"
应为td.getText().toString()
。
如果您仍有问题,请在您的问题中发布LogCat输出。
TextView tv;
long ds;
TextView td;
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
// not sure you ever call this either
// consider moving it to onCreate of Application http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/
// public void onCreate() {
// Parse.initialize(this, "ID", "ID");
// }
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Parse.initialize(this, "ID", "ID");
setContentView(R.layout.activity_main);
Button bx = (Button) findViewById(R.id.bcapture);
Button br = (Button) findViewById(R.id.brefresh);
Button bs = (Button) findViewById(R.id.bsubmit);
td = (TextView) findViewById(R.id.your_textview);
bs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", td.getText().toString());
testObject.saveInBackground();
}
}
}
答案 1 :(得分:0)
@cYrixmorten这应该以任何一种方式工作。 我猜findViewById返回null,因为你错误地使用了不同布局的id。如果有意义,发布的代码应该有效。你检查过你的ids吗?