所以我收到一个我无法弄清楚的错误。button
我在我的内部单击 afragment
以启动 adialog
并且我的程序崩溃了。它在我的 logcat 中说我没有button
id 而没有method
. handler
我显然确实有这些东西,否则我不会感到困惑。我觉得我疲倦的眼睛缺少一些明显的东西。这是.java
,.xml
和logcat
任何帮助表示赞赏。
.java
public class Store_Fragment extends Fragment {
View view;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_store, container, false);
return view;
}
public void syncHandler (View view) {
DialogFragment newFragment = new StoreDialog_Fragment();
newFragment.show(getFragmentManager(), "correct store?");
}
}
.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/store_number"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/storeNum_input_ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="8"
android:hint="@string/store_hint" />
<Button
android:id="@+id/sync_button_ID"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="syncHandler"
android:text="@string/sync" />
</TableRow>
</LinearLayout>
日志猫
05-07 06:38:34.143: W/dalvikvm(1579): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-07 06:38:34.183: E/AndroidRuntime(1579): FATAL EXCEPTION: main
05-07 06:38:34.183: E/AndroidRuntime(1579): java.lang.IllegalStateException: Could not find a method syncHandler(View) in the activity class
com.facilitysolutionsinc.trackflex.Main for onClick handler on view class android.widget.Button with id 'sync_button_ID'
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.view.View$1.onClick(View.java:3586)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.view.View.performClick(View.java:4204)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.view.View$PerformClick.run(View.java:17355)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.os.Handler.handleCallback(Handler.java:725)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.os.Handler.dispatchMessage(Handler.java:92)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.os.Looper.loop(Looper.java:137)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-07 06:38:34.183: E/AndroidRuntime(1579): at java.lang.reflect.Method.invokeNative(Native Method)
05-07 06:38:34.183: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Method.java:511)
05-07 06:38:34.183: E/AndroidRuntime(1579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-07 06:38:34.183: E/AndroidRuntime(1579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-07 06:38:34.183: E/AndroidRuntime(1579): at dalvik.system.NativeStart.main(Native Method)
05-07 06:38:34.183: E/AndroidRuntime(1579): Caused by: java.lang.NoSuchMethodException: syncHandler [class android.view.View]
05-07 06:38:34.183: E/AndroidRuntime(1579): at java.lang.Class.getConstructorOrMethod(Class.java:460)
05-07 06:38:34.183: E/AndroidRuntime(1579): at java.lang.Class.getMethod(Class.java:915)
05-07 06:38:34.183: E/AndroidRuntime(1579): at android.view.View$1.onClick(View.java:3579)
05-07 06:38:34.183: E/AndroidRuntime(1579): ... 11 more