如何修复android studio崩溃?

时间:2019-01-19 13:54:00

标签: android-studio

我正在Android Studio中工作,但出现此错误:

  

错误:找不到参数的方法compile()   [com.google.android.gms:play-services-analytics:11.8.0]的对象   类型   org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler。

当我在Android Studio中打开项目时,程序突然关闭。

我的代码:

package com.example.block07;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 import android.graphics.Color;
import android.app.Activity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.NumberPicker;
import android.view.View;

import java.net.URL;


public class MainActivity extends Activity {
    WebView webView;
    NumberPicker np;
    TextView tv;

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

        //Get the widgets reference from XML layout
          final TextView tv;
         tv = (TextView) findViewById(R.id.tv);

         final Button btn = (Button) findViewById(R.id.button);
         final NumberPicker np = (NumberPicker) findViewById(R.id.np);

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

                webView.getSettings().setJavaScriptEnabled(true);
                webView.getSettings().setAppCacheEnabled(true);

AdjustBridge.registerAndGetInstance(getApplication(), webview)

                //Set TextView text color
                tv.setTextColor(Color.parseColor("#FF2C834F"));

                //Initializing a new string array with elements
                final String[] values = {"Tunisia", "France", "Espagne", 
"Chine", "Russie"};

                //Populate NumberPicker values from String array values
                //Set the minimum value of NumberPicker
                np.setMinValue(0); //from array first value
                //Specify the maximum value/number of NumberPicker
                np.setMaxValue(values.length - 1); //to array last value

                //Specify the NumberPicker data source as array elements
                np.setDisplayedValues(values);

                //Gets whether the selector wheel wraps when reaching the 
min/max value.
                np.setWrapSelectorWheel(true);

                //Set a value change listener for NumberPicker
                np.setOnValueChangedListener(new 
NumberPicker.OnValueChangeListener() {
                    private View v;

                    @Override
                    public void onValueChange(NumberPicker picker, int 
oldVal, int newVal) {
                        //Display the newly selected value from picker
                        tv.setText("Selected value : " + values[newVal]);
                    }

                    public void navigate(View v) {
try{ 
                        int choice = np.getValue();
                        if (choice == 0)

webView.loadUrl("https://fr.wikipedia.org/wiki/Tunisie");
                        else if (choice == 1)

webView.loadUrl("https://fr.wikipedia.org/wiki/France");
                         else if (choice == 2)

webView.loadUrl("https://fr.wikipedia.org/wiki/Espagne");
                        else if (choice == 3)

webView.loadUrl("https://fr.wikipedia.org/wiki/Chine");
                         else if (choice == 4)

webView.loadUrl("https://fr.wikipedia.org/wiki/Russie");
                    }
catch (Exception e) {
            e.printStackTrace();
        }
                });
            }
        });
    }

}

1 个答案:

答案 0 :(得分:0)

可能相似,您可以尝试一下。如果不起作用,请共享您的gradle文件。

Error:(30, 0) Could not find method compile() for arguments