为什么这if语句总是返回true?

时间:2018-10-28 21:04:09

标签: android google-cloud-firestore

即使我知道输入的名称不存在,我的if语句(将现有名称与输入的名称进行比较)也会返回true。它还说if语句的主体为空。

I created a quick example to test an AdMob BANNER Ad. I ran it and it 
works perfectly.

Compare your setting with the setting here, maybe that will help.

I am using: ca-app-pub-3940256099942544/6300978111 for the Test Ad Unit 
Id.

I am using: ca-app-pub-3940256099942544~3347511713 for the Test App Id.

Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="net.envisionapps.tester">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>

MainActivity.java:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");


    load_ad();

}

private void load_ad() {
    AdView myAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    myAdView.loadAd(adRequest);
}

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

I added this to the build.gradle (Module: app):

implementation 'com.google.android.gms:play-services-ads:17.0.0'

And the maven in the build.gradle (project) file, added:

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
}

This is the same way I have done it on all my Apps and they all show the 
Banners. Obviously I use my own Ad Unit Ids and App Ids for live Apps.

Good Luck :)

我在做什么错了?

此代码的结果是大学已经存在的对话框。

1 个答案:

答案 0 :(得分:2)

编译器正确,由于以下原因,该值将为true

下面的这一行末尾有一个;:将其删除即可正常工作。

if(u.getDesc().trim().toLowerCase().equals(addUniDesc.getText()
                                         .toString().trim().toLowerCase()));

在这种情况下,;终止了if范围。这意味着下面的“范围”:

{ 
    exists = true;
}

将始终被执行。