您好我正在编写应用程序并使用firebase登录后获取用户的显示名称但是我只在api 27 java.lang.String com.google.firebase.auth.FirebaseUser.getDisplayName()' on a null object reference
用户在发生这种情况时登录
我的代码是
String displayname = FirebaseAuth.getInstance().getCurrentUser().getDisplayName().toString();
Toast.makeText(getApplicationContext(),"Logged in as "+ displayname, Toast.LENGTH_LONG).show();
答案 0 :(得分:0)
FirebaseAuth.getInstance().getCurrentUser()会返回空的FirebaseUser。您在该空引用上调用<div style="background-color:black">
<div class="dropdown1">
<button class="dropbtn1">REFRIGERANTS</button>
<div id="myDropdown1" class="dropdown1-content" style="text-align:left;">
<a href="#">Refrigerants</a><br>
<a href="#">Lubricants</a><br>
<a href="#">Treatments</a><br>
<a href="#">R-134A Products</a><br>
</div>
</div>
<div class="dropdown1">
<button class="dropbtn1">FLUIDS</button>
<div id="myDropdown2" class="dropdown1-content" style="text-align:left">
<a href="#">Brake Fluid</a><br>
<a href="#">Automatic Transmission Fluid</a><br>
<a href="#">Power Steering Fluid</a><br>
</div>
</div>
<div class="dropdown1">
<button class="dropbtn1">ADDITIVES</button>
<div id="myDropdown3" class="dropdown1-content" style="text-align:left">
<a href="#">Fuel Additives</a><br>
<a href="#">Oil Additives</a>
</div>
</div>
<div class="dropdown1">
<button class="dropbtn1">CLEANERS</button>
<div id="myDropdown4" class="dropdown1-content" style="text-align:left">
<a href="#">Brake Parts Cleaner</a><br>
<a href="#">Carb & Air Intake Cleaners</a><br>
<a href="#">General Cleaners</a><br>
<a href="#">Battery Cleaners</a><br>
</div>
</div>
<div class="dropdown1">
<button class="dropbtn1">WINTER DRIVING</button>
<div id="myDropdown5" class="dropdown1-content" text-align="left">
<a href="#">Link 1</a><br>
<a href="#">Link 2</a><br>
<a href="#">Link 3</a><br>
</div>
</div>
<div class="dropdown1">
<button class="dropbtn1">LUBIRICANTS</button>
<div id="myDropdown6" class="dropdown1-content" text-align="left">
<a href="#">Link 1</a><br>
<a href="#">Link 2</a><br>
<a href="#">Link 3</a><br>
</div>
</div>
<div class="dropdown1">
<button class="dropbtn1">OTHER PRODUCTS</button>
<div id="myDropdown7" class="dropdown1-content" text-align="left">
<a href="#">Link 1</a><br>
<a href="#">Link 2</a><br>
<a href="#">Link 3</a><br>
</div>
</div>
</div>
,这会导致错误。你应该在那里检查null,看看在User对象上调用方法是否安全。