我是全新的,不明白我的代码有什么问题。您可以编辑它然后回复它,以便我可以复制粘贴它

时间:2017-09-22 05:10:39

标签: java android

请编辑并回复。 我不想学习任何编码,只想创建一个应用程序。 此应用功能仅显示包含横幅广告和插页式广告的YouTube网站  它显示的错误是这些 错误:(39,5)错误:非法开始表达 错误:(39,12)错误:非法开始表达 错误:(39,33)错误:';'预期 错误:(53,5)错误:非法开始表达 错误:(53,54)错误:';'预期 错误:(66,2)错误:解析时到达文件末尾 错误:任务':app:compileReleaseJavaWithJavac'执行失败。

  

编译失败;有关详细信息,请参阅编译器错误输出。

我的代码 - >

    package cominfinitygaminghere.wixsite.httpsinfinitygaminghere.mumbojumbo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;

public class MainActivity extends AppCompatActivity {

    WebView webView;

    private InterstitialAd mInterstitialAd;

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

        mInterstitialAd = newInterstitialAd();
        loadInterstitial();

        AdView adView = (AdView) findViewById(R.id.adView);

        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();

        adView.loadAd(adRequest);

        webView = (WebView) findViewById(R.id.webview1);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://www.youtube.com/channel/UChFur_NwVSbUozOcF_F2kMg");

    public void loadInterstitial() {
        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();
        mInterstitialAd.loadAd(adRequest);

        // Show the ad if it's ready. Otherwise toast and reload the ad.
        if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            //code to go to next level of the app
        }
    }


    private InterstitialAd newInterstitialAd() {
        InterstitialAd interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
        interstitialAd.setAdListener(new AdListener() {

            @Override
            public void onAdClosed() {
                // Code for proceeding to next level here

            }
        });
        return interstitialAd;
    }
}

4 个答案:

答案 0 :(得分:0)

将loadInterstitial()放在 onCreate()方法之外。

答案 1 :(得分:0)

检查此编辑过的代码。它可以帮助您

   public class MainActivity extends AppCompatActivity {
    private InterstitialAd mInterstitialAd;

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

    private void loadWebView() {
        WebView webView;
        webView = (WebView) findViewById(R.id.webview1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://www.youtube.com/channel/UChFur_NwVSbUozOcF_F2kMg");
    }

    public void loadInterstitial() {
        AdView adView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
                .setRequestAgent("android_studio:ad_template").build();
        mInterstitialAd.loadAd(adRequest);
        // Show the ad if it's ready. Otherwise toast and reload the ad.
        if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            //code to go to next level of the app
        }
    }

    private InterstitialAd newInterstitialAd() {
        mInterstitialAd = newInterstitialAd();
        InterstitialAd interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                // Code for proceeding to next level here

            }
        });
        return interstitialAd;
    }
}

答案 2 :(得分:-1)

需要在onCreate()

上插入右括号
package cominfinitygaminghere.wixsite.httpsinfinitygaminghere.mumbojumbo;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import com.google.android.gms.ads.AdListener;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    import com.google.android.gms.ads.InterstitialAd;

    public class MainActivity extends AppCompatActivity {

        WebView webView;

        private InterstitialAd mInterstitialAd;

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

            mInterstitialAd = newInterstitialAd();
            loadInterstitial();

            AdView adView = (AdView) findViewById(R.id.adView);

            AdRequest adRequest = new AdRequest.Builder()
                    .setRequestAgent("android_studio:ad_template").build();

            adView.loadAd(adRequest);

            webView = (WebView) findViewById(R.id.webview1);

            webView.getSettings().setJavaScriptEnabled(true);
            webView.setWebViewClient(new WebViewClient());
            webView.loadUrl("https://www.youtube.com/channel/UChFur_NwVSbUozOcF_F2kMg");

         }   // insert closing bracket here

        public void loadInterstitial() {
            AdRequest adRequest = new AdRequest.Builder()
                    .setRequestAgent("android_studio:ad_template").build();
            mInterstitialAd.loadAd(adRequest);

            // Show the ad if it's ready. Otherwise toast and reload the ad.
            if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            } else {
                //code to go to next level of the app
            }
        }


        private InterstitialAd newInterstitialAd() {
            InterstitialAd interstitialAd = new InterstitialAd(this);
            interstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
            interstitialAd.setAdListener(new AdListener() {

                @Override
                public void onAdClosed() {
                    // Code for proceeding to next level here

                }
            });
            return interstitialAd;
        }
    }

答案 3 :(得分:-1)

在onCreate方法中,您尚未添加结束花括号,请在第38行添加结束花括号。

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

    mInterstitialAd = newInterstitialAd();
    loadInterstitial();

    AdView adView = (AdView) findViewById(R.id.adView);

    AdRequest adRequest = new AdRequest.Builder()
            .setRequestAgent("android_studio:ad_template").build();

    adView.loadAd(adRequest);

    webView = (WebView) findViewById(R.id.webview1);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("https://www.youtube.com/channel/UChFur_NwVSbUozOcF_F2kMg");
} // Add your closing bracket here