Java android白屏

时间:2019-04-04 10:15:50

标签: java android google-maps

当我将应用程序放入清单中时,我的应用程序中的Google地图存在问题:

 <activity
            android:name="com.journaldev.MapsInAction.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

但是,当此活动在我的第二地点时,我只会看到白屏,而且我不知道我做错了什么

这是我的activity_main:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/cor"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".activities.MainActivity">


    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".activities.MainActivity" />

</RelativeLayout>

这是我的日志

 12:40:26.416 17851-17985/pl.logistic I/System.out: (HTTPLog)-Static: isShipBuild true
04-04 12:40:26.416 17851-17985/pl.logistic I/System.out: (HTTPLog)-Static: getDebugLevel 0x4f4c
04-04 12:40:26.416 17851-17985/pl.logistic I/System.out: (HTTPLog)-Thread-4478-211231246: SmartBonding Enabling is true, SHIP_BUILD is true, log to file is false, DBG is false, DEBUG_LEVEL (1-LOW, 2-MID, 3-HIGH) is 1
04-04 12:40:26.416 17851-17985/pl.eltegps.logistic I/System.out: (HTTPLog)-Thread-4478-211231246: SMARTBONDING_FEATURE_ENABLED is true
04-04 12:40:26.416 17851-17985/pl.logistic I/System.out: (HTTPLog)-Static: isSBSettingEnabled true

这是我的MainActivity代码:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pgoList = ((PGOList) getIntent().getSerializableExtra("list"));
        view =  getWindow().getCurrentFocus();

//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
        File excelFile = Environment.getExternalStorageDirectory();
        tts = new TextToSpeech(this, this);
//        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.cor);


        File f = new File(excelFile + "/b.json");
        final List<Uri> uris = new ArrayList<>();
        uris.add(Uri.fromFile(f));

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);



    }


    @Override
    public void onMapReady(GoogleMap googleMap) {

        gMap = googleMap;
        gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    }

我认为这是我的难题:

private class LoginTask extends AsyncTask<Void, Void, Result> {

        LoginRequest request = null;

        @Override
        protected void onPreExecute() {

            taskRunning(true);
            progressDialog.show();
        }

        @Override
        protected Result doInBackground(Void... params) {

            request = new LoginRequest();

            String currentLang = Locale.getDefault().getLanguage();
            if (!StringUtils.isEmpty(currentLang)) {
                request.lang = currentLang;
            }
            request.os = "ANDROID " + android.os.Build.VERSION.RELEASE;
            try {
                PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                String version = pInfo.versionName;
                if (!StringUtils.isEmpty(version)) {
                    request.ver = version;
                }
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            request.login = etLogin.getText().toString();
            request.firm = etFirm.getText().toString();
            request.password = etPassword.getText().toString();
            request.device_id = prefs.getDeviceID();
            Log.d("device id ", "device id " + prefs.getDeviceID());

            if (TextUtils.isEmpty(request.device_id)) {

                LoginResult result = new LoginResult();
                result.status = Result.Code.STATUS_ERR_LOGIN_AD;
                return result;
            }

            return new SoapManager(LoginActivity.this).invokeSoapMethod(request, this);
        }

        protected void onCancelled() {

            Tools.makeToast(LoginActivity.this, LoginActivity.this.getString(R.string.operationCancelled));

            taskRunning(false);
        }

        @SuppressLint("StringFormatInvalid")
        @Override
        protected void onPostExecute(Result result) {

            taskRunning(false);
            progressDialog.dismiss();

            if (result != null) {

                switch (((LoginResult) result).status) {

                    case Result.Code.STATUS_OK:

                        prefs.set(Preferences.Key.PERSISTANT_USER_UID, ((LoginResult) result).uid);
                        prefs.set(Preferences.Key.IS_NOT_FIRST_RUN, true);

                        /**
                         * Used for user session refreshing - getting new PERSISTANT_USER_UID.
                         */
                        prefs.set(Preferences.Key.PERSISTANT_USER_NAME, etLogin.getText().toString());
                        prefs.set(Preferences.Key.PERSISTANT_USER_PASSWORD, etPassword.getText().toString());
                        prefs.set(Preferences.Key.PERSISTANT_USER_FIRM, etFirm.getText().toString());
                        if (!StringUtils.isEmpty(request.ver)) {
                            prefs.set(Preferences.Key.PERSISTANT_USER_VER, request.ver);
                        }
                        if (!StringUtils.isEmpty(request.lang)) {
                            prefs.set(Preferences.Key.PERSISTANT_USER_LANG, request.lang);
                        }


                        /**
                         * Starting database update service - downloading dictionaries.
                         */
//                        if (Preferences.runUpdateService)
//                            startService(new Intent(LoginActivity.this, UpdateService.class));

                        editor.putString("login", etLogin.getText().toString()).apply();
                        editor.putString("firm", etFirm.getText().toString()).apply();

                        startActivity(new Intent(LoginActivity.this, RMActivity.class));

                        return;

                    case Result.Code.STATUS_ERR_LOGIN_AD:

                        Tools.showOkDialog(LoginActivity.this,
                                R.string.accessDeniedTitle,
                                !TextUtils.isEmpty(request.device_id) ?
                                        String.format(getString(R.string.accessDeniedMessage), request.device_id) :
                                        getString(R.string.noIMEIAvailable));

                        return;

                    case Result.Code.STATUS_ERR:

                    default:

                        break;
                }
            }

            Tools.makeToast(LoginActivity.this, LoginActivity.this.getString(R.string.loginFailed));
        }
    }

1 个答案:

答案 0 :(得分:0)

 1.Add required permisson on manifeast:

 <!--Permissions-->

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.
READ_GSERVICES" />

 <!--Google MAP API key-->(i think you are not mentioned mapkey)

 <meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="YOUR MAP KEY" />  

在xml文件中

<fragment 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"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />

在Java中

private GoogleMap mMap;

 SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

  @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney, Australia, and move the camera.
    LatLng india= new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(india).title("Marker in india"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(india));
}