InflateException和应用程序在android小米Redmi注意事项4中崩溃

时间:2018-10-25 11:29:25

标签: android

朋友,我正在开发一个android应用程序,它在所有设备上都能正常工作,但是当我在小米Redmi note 4设备上运行该应用程序时,该应用程序将崩溃。当我单击一个按钮时,该应用程序将崩溃。任何人,请帮助我。

我在这里添加日志

FATAL EXCEPTION: main
                                                                 Process: com.wowword.wowword, PID: 21547
                                                                 android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
                                                                 Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
                                                                 Caused by: java.lang.reflect.InvocationTargetException
                                                                     at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                     at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                     at android.view.LayoutInflater.createView(LayoutInflater.java:652)
                                                                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
                                                                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:989)
                                                                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:879)
                                                                     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
                                                                     at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                     at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                     at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
                                                                     at com.wowword.wowword.customDialog.CustomDialogForAudioRecord.onCreate(CustomDialogForAudioRecord.java:68)
                                                                     at android.app.Dialog.dispatchOnCreate(Dialog.java:392)
                                                                     at android.app.Dialog.show(Dialog.java:296)
                                                                     at com.wowword.wowword.activity.MenuScreenActivity.onClick(MenuScreenActivity.java:224)
                                                                     at android.view.View.performClick(View.java:5619)
                                                                     at android.view.View$PerformClick.run(View.java:22295)
                                                                     at android.os.Handler.handleCallback(Handler.java:754)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                     at android.os.Looper.loop(Looper.java:163)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:6342)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
                                                                  Caused by: java.lang.OutOfMemoryError: Failed to allocate a 27362512 byte allocation with 8077528 free bytes and 7MB until OOM
                                                                     at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
                                                                     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
                                                                     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
                                                                     at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1272)
                                                                     at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
                                                                     at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
                                                                     at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:308)
                                                                     at android.content.res.Resources.loadDrawable(Resources.java:872)
                                                                     at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
                                                                     at android.view.View.<init>(View.java:4182)
                                                                     at android.view.ViewGroup.<init>(ViewGroup.java:578)
                                                                     at android.view.ViewGroup.<init>(ViewGroup.java:574)
                                                                     at android.view.ViewGroup.<init>(ViewGroup.java:570)
                                                                     at android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:575)

这是我的CustomDialogForAudioRecord类:

public class CustomDialogForAudioRecord extends AppCompatDialog implements View.OnClickListener {

public static final int RECORD_AUDIO = 0;
public Activity activity;
private TextView mTextViewTerm;
private ImageView mButtonWindowClose;
private View mViewPlayOurs;
private View mViewRecord;
private View mViewPlayYours;
private ImageView mImageViewRecord;
private ImageView mButtonPlayRecordedAudio;
private ImageView mImagePlayOurs;
private FirebaseAnalytics mFirebaseAnalytics;
private CircularProgressBar circularProgressBar;
private MediaRecorder mAudioRecorder;
private boolean mIsAudioRecorded = false;
private WowWordActionSounds mWowWordActionSounds;
private String mPathToSaveRecording;
private File mFileToSaveAudio;

public CustomDialogForAudioRecord(Activity activity) {
    super(activity);
    this.activity = activity;
    mPathToSaveRecording = activity.getApplicationContext().getFilesDir().getPath();
    mFileToSaveAudio = new File(mPathToSaveRecording);
    if (!mFileToSaveAudio.exists()) {
        mFileToSaveAudio.mkdirs();
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.layout_custom_dialog_audio_record);
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(activity);
    mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
    circularProgressBar = findViewById(R.id.progress_bar);
    mTextViewTerm = findViewById(R.id.text_term);
    mButtonWindowClose = findViewById(R.id.button_close);
    mImageViewRecord = findViewById(R.id.icon_record);
    mViewPlayOurs = findViewById(R.id.view_play_ours);
    mViewRecord = findViewById(R.id.view_record);
    mViewPlayYours = findViewById(R.id.view_play_yours);
    mImagePlayOurs = findViewById(R.id.icon_play_ours);
    mButtonPlayRecordedAudio = findViewById(R.id.icon_play_yours);
    mButtonPlayRecordedAudio.setImageResource(R.drawable.ic_button_yours_disabled);
    mWowWordActionSounds = new WowWordActionSounds(activity);
    mFormatAndSetTextFromHtml();
    mButtonWindowClose.setOnClickListener(this);
    mViewPlayOurs.setOnClickListener(this);
    mViewRecord.setOnClickListener(this);
    mViewPlayYours.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.button_close:
            mWowWordActionSounds.mPlayAudioDialogClose();
            mAddToFirebaseAnalytics("close button in audio record dialog clicked", "close audio record dialog", "Close Button");
            dismiss();
            break;
        case R.id.view_play_ours:
            mWowWordActionSounds.mPlayAudioButtonClick();
            mPlayDownloadedAudio();
            break;
        case R.id.view_record:
            mWowWordActionSounds.mPlayAudioButtonClick();
            mRecordAudioAndSetProgress();
            break;
        case R.id.view_play_yours:
            mWowWordActionSounds.mPlayAudioButtonClick();
            mCheckIsAudioRecorded();
            break;
    }
}

private void mFormatAndSetTextFromHtml() {
    if (TemporaryModelCache.getInstance().getTerm().getmTermSpik() != null) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            mTextViewTerm.setText(Html.fromHtml(TemporaryModelCache.getInstance().getTerm().getmTermSpik(), Html.FROM_HTML_MODE_COMPACT));
        }
        mTextViewTerm.setText(Html.fromHtml(TemporaryModelCache.getInstance().getTerm().getmTermSpik()));
    } else {
        mTextViewTerm.setText("");
    }
}

private void mPlayDownloadedAudio() {
    TemporaryModelCache.stopMediaPlayer();
    TemporaryModelCache.getAsyncInstance().cancel(true);
    TemporaryModelCache.clearAsyncInstance();
    TemporaryModelCache.getAsyncInstance().execute(TemporaryModelCache.getInstance().getTerm().getmTermSpikAudio());
}

private void mCheckIsAudioRecorded() {
    if (mIsAudioRecorded) {
        mPlayRecordedAudio();

    } else {
        Toast.makeText(getContext(), "Please record first", Toast.LENGTH_LONG).show();
    }
}

private void mPlayRecordedAudio() {

    String file_name = mFileToSaveAudio + "recording.3gp";
    TemporaryModelCache.stopMediaPlayer();
    TemporaryModelCache.getAsyncInstance().cancel(true);
    TemporaryModelCache.clearAsyncInstance();
    TemporaryModelCache.getAsyncInstance().execute(file_name);
}

private void mRecordAudioAndSetProgress() {
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO}, RECORD_AUDIO);
    } else {
        mStartRecordingAudio();
    }
}

private void mStartRecordingAudio() {
    try {
        TemporaryModelCache.stopMediaPlayer();
        TemporaryModelCache.getAsyncInstance().cancel(true);
        TemporaryModelCache.clearAsyncInstance();
        mAudioRecorder = new MediaRecorder();
        mAudioRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mAudioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        String file_name = mFileToSaveAudio + "recording.3gp";
        mAudioRecorder.setOutputFile(file_name);
        mAudioRecorder.prepare();
        mAudioRecorder.start();
        mImageViewRecord.setImageResource(R.drawable.ic_button_recording);
        circularProgressBar.setVisibility(View.VISIBLE);
        mImagePlayOurs.setImageResource(R.drawable.ic_button_play_ours_disabled);
        mButtonPlayRecordedAudio.setImageResource(R.drawable.ic_button_yours_disabled);
        mViewRecord.setEnabled(false);
        mViewPlayYours.setEnabled(false);
        mViewPlayOurs.setEnabled(false);

    } catch (IllegalStateException ise) {
        Log.e("error", ise.toString());
        // make something ...
    } catch (IOException ioe) {
        Log.e("error", ioe.toString());
        // make something
    }
    new Timer().schedule(new TimerTask() {

        @Override
        public void run() {
            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        mAudioRecorder.stop();
                        mAudioRecorder.reset();
                        mAudioRecorder.release();
                    } catch (RuntimeException stopException) {
                        //handle cleanup here
                    }
                    circularProgressBar.setVisibility(View.GONE);
                    mWowWordActionSounds.mPlayAudioButtonClick();
                    mIsAudioRecorded = true;
                    mButtonPlayRecordedAudio.setImageResource(R.drawable.ic_button_yours_png);
                    mImagePlayOurs.setImageResource(R.drawable.ic_btn_playours);
                    mImageViewRecord.setImageResource(R.drawable.ic_btn_record);
                    mViewPlayYours.setEnabled(true);
                    mViewPlayOurs.setEnabled(true);
                    mViewRecord.setEnabled(true);
                }
            });

        }
    }, 5000);
}

private void mAddToFirebaseAnalytics(String eventName, String eventDetail, String contentType) {
    Bundle bundle = new Bundle();
    bundle.putString(FirebaseAnalytics.Param.ITEM_ID, eventName);
    bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, eventDetail);
    bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
}

}

此清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wowword.wowword">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
    android:name=".WowWord"
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppThemeNoActionBar">
    <activity
        android:name="com.wowword.wowword.activity.SplashScreenActivity"
        android:theme="@style/AppThemeNoActionBar"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.wowword.wowword.activity.MainActivity"
        android:launchMode="singleInstance"
        android:theme="@style/AppThemeNoActionBar"/>

    <activity
        android:name="com.wowword.wowword.activity.HelpVideoActivity"
        android:theme="@style/AppThemeNoActionBar" />
    <activity
        android:name="com.wowword.wowword.activity.PlayScreenActivity"
        android:theme="@style/AppThemeNoActionBar" />
    <activity
        android:name="com.wowword.wowword.activity.MenuScreenActivity"
        android:theme="@style/AppThemeNoActionBar" />
    <activity
        android:name="com.wowword.wowword.activity.VideoViewActivity"
        android:theme="@style/AppThemeNoActionBar" />
    <activity
        android:name="com.wowword.wowword.activity.ApplicationClosingActivity"
        android:theme="@style/AppThemeNoActionBar" />

    <service
        android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
        android:enabled="true" />
</application>

1 个答案:

答案 0 :(得分:1)

问题是

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 27362512 byte 
allocation with 8077528 free bytes and 7MB until OOM

在线

mButtonPlayRecordedAudio.setImageResource(R.drawable.ic_button_yours_disabled);

我猜想它的第68行。图像太大,导致OutOfMemory错误,请在Internet上搜索如何有效使用图像。