English 中文(简体)
I m setting up ads on my mobile app and getting an error saying that mAdView wasn t resolved
原标题:

In Java Android Studio when I look at my code, I see the error: Cannot resolve symbol "mAdView" I checked on the AdMob website and it seems I did the code right but I get this error.

Here is my main java code:

package com.example.javaamogbutton;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

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);

        Button amogussus = findViewById(R.id.amogus);
        final MediaPlayer mediaPlayer = MediaPlayer.create(this,R.raw.amongus);

        amogussus.setOnClickListener(v -> mediaPlayer.start()); {

        }

        MobileAds.initialize(this, initializationStatus -> {
        });
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }
}

build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

plugins {
    id  com.android.application 
}

android {
    namespace  com.example.javaamogbutton 
    compileSdk 33

    defaultConfig {
        applicationId "com.example.javaamogbutton"
        minSdk 27
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile( proguard-android-optimize.txt ),  proguard-rules.pro 
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation  androidx.appcompat:appcompat:1.6.1 
    implementation  com.google.android.material:material:1.9.0 
    implementation  androidx.constraintlayout:constraintlayout:2.1.4 
    implementation  com.google.android.gms:play-services-ads:22.1.0 
    testImplementation  junit:junit:4.13.2 
    androidTestImplementation  androidx.test.ext:junit:1.1.5 
    androidTestImplementation  androidx.test.espresso:espresso-core:3.5.1 
}

main_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">

    <Button
        android:id="@+id/amogus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/amogussus"
        android:textColor="@color/black"
        android:layout_centerInParent="true"
        android:textSize="24sp"/>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="MY_ID">
    </com.google.android.gms.ads.AdView>
</RelativeLayout>

Importing AdView and other imports didn t work. My program said import com.google.android.gms.ads.AdView; was an unused import.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签