Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 库项目中XML中的空指针异常处理按钮_Android_Xml_Nullpointerexception - Fatal编程技术网

Android 库项目中XML中的空指针异常处理按钮

Android 库项目中XML中的空指针异常处理按钮,android,xml,nullpointerexception,Android,Xml,Nullpointerexception,我试图通过XML在我的库项目中创建一个自定义对话框 以下是XML文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:

我试图通过XML在我的库项目中创建一个自定义对话框

以下是XML文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/tenlogix" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="25dp" >

        <Button
            android:id="@+id/likeitb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/likeitd" />

        <Button
            android:id="@+id/dontlikeitb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/dontliked" />

        <Button
            android:id="@+id/notnowb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/notnowd" />
    </LinearLayout>

</RelativeLayout>
如果我没有设置类似于按钮的单击侦听器,则会显示对话框,但当我尝试在其上设置单击侦听器时。它给了我一个空指针异常。 我找不到解决这个问题的办法。当我尝试访问时,
LikeIt
按钮为空。 我没有任何同名资源。请帮忙

参考
mAct
是使用库项目的另一个项目的活动。 期待着一个积极和快速的反应。 谢谢。

换成

 Button LikeIt = (Button) feed_back_dialog.findViewById(R.id.likeitb);
假设对话框布局有一个id为likeitb的按钮

其他观点也是如此

 Button DontLikeIt = (Button) feed_back_dialog.findViewById(R.id.dontlikeitb);
 Button NotNow = (Button) feed_back_dialog.findViewById(R.id.notnowb);
findViewById
查找具有当前布局中提到的id的视图。因此,您需要使用dialog对象来初始化视图,因为您将布局的内容设置为对话框。属于对话框的视图更改为

 Button LikeIt = (Button) feed_back_dialog.findViewById(R.id.likeitb);
假设对话框布局有一个id为likeitb的按钮

其他观点也是如此

 Button DontLikeIt = (Button) feed_back_dialog.findViewById(R.id.dontlikeitb);
 Button NotNow = (Button) feed_back_dialog.findViewById(R.id.notnowb);
findViewById
查找具有当前布局中提到的id的视图。因此,您需要使用dialog对象来初始化视图,因为您将布局的内容设置为对话框。属于对话框的视图更改为

 Button LikeIt = (Button) feed_back_dialog.findViewById(R.id.likeitb);
假设对话框布局有一个id为likeitb的按钮

其他观点也是如此

 Button DontLikeIt = (Button) feed_back_dialog.findViewById(R.id.dontlikeitb);
 Button NotNow = (Button) feed_back_dialog.findViewById(R.id.notnowb);
findViewById
查找具有当前布局中提到的id的视图。因此,您需要使用dialog对象来初始化视图,因为您将布局的内容设置为对话框。属于对话框的视图更改为

 Button LikeIt = (Button) feed_back_dialog.findViewById(R.id.likeitb);
假设对话框布局有一个id为likeitb的按钮

其他观点也是如此

 Button DontLikeIt = (Button) feed_back_dialog.findViewById(R.id.dontlikeitb);
 Button NotNow = (Button) feed_back_dialog.findViewById(R.id.notnowb);

findViewById
查找具有当前布局中提到的id的视图。因此,您需要使用dialog对象来初始化视图,因为您将布局的内容设置为对话框。视图属于该对话框

您可以这样展开布局。然后使用膨胀视图,您可以获得按钮控件。[我希望mAct是一个活动对象]

    LayoutInflater li = LayoutInflater.from(mAct);
    View inflatedView = li.inflate(R.layout.ratedialog, null, false);

    //button initialization
    Button LikeIt = (Button) inflatedView .findViewById(R.id.likeitb);
    Button DontLikeIt = (Button) inflatedView .findViewById(R.id.dontlikeitb);
    Button NotNow = (Button) inflatedView .findViewById(R.id.notnowb);

你能做的就是像这样膨胀布局。然后使用膨胀视图,您可以获得按钮控件。[我希望mAct是一个活动对象]

    LayoutInflater li = LayoutInflater.from(mAct);
    View inflatedView = li.inflate(R.layout.ratedialog, null, false);

    //button initialization
    Button LikeIt = (Button) inflatedView .findViewById(R.id.likeitb);
    Button DontLikeIt = (Button) inflatedView .findViewById(R.id.dontlikeitb);
    Button NotNow = (Button) inflatedView .findViewById(R.id.notnowb);

你能做的就是像这样膨胀布局。然后使用膨胀视图,您可以获得按钮控件。[我希望mAct是一个活动对象]

    LayoutInflater li = LayoutInflater.from(mAct);
    View inflatedView = li.inflate(R.layout.ratedialog, null, false);

    //button initialization
    Button LikeIt = (Button) inflatedView .findViewById(R.id.likeitb);
    Button DontLikeIt = (Button) inflatedView .findViewById(R.id.dontlikeitb);
    Button NotNow = (Button) inflatedView .findViewById(R.id.notnowb);

你能做的就是像这样膨胀布局。然后使用膨胀视图,您可以获得按钮控件。[我希望mAct是一个活动对象]

    LayoutInflater li = LayoutInflater.from(mAct);
    View inflatedView = li.inflate(R.layout.ratedialog, null, false);

    //button initialization
    Button LikeIt = (Button) inflatedView .findViewById(R.id.likeitb);
    Button DontLikeIt = (Button) inflatedView .findViewById(R.id.dontlikeitb);
    Button NotNow = (Button) inflatedView .findViewById(R.id.notnowb);

只需使用“反馈”对话框更改这些代码行中的
mAct
“反馈”对话框是您当前的布局

Button LikeIt=(Button)mAct.findviewbyd(R.id.likeitb);
按钮DontLikeIt=(按钮)mAct.findViewById(R.id.dontlikeitb);
按钮NotNow=(按钮)mAct.findViewById(R.id.notnowb)

一定是这样

Button LikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.likeitb);
Button DontLikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.dontlikeitb);

Button NotNow=(Button)feed_back_dialog.findviewbyd(R.id.notnowb)

只需使用
反馈对话框在这些代码行中更改
mAct
“反馈”对话框是您当前的布局

Button LikeIt=(Button)mAct.findviewbyd(R.id.likeitb);
按钮DontLikeIt=(按钮)mAct.findViewById(R.id.dontlikeitb);
按钮NotNow=(按钮)mAct.findViewById(R.id.notnowb)

一定是这样

Button LikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.likeitb);
Button DontLikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.dontlikeitb);

Button NotNow=(Button)feed_back_dialog.findviewbyd(R.id.notnowb)

只需使用
反馈对话框在这些代码行中更改
mAct
“反馈”对话框是您当前的布局

Button LikeIt=(Button)mAct.findviewbyd(R.id.likeitb);
按钮DontLikeIt=(按钮)mAct.findViewById(R.id.dontlikeitb);
按钮NotNow=(按钮)mAct.findViewById(R.id.notnowb)

一定是这样

Button LikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.likeitb);
Button DontLikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.dontlikeitb);

Button NotNow=(Button)feed_back_dialog.findviewbyd(R.id.notnowb)

只需使用
反馈对话框在这些代码行中更改
mAct
“反馈”对话框是您当前的布局

Button LikeIt=(Button)mAct.findviewbyd(R.id.likeitb);
按钮DontLikeIt=(按钮)mAct.findViewById(R.id.dontlikeitb);
按钮NotNow=(按钮)mAct.findViewById(R.id.notnowb)

一定是这样

Button LikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.likeitb);
Button DontLikeIt=(Button)feed\u back\u dialog.findviewbyd(R.id.dontlikeitb);

Button NotNow=(Button)feed_back_dialog.findviewbyd(R.id.notnowb)

我们可以查看堆栈跟踪吗?问题已经解决,这是一个编程错误。Mohsin帮我修好了。我们能看看堆栈跟踪吗?问题解决了,这是一个编程错误。Mohsin帮我修好了。我们能看看堆栈跟踪吗?问题解决了,这是一个编程错误。Mohsin帮我修好了。我们能看看堆栈跟踪吗?问题解决了,这是一个编程错误。莫辛帮我修的。