我的应用在启动时崩溃

时间:2018-08-29 16:38:52

标签: android

我的应用在启动时崩溃!请帮忙!

这是我的代码

MainActivity.java:

  }

public static String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.startsWith(manufacturer)) {
        return capitalize(model);
    }
    return capitalize(manufacturer) + " " + model;
}

private static String capitalize(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    char[] arr = str.toCharArray();
    boolean capitalizeNext = true;
    String phrase = "";
    for (char c : arr) {
        if (capitalizeNext && Character.isLetter(c)) {
            phrase += Character.toUpperCase(c);
            capitalizeNext = false;
            continue;
        } else if (Character.isWhitespace(c)) {
            capitalizeNext = true;
        }
        phrase += c;
    }
    return phrase;
}


private AdView mAdView;
AdRequest adRequest;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.app_color_Dark));
    }
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    toolbar.setTitleTextColor(Color.WHITE);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(getResources().getString(R.string.app_name));
    setupdialog();


    getBaseContext().getApplicationContext().sendBroadcast(new Intent("BatteryReciver"));

    arcProgress = (ArcProgress) findViewById(R.id.arc_progress);
    TxtLevel = (TextView) findViewById(R.id.TxtLevel);
    TxtVoltage = (TextView) findViewById(R.id.TxtVoltage);
    TxtTemperature = (TextView) findViewById(R.id.TxtTemperature);
    Tools_WiFi = (ImageView) findViewById(R.id.tool_wifi);
    Tools_Rotate = (ImageView) findViewById(R.id.tool_rotate);
    Tools_Brightness = (ImageView) findViewById(R.id.tool_brightness);
    Tools_Bluetooth = (ImageView) findViewById(R.id.tool_bluetooth);
    Tools_Timeout = (ImageView) findViewById(R.id.tool_timeout);
    Tools_Mode = (ImageView) findViewById(R.id.tool_mode);
    PowerSavingMode = (Button) findViewById(R.id.PowerSavingMode);
    CardViewBatteryArc = (CardView) findViewById(R.id.CardViewBatteryArc);
    CardViewTools = (CardView) findViewById(R.id.CardViewTools);
    batteryDetail = (CardView) findViewById(R.id.batteryDetail);
    CardViewRate = (CardView) findViewById(R.id.CardViewRate);
    mCardViewShare = (CardView) findViewById(R.id.CardViewShare);
    btn_feedback = (Button) findViewById(R.id.btn_feedbak);
    btn_ratenow = (Button) findViewById(R.id.btn_ratenow);
    AlertLout = (RelativeLayout) findViewById(R.id.AlertLout);
    mAlertText = (TextView) findViewById(R.id.AlertText);


    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    final NativeExpressAdView adView = (NativeExpressAdView) findViewById(R.id.NativeadView);
    adView.loadAd(new AdRequest.Builder().build());
    adView.setVisibility(View.GONE);
    adView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            adView.setVisibility(View.VISIBLE);
        }
    });

    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mAdView.setVisibility(View.VISIBLE);
        }
    });

    registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    setColorToCardview();

    cResolver = getContentResolver();
    window = getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (Settings.System.canWrite(this)) {
            try {
                Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
                brightness = Settings.System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS);
                rotate = Settings.System.getInt(cResolver, Settings.System.ACCELEROMETER_ROTATION);
                timeout = Settings.System.getInt(cResolver, Settings.System.SCREEN_OFF_TIMEOUT);

                if (timeout > 40000) {
                    setTimeout(3);
                    timeout = 40000;
                }

                CheckOnAndOff();

            } catch (Settings.SettingNotFoundException e) {
                //Throw an error case it couldn't be retrieved
                Log.e("Error", "Cannot access system brightness");
                e.printStackTrace();
            }
        } else {
            NotificationManager notificationManager =
                    (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                    && !notificationManager.isNotificationPolicyAccessGranted()) {

                donotdisterb_dialog.show();
            }
            writesetting_dialog.show();

        }

    } else {
        try {
            Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
            brightness = Settings.System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS);
            rotate = Settings.System.getInt(cResolver, Settings.System.ACCELEROMETER_ROTATION);
            timeout = Settings.System.getInt(cResolver, Settings.System.SCREEN_OFF_TIMEOUT);

            Log.e("timeout", "" + timeout);

            if (timeout > 40000) {
                setTimeout(3);
                timeout = 40000;
            }

            CheckOnAndOff();

        } catch (Settings.SettingNotFoundException e) {
            //Throw an error case it couldn't be retrieved
            Log.e("Error", "Cannot access system brightness");
            e.printStackTrace();
        }
    }

    //refreshAd1();
    //refreshAd2();
    getBatteryPercentage();
    SetClickListner();
    CheckIntentToolsOnOrOff();

    mInterstitialAd = new InterstitialAd(getApplicationContext());
    mInterstitialAd.setAdUnitId(getResources().getString(R.string.instritial));
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }
    });

}

private void showInterstitial() {
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }
}


private void setColorToCardview() {

    CardViewBatteryArc.setCardBackgroundColor(getApplicationContext().getResources().getColor(R.color.white));
    CardViewTools.setCardBackgroundColor(getApplicationContext().getResources().getColor(R.color.white));
    batteryDetail.setCardBackgroundColor(getApplicationContext().getResources().getColor(R.color.white));
    CardViewRate.setCardBackgroundColor(getApplicationContext().getResources().getColor(R.color.white));
    mCardViewShare.setCardBackgroundColor(getApplicationContext().getResources().getColor(R.color.white));
    CardViewBatteryArc.setCardElevation(0);
    CardViewTools.setCardElevation(0);
    batteryDetail.setCardElevation(0);
    CardViewRate.setCardElevation(0);
    mCardViewShare.setCardElevation(0);
}

private void setupdialog() {

    exit_dialog = new AlertDialog.Builder(MainActivity.this);
    exit_dialog.setTitle("Are you sure?");
    exit_dialog.setMessage("Do you want to exit from this application?");
    exit_dialog.setNegativeButton("Yes",
            new DialogInterface.OnClickListener() {
                @SuppressLint("NewApi")
                public void onClick(DialogInterface dialog, int whichButton) {
                    am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                    am.setRingerMode(Profile);
                    setTimeout(3);
                    finish();
                }
            });

    writesetting_dialog = new AlertDialog.Builder(MainActivity.this);
    writesetting_dialog.setTitle("Important!");
    writesetting_dialog.setCancelable(false);
    writesetting_dialog.setMessage("Need write setting permission to set screen brightness, screen timeout, screen rotation, sound profile.");
    writesetting_dialog.setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                    intent.setData(Uri.parse("package:" + getPackageName()));
                    startActivity(intent);
                }
            });

Logcat:

  

08-29 17:31:22.448 25221-25221 / com.loopapp.fast.batterycharger   D / FirebaseApp:com.google.firebase.auth.FirebaseAuth未链接。   跳过初始化。 08-29 17:31:22.450   25221-25221 / com.loopapp.fast.batterycharger D / FirebaseApp:   com.google.firebase.crash.FirebaseCrash未链接。跳过   初始化。 08-29 17:31:22.450   25221-25221 / com.loopapp.fast.batterycharger I / FirebaseInitProvider:   FirebaseApp初始化成功08-29 17:31:22.455   25221-25221 / com.loopapp.fast.batterycharger D / Android运行时:正在关闭   VM 08-29 17:31:22.457 25221-25221 / com.loopapp.fast.batterycharger   E / AndroidRuntime:致命异常:main       流程:com.loopapp.fast.batterycharger,PID:25221       java.lang.RuntimeException:无法实例化活动ComponentInfo {com.loopapp.fast.batterycharger / com.loopapp.fast.batterycharger.com.loopapp.fast.charging.MainActivity}:   java.lang.ClassNotFoundException:找不到类   “ com.loopapp.fast.batterycharger.com.loopapp.fast.charging.MainActivity”   在路径上:DexPathList [[zip文件   “ /data/app/com.loopapp.fast.batterycharger-2/base.apk”,zip文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_dependencies_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_0_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_1_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_2_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_3_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_4_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_5_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_6_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_7_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_8_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.loopapp.fast.batterycharger-2/lib/arm,   / system / lib,/ vendor / lib]]           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2849)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)           在android.app.ActivityThread.-wrap14(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:154)           在android.app.ActivityThread.main(ActivityThread.java:6776)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1496)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)        原因:java.lang.ClassNotFoundException:找不到类“ com.loopapp.fast.batterycharger.com.loopapp.fast.charging.MainActivity”   在路径上:DexPathList [[zip文件   “ /data/app/com.loopapp.fast.batterycharger-2/base.apk”,zip文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_dependencies_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_0_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_1_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_2_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_3_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_4_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_5_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_6_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_7_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_8_apk.apk”,   压缩文件   “ /data/app/com.loopapp.fast.batterycharger-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.loopapp.fast.batterycharger-2/lib/arm,   / system / lib,/ vendor / lib]]           在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)           在java.lang.ClassLoader.loadClass(ClassLoader.java:380)           在java.lang.ClassLoader.loadClass(ClassLoader.java:312)           在android.app.Instrumentation.newActivity(Instrumentation.java:1086)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2839)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)           在android.app.ActivityThread.-wrap14(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1642)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:154)           在android.app.ActivityThread.main(ActivityThread.java:6776)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1496)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)08-29   17:31:22.459 2832-3758 /? D /调试:!@DumpState:SHIP       !@DumpState:调试级别:0x4f4c       !@Dumpstate:最后,系统将跳过dumpstate

1 个答案:

答案 0 :(得分:0)

  

FirebaseApp:com.google.firebase.auth。 FirebaseAuth未链接。   跳过初始化。 08-29 17:31:22.450   25221-25221 / com.loopapp.fast.batterycharger D / FirebaseApp:   com.google.firebase.crash。 FirebaseCrash未链接

检查您的依赖项并添加(如果您还没有的话):

implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'

阅读https://firebase.google.com/docs/android/setup


Android Studio已经具有 Connect to Firebase 选项,这对添加Firebase及其依赖项有很大帮助:https://developer.android.com/studio/write/firebase