Firebase空指针异常(Firebase null pointer exception)

我在firebase中得到空指针异常我知道没有任何值,就像我给出的数据库引用那样但是我希望当生成该值时它会自动显示...只是想得到那个单值每次它在firebase上创建但它在行上给我空指针异常String val = .....

请帮帮我 ...

final DatabaseReference dtt = database.getReference("/trial/trials/");
    dtt.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String val= dataSnapshot.child("myvalue").getValue().toString();
            if(val!=null)
            {
                Log.e("not null------","---------------");
            }else
            {
                Log.e("null------","---------------");
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

请帮帮我......请..


I am getting null pointer exception in firebase I knows that there is not any value like that to which database reference I am giving but I wants that when the value is generated then it will be shown automatically... Just wants to get that single value everytime it is created on the firebase but its giving me null pointer exception on the line String val =.....

Please help me ...

final DatabaseReference dtt = database.getReference("/trial/trials/");
    dtt.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String val= dataSnapshot.child("myvalue").getValue().toString();
            if(val!=null)
            {
                Log.e("not null------","---------------");
            }else
            {
                Log.e("null------","---------------");
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

Please help me.....Please ..


原文:https://stackoverflow.com/questions/38186051
2023-01-21 07:01

满意答案

我传统上做的是使用一个自定义的IUserType类,它将在有问题的枚举和如何持久化之间进行转换。 但是,这需要每个枚举类型的自定义IUserType。


What I've traditionally done is use a custom IUserType class that would translate between the enum in question and how it would be persisted. However, this required a custom IUserType per enum type.

相关问答

更多

流利的nHibernate Automapping不创建复数表名(Fluent nHibernate Automapping not creating Plural table name)

你有没有制定一个惯例 ? public class TableNameConvention : IClassConvention { public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance) { string typeName = instance.EntityType.Name; instance.Table(Inflector.Net.In...

当尝试提交列表<>时,Fluent NHibernate AutoMapping会抛出“StaleStateException”(Fluent NHibernate AutoMapping throws “StaleStateException” when try to Commit a List<>)

在尝试保存order之前,您需要先保存orderItems : session.Save(orderItems[0]); session.Save(orderItems[1]); session.Save(order); Since posting the question, I've learned that the easiest way to get cascading saves is to add a DefaultCascade convention. See the section...

流利的NHibernate DuplicateMappingException与AutoMapping(Fluent NHibernate DuplicateMappingException with AutoMapping)

来自詹姆斯格雷戈里流畅的论坛的解决方案 今晚有一个适当的看看。 基本上,这是AutoImport提到的例外; 当NHibernate被赋予第一个映射时,它看到该实体被命名为完整的程序集限定名,并为短名称创建一个导入(有帮助!),然后当你添加第二个时,它会抱怨这个导入是现在将发生冲突。 所以解决方案是关闭自动导入; 不幸的是,我们在RC中没有办法做到这一点......我刚刚提交了一个修复,增加了在一个约定中更改此功能的能力。 因此,如果您获得最新的二进制文件或源代码,则应该能够在您的附加项目中更改您...

使用流畅的Nhibernate Automapping和Guids / UniqueIdentifier作为主键字段的问题(Issue With Fluent Nhibernate Automapping and Guids / UniqueIdentifiers as Primary Key Fields)

显然,Fluent Nhibernate版本1.0RC和版本1.0存在问题。 但是,如果从SVN主干下载最新版本,那么每件事都可以完美运行。 似乎问题只是代码中的一个错误,现在已经得到纠正。 另外,我应该注意到James Gregory,Paul Batum以及其他人正在积极研究Fluent NHibernate。 该产品发展非常迅速,过去几个月代码发生了重大变化。 Apparently, there was an issue in the Fluent Nhibernate version 1....

流畅的NHibernate AutoMapping SchemaExport - 更改对象模型和保持数据(Fluent NHibernate AutoMapping SchemaExport - Change object model and Keeping Data)

卫生署! 只是用 new SchemaUpdate(config).Execute(false, true); 代替 new SchemaCreate(config).Execute(yadda yadda); Doh! Just use new SchemaUpdate(config).Execute(false, true); instead of new SchemaCreate(config).Execute(yadda yadda);

如何在不自动化的情况下告诉Fluent NHibernate忽略特定属性?(How do I tell Fluent NHibernate to ignore specific properties without automapping?)

所有属性和方法都必须是可覆盖的,以便NHibernate创建动态代理,包括未映射的属性。 这并不意味着NHibernate正在映射您的只读属性,它只需要它们可以覆盖它们以便它可以生成该类的代理。 本文解释了该要求。 All properties and methods must be overridable in order for NHibernate to create dynamic proxies, including unmapped properties. This does not ...

流利NHibernate的自动映射:改变日期时间到时间戳(Fluent NHibernate Automapping: Alter DateTime to Timestamp)

您可以覆盖特定的类。 不知道如何在更一般的水平上做到这一点。 public class AlbumMappingOverride : IAutoMappingOverride<Album> { public void Override(AutoMap<Album> mapping) { mapping.Map(x => x.Created).CustomSqlTypeIs("timestamp"); } } You can override a speci...

流畅的nHibernate与Automapping:如何在关系的“Child”侧设置Inverse(Fluent nHibernate with Automapping: How to set Inverse on “Child” side of relation)

没有直接的语法来使多对一关系成为反向关系。 这有一些原因: 它更自然 并且执行得更好,因为类(Parent)中的引用直接映射到数据库中的外键 因为无论如何它需要在记忆中保持一致(这是你必须关心自己的部分),这没关系。 您可以通过使其无反转并禁止更新Parent属性来欺骗它。 我不知道Fluent是否有可能。 反正我也不会这样做。 这只是在寻找麻烦。 使用XML映射,它看起来像这样: <many-to-one name ="Parent" ... insert="false" update="fa...

流畅的NHibernate自动化问题与2类重新同一类(Fluent NHibernate automapping problem with 2 class refrencing same class)

我转向流利的nhibernate v1.2,现在看来一切正常。 i moved to fluent nhibernate v1.2 , and it seems everything is working fine now.

将EnumTypes与Fluent NHibernate和Automapping一起使用(Using EnumTypes with Fluent NHibernate and Automapping)

我传统上做的是使用一个自定义的IUserType类,它将在有问题的枚举和如何持久化之间进行转换。 但是,这需要每个枚举类型的自定义IUserType。 What I've traditionally done is use a custom IUserType class that would translate between the enum in question and how it would be persisted. However, this required a custom I...

相关文章

更多

java Exception异常处理实例

java异常处理在java异常处理分类说过了,处理他的方式有try catch、继续往外抛或者不做处理 ...

EXT4 Store Load For Gird Exception

Gird Store 自动装载时附加一个参数user,而在pagingtoolbar上点击获取下一页数 ...

EXT4 Store Batch Sync Exception

单条数据删除sync正常,批量删除时循环sync发生异常,不知该如何解决? CONSOLE: PO ...

Guava学习笔记:Optional优雅的使用null

  在我们学习和使用Guava的Optional之前,我们需要来了解一下Java中null。因为,只有 ...

Hive 终端产生的问题 (Failed to start database 'metastore_db', see the next exception for details.)

今天使用Hive的时候遇到一个这样的bug,上网查下原来是个小问题,在此记录下。 FAILED: Er ...

[Hadoop Err] Call to ? failed on local exception: java.net.NoRouteToHostException: No route to host

表现: 如果你 grep datanode 的 log 发现了这个 Error,原文如下: Hadoo ...

Java基础:异常的限制

1 package cn.tju.thinkinginjava.exception; 2 3 @Su ...

Java 异常处理

Java 异常处理 异常是程序中的一些错误,但并不是所有的错误都是异常,并且错误有时候是可以避免 ...

List用完后需要赋null吗

从数据库查询N条记录放在List集合中,然后通过request对象返回给页面,通过循环遍历将List中 ...

最新问答

更多

您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)

将diff文件复制到存储库的根目录,然后执行以下操作: git apply yourcoworkers.diff 有关apply命令的更多信息, apply 见其手册页 。 顺便说一下:一个更好的方法是通过文件交换整个提交文件是发送者上的命令git format-patch ,然后在接收器上加上git am ,因为它也传送作者信息和提交信息。 如果修补程序应用程序失败,并且生成diff的提交实际上在您的备份中,则可以使用尝试在更改中合并的apply程序的-3选项。 它还适用于Unix管道,如下

将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)

尝试将第二行更改为snprintf(buf1, sizeof buf1, "%.2f", balance1); 。 另外,为什么要声明用该特定表达式分配缓冲区的存储量? EDIT @LưuVĩnhPhúc在下面的评论中提到我的原始答案中的格式说明符将舍入而不是截断,因此根据如何在不使用C舍入的情况下截断小数,您可以执行以下操作: float balance = 200.56866; int tmp = balance1 * 100; float balance1 = tmp / 100.0; c

OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)

这是简单的解决方案 在你需要写的控制器中 BackendMenu::setContext('Archetypics.Team', 'website', 'team'); 请参阅https://octobercms.com/docs/backend/controllers-views-ajax#navigation-context BackendMenu::setContext('Author.Plugin name', 'Menu code', 'Sub menu code'); 你需要在r

页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)

每当发出请求时ASP都会创建一个新的Page对象,并且一旦它将响应发送回用户就不会保留对该Page对象的引用,因此只要你找不到某种方法来保持生命自己引用该Page对象后,一旦发送响应, Page和只能通过该页面访问的所有对象才有资格进行垃圾回收。 ASP creates a new Page object whenever a request is made, and it does not hold onto the reference to that Page object once it

codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)

要在生产服务器中调试这个,你可以临时放 error_reporting(E_ALL); 并查看有哪些其他错误阻止正确的重定向。 您还应该检查生产服务器发送的响应标头。 它是否具有“缓存”,是否需要重新验证标头等 to debug this in production server, you can temporary put error_reporting(E_ALL); and see what other errors are there that prevents the proper

在计算机拍照在哪里进入

打开娥的电脑.在下面找到视频设备点击进去就可以了...

使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)

你是对的。 第一次输入后,换行符将保留在输入缓冲区中。 第一次读取后尝试插入: cin.ignore(); // to ignore the newline character 或者更好的是: //discards all input in the standard input stream up to and including the first newline. cin.ignore(numeric_limits::max(), '\n'); 您必须为#inc

No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)

for (int k = 0; k > 10; k++) { System.out.println(k); } k不大于10,所以循环将永远不会执行。 我想要什么是k<10 ,不是吗? for (int k = 0; k < 10; k++) { System.out.println(k); } for (int k = 0; k > 10; k++) { System.out.println(k); } k is not greater than 10, so loop

单页应用程序:页面重新加载(Single Page Application: page reload)

优点是不注销会避免惹恼用户,以至于他们会想要杀死你:-)。 说真的,如果每次刷新页面时应用程序都会将我注销(或者在新选项卡中打开一个链接),我再也不会使用该应用程序了。 好吧,不要这样做。 确保身份验证令牌存储在刷新后的某个位置,即不在某些JS变量中,而是存储在cookie或本地存储中。 The advantage is that not logging off will avoid pissing off your users so much that they'll want to kill

在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)

EXECUTE IMMEDIATE 'SELECT '||field_val_temp ||' FROM tableb WHERE function_id = :func_val AND rec_key = :rec_key' INTO field_val USING 'STDCUSAC' , yu.rec_key; 和, EXECUTE IMMEDIATE 'UPDATE tablec SET field_val_'||i||' = :field_val' USI