我不知道这是怎么回事。我曾尝试上网。当我运行它时,我的应用程序崩溃了。实施点击列表器时问题仍然存在。我需要一些专家的帮助...我可以使用任何建议吗?
public class Update extends AppCompatActivity {
String tempobj;
EditText name;
Button s;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update);
name = (EditText) findViewById(R.id.rightupname);
RadioGroup rg = (RadioGroup) findViewById(R.id.radservgrp);
String radiovalue = ((RadioButton) findViewById(rg.getCheckedRadioButtonId())).getText().toString();
Toast.makeText(getApplicationContext(),
radiovalue, Toast.LENGTH_LONG).show();
ParseQuery<ParseObject> query = ParseQuery.getQuery("serviceop");
query.whereEqualTo("no", "6382551203");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
for (ParseObject object : objects) {
String one = object.getString("name");
name.setText(one);
}
} else {
Log.d("no data", "left or right");
}
} else {
Log.d("awserror", "left or right");
}
}
});
}
public void onSave(View view) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("serviceop");
query.getInBackground(makeobj("6382551203"), new GetCallback<ParseObject>() {
public void done(ParseObject Grillen, ParseException eg) {
if (eg == null) {
Grillen.put("name", name.getText().toString());
Grillen.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
Log.d("MyApp", "Successfully saved!");
} else {
e.printStackTrace();
}
}
});
} else {
eg.printStackTrace();
}
}
});
Log.d("sdas","sda");
}
public String makeobj(String nos) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("serviceop");
query.whereEqualTo("no",nos);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
for (ParseObject object : objects) {
tempobj = object.getObjectId();
}
} else {
Log.d("no data","left or right");
}
} else {
Log.d("awserror","left or right");
}
}
});
return tempobj;
}
}
我的日志猫:
08-27 19:55:09.354 5672-5672/com.parse.starter E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.parse.starter, PID: 5672
java.lang.IllegalStateException: Could not find method onSave(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'saveactive'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:325)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Update">
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sname1"
android:text="Name"
android:layout_weight="3"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/rightupname"
android:layout_weight="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sname2"
android:text="Service type"
android:layout_weight="3"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:id="@+id/radservgrp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_weight="3"
>
<RadioButton
android:id="@+id/radcar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Car" />
<RadioButton
android:id="@+id/radbike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sname3"
android:text="Fuel backup"
android:layout_weight="3"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:id="@+id/radfuelgrp"
android:orientation="horizontal"
android:layout_weight="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radfuelyes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes"
android:checked="true" />
<RadioButton
android:id="@+id/radfuelno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sname4"
android:text="Location"
android:layout_weight="3"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="Change work location"
android:layout_weight="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Pro membership"
android:textStyle="bold" />
<Button
android:layout_marginTop="10dp"
android:id="@+id/activepro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="active pro membership" />
</LinearLayout>
<Button
android:id="@+id/saveactive"
android:text="save"
android:onClick="onSave"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
答案 0 :(得分:0)
我认为您的Activity
需要使用onClick()
方法。尝试添加此内容:
public void onSave(View view) {
//your code goes here
}