我是一个新手。我的目的是在用户点击一个按钮时产生一个对话框。对话框应该包含用户输入一些数据的可编辑文本区域,以及“创建”和“取消”按钮。我通过XML将按钮链接到了我的方法。然而,每次我运行它的应用程序崩溃,只是说“(X应用程序)已停止”。尝试创建对话框时应用程序崩溃
TerritoryList.java:
/*Called upon when user clicks "Create new territory" button*/
private void creationDialog (View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Buisiness Call Creation");
alert.setMessage("Create a new business call");
//EditText view for user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int whichButton) {
String value = input.getText().toString();
//Do something with the value
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int whichButton) {
//Cancelled. Do nothing
}
});
}
}
这里是我的activity_territory_list.xml(只按钮):
<Button
android:id="@+id/create_new_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="67dp"
android:text="@string/create_territory"
android:onClick="creationDialog" />
我已@ 323go的意见,这里就是我的想法是正确的logcat:
12-22 19:02:11.582: E/AndroidRuntime(2138): FATAL EXCEPTION: main
12-22 19:02:11.582: E/AndroidRuntime(2138): Process: com.example.buninessterritory1, PID: 2138
12-22 19:02:11.582: E/AndroidRuntime(2138): java.lang.IllegalStateException: Could not find a method creationDialog(View) in the activity class com.example.buninessterritory1.TerritoryList for onClick handler on view class android.widget.Button with id 'create_new_call'
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.view.View$1.onClick(View.java:3978)
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.view.View.performClick(View.java:4659)
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.view.View$PerformClick.run(View.java:19462)
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.os.Handler.handleCallback(Handler.java:733)
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.os.Handler.dispatchMessage(Handler.java:95)
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.os.Looper.loop(Looper.java:146)
12-22 19:02:11.582: E/AndroidRuntime(2138): at android.app.ActivityThread.main(ActivityThread.java:5692)
12-22 19:02:11.582: E/AndroidRuntime(2138): at java.lang.reflect.Method.invokeNative(Native Method)
12-22 19:02:11.582: E/AndroidRuntime(2138): at java.lang.reflect.Method.invoke(Method.java:515)
12-22 19:02:11.582: E/AndroidRuntime(2138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
12-22 19:02:11.582: E/AndroidRuntime(2138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
12-22 19:02:11.582: E/AndroidRuntime(2138): at dalvik.system.NativeStart.main(Native Method)
从所提供的代码块中未提出异常 –
此处解决了类似的问题。 试试这个 http://stackoverflow.com/questions/5618664/an-established-connection-was-aborted-by-the-software-in-your-host-machine – Rohit5k2
@ Rohit5k2一点不回答我的问题... –