Android应用程序崩溃分享按钮单击

时间:2015-07-30 18:16:57

标签: android button crash share

我正在开发一个在操作栏上有一个分享按钮的Android应用程序。以前按钮工作正常,但最近这不再适用,我有调试此问题的问题,因为点击后代码流不会停止任何断点。我唯一的问题是跟随LogCat的错误:

07-30 17:52:55.876  16042-16044/igparadaxv.igbparadaxv E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 52 byte allocation with 0 free bytes and 0B until OOM"
07-30 17:52:55.879  16042-16042/igparadaxv.igbparadaxv E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 54 byte allocation with 0 free bytes and 0B until OOM"
07-30 17:52:55.937  16042-16051/igparadaxv.igbparadaxv E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 36 byte allocation with 0 free bytes and 0B until OOM"
07-30 17:52:56.291  16042-16042/igparadaxv.igbparadaxv E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 0 free bytes and 0B until OOM" (recursive case)
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ "main" prio=5 tid=1 Runnable
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ | group="main" sCount=0 dsCount=0 obj=0x74172970 self=0xb4606800
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ | sysTid=16042 nice=0 cgrp=apps sched=0/0 handle=0xb77b1160
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ | state=R schedstat=( 0 0 0 ) utm=97 stm=42 core=0 HZ=100
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ | stack=0xbf43b000-0xbf43d000 stackSize=8MB
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ | held mutexes= "mutator lock"(shared held)
07-30 17:52:56.294  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #00 pc 00005ac3  /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+83)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #01 pc 00002e91  /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+33)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #02 pc 003c3f3a  /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+138)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #03 pc 0038d03c  /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+268)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #04 pc 0039142b  /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+459)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #05 pc 001ec6fb  /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+1243)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #06 pc 001f030d  /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+2749)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #07 pc 00176b91  /system/lib/libart.so (art::mirror::Class::AllocObject(art::Thread*)+1329)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #08 pc 003905de  /system/lib/libart.so (art::Thread::ThrowNewWrappedException(art::ThrowLocation const&, char const*, char const*)+830)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #09 pc 003914d2  /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+626)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #10 pc 001ec6fb  /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+1243)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #11 pc 001f030d  /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+2749)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #12 pc 0031aabf  /system/lib/libart.so (art::mirror::String::Alloc(art::Thread*, int)+1903)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #13 pc 0031b0fc  /system/lib/libart.so (art::mirror::String::AllocFromModifiedUtf8(art::Thread*, char const*)+44)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #14 pc 0038f9ff  /system/lib/libart.so (art::Thread::InternalStackTraceToStackTraceElementArray(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobjectArray*, int*)+383)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #15 pc 00340650  /system/lib/libart.so (art::Throwable_nativeGetStackTrace(_JNIEnv*, _jclass*, _jobject*)+80)
07-30 17:52:56.295  16042-16042/igparadaxv.igbparadaxv E/art﹕ native: #16 pc 00000fe6  /data/dalvik-cache/x86/system@framework@boot.oat (Java_java_lang_Throwable_nativeGetStackTrace__Ljava_lang_Object_2+142)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at java.lang.Throwable.nativeGetStackTrace!(Native method)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at java.lang.Throwable.getInternalStackTrace(Throwable.java:264)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at java.lang.Throwable.printStackTrace(Throwable.java:318)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at java.lang.Throwable.printStackTrace(Throwable.java:300)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at android.util.Log.getStackTraceString(Log.java:335)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at com.android.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:59)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at com.android.internal.os.RuntimeInit.access$200(RuntimeInit.java:43)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:85)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
07-30 17:52:56.296  16042-16042/igparadaxv.igbparadaxv E/art﹕ [ 07-30 17:52:56.315 16042:16051 I/art      ]
    Clamp target GC heap from 68MB to 64MB
07-30 17:52:56.379  16042-16042/? E/AndroidRuntime﹕ Error reporting crash
    java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available

有人有什么问题的建议吗?

[编辑]

我正在使用以下代码:

fotoDetalheActivity.java

package igparadaxv.igbparadaxv;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.support.v7.widget.ShareActionProvider;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.Normalizer;
import java.util.zip.Inflater;

import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * Created by Jarves on 19/07/2015.
 */
public class fotoDetalheActivity extends Fragment{

    OnFotoSelecionadaListener mCallback;
    public static String Url;
    public static String Nome;
    Activity activity;

    ImageView expandedImageView;
    ImageButton download,compartilhar;
    private ShareActionProvider mShareActionProvider;
    Intent intent = new Intent(Intent.ACTION_SEND);

    public interface OnFotoSelecionadaListener {
        public void OnFotoSelecionada(String Url, String nome);
    }

    public fotoDetalheActivity(){

    }

    @Override
    public void onAttach(Activity activity)
    {
        super.onAttach(activity);
        this.activity = activity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("Fotos IBPXV");

        Bundle bundle = this.getArguments();
        if (bundle != null) {
            this.Url = bundle.getString("Url");

            if( bundle.getString("Nome").length()<20)
            {
                this.Nome = bundle.getString("Nome").replaceAll("\\p{C}", "?");
            }else {
                this.Nome = bundle.getString("Nome").replaceAll("\\p{C}", "?").substring(0, 20);
            }
        }

    }

      @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fotodetalhe, container, false);
    }


    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        expandedImageView = (ImageView) getView().findViewById(R.id.imgDetalhe);
        download = (ImageButton) getView().findViewById(R.id.btnDownload);
        download.setOnClickListener(clicado);

        compartilhar = (ImageButton) getView().findViewById(R.id.btnShare);
        compartilhar.setOnClickListener(clicado);
        setHasOptionsMenu(true);
        OnFotoSelecionada(Url);
    }

    public void OnFotoSelecionada(String Url) {

        Picasso.with(getActivity()).load(Url).into(expandedImageView);

        PhotoViewAttacher mAttacher = new PhotoViewAttacher(expandedImageView);

    }

    // Call to update the share intent
    private Intent setShareIntent(Uri endereco, File foto) {
        // If you want to share a png image only, you can do:
        // setType("image/png"); OR for jpeg: setType("image/jpeg");
        intent.setType("image/*");

        // Make sure you put example png image named myImage.png in your
        // directory
        Uri uri = Uri.fromFile(foto);
        intent.putExtra(Intent.EXTRA_STREAM, endereco);

        return intent;

    }

    private void compartilhar() {

        expandedImageView.buildDrawingCache();
        Bitmap bm = expandedImageView.getDrawingCache();

        OutputStream fOut = null;
        Uri outputFileUri;
        File sdImageMainDirectory;
        try {
            File root = new File(Environment.getExternalStorageDirectory()
                    + File.separator + "IBPXV" + File.separator);
            root.mkdirs();
            sdImageMainDirectory = new File(root,Nome+".jpg");
            outputFileUri = Uri.fromFile(sdImageMainDirectory);
            fOut = new FileOutputStream(sdImageMainDirectory);

            bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            fOut.flush();
            fOut.close();

            startActivity(Intent.createChooser(setShareIntent(outputFileUri, sdImageMainDirectory), "Compartilhar!"));


        } catch (Exception e) {
            Toast.makeText(getActivity(),"Erro enviando imagem.",Toast.LENGTH_SHORT).show();

        }

    }

    View.OnClickListener clicado = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btnShare:
                    compartilhar();
                    break;


            }
        }
    };

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

        // Inflate menu resource file.
        getActivity().getMenuInflater().inflate(R.menu.menufotodetalhe, menu);

        // Locate MenuItem with ShareActionProvider
        MenuItem item = menu.findItem(R.id.menu_item_share);

        super.onCreateOptionsMenu(menu,inflater);
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.menu_item_share:
                compartilhar();
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }

}

menufotodetalhe.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menu_item_share"
        android:actionProviderClass="android.widget.ShareActionProvider"
        app:showAsAction="ifRoom"
        android:title="@string/baixar"
        android:icon="@drawable/ic_share_white_48dp"
        />
</menu>

0 个答案:

没有答案