java.lang.IllegalArgumentException:找不到片段

时间:2016-01-20 07:50:55

标签: android android-fragments illegalargumentexception

我正在开发一个Android聊天消息。我有一个包含imageview的活动。点击imageview,将打开一个对话框。对话框的布局是:

emoji.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/emojicon"
        android:layout_width="match_parent"
        android:layout_height="50dp" />

</LinearLayout>

处理图片的代码点击

 imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            hideKeyboard();  // hiding the keyboard
           // showEmojiPopUp(!showEmoji);
            Dialog dialog = new Dialog(ChatActivity.this);
            dialog.setContentView(R.layout.emoji);
            getSupportFragmentManager().beginTransaction().replace(R.id.emojicon, EmojiconsFragment.newInstance(false)).commit();
            dialog.show();
        }
    });

在单击图像视图时,我正在创建一个包含FrameLayout的对话框.Here EmojiFragment将创建一个表情符号面板,emoji.xml中的FrameLayout将被EmojiFragment替换。但是在这里我得到了下面提到的错误:

java.lang.IllegalArgumentException: No view found for id 0x7f0c004b (com.almabay.almachat:id/emojicon) for fragment EmojiconsFragment{429a7f68 #1 id=0x7f0c004b}
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:5096)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
        at dalvik.system.NativeStart.main(Native Method)

请帮我解决。

1 个答案:

答案 0 :(得分:0)

这是显示自定义对话的示例。自定义是xml布局

final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom);
            dialog.setTitle("Title...");

            // set the custom dialog components - text, image and button
            TextView text = (TextView) dialog.findViewById(R.id.text);
            text.setText("Android custom dialog example!");
            ImageView image = (ImageView) dialog.findViewById(R.id.image);
            image.setImageResource(R.drawable.ic_launcher);

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            // if button is clicked, close the custom dialog
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            dialog.show();
          }

我希望这会有所帮助。