海量数据传输应用程序

时间:2016-11-01 18:35:26

标签: java android

我遇到的问题是我开发的应用程序,它应该执行大量数据传输。当它是几个文件时效果很好但是一旦你达到MB规模,应用程序崩溃了。我目前不得不转移一堆目前导致我的应用程序崩溃的图像。

我得到的错误是。

        E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 68)
 E/BulkCursor: Unable to get window because the remote process is dead
 D/AndroidRuntime: Shutting down VM
 E/AndroidRuntime: FATAL EXCEPTION: main
                   Process: com.example.alex.tableappnavrev1, PID: 23138
                   java.lang.IllegalStateException: Could not execute
 method for android:onClick
                       at
 android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                       at android.view.View.performClick(View.java:5698)
                       at
 android.widget.TextView.performClick(TextView.java:10881)
                       at android.view.View$PerformClick.run(View.java:22565)
                       at android.os.Handler.handleCallback(Handler.java:739)
                       at android.os.Handler.dispatchMessage(Handler.java:95)
                       at android.os.Looper.loop(Looper.java:158)
                       at
 android.app.ActivityThread.main(ActivityThread.java:7231)
                       at java.lang.reflect.Method.invoke(Native Method)
                       at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                       at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                    Caused by: java.lang.reflect.InvocationTargetException
                       at java.lang.reflect.Method.invoke(Native Method)
                       at
 android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                       at android.view.View.performClick(View.java:5698)
                       at
 android.widget.TextView.performClick(TextView.java:10881)
                       at android.view.View$PerformClick.run(View.java:22565)
                       at android.os.Handler.handleCallback(Handler.java:739)
                       at android.os.Handler.dispatchMessage(Handler.java:95)
                       at android.os.Looper.loop(Looper.java:158)
                       at
 android.app.ActivityThread.main(ActivityThread.java:7231)
                       at java.lang.reflect.Method.invoke(Native Method)
                       at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                       at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                    Caused by:
 android.database.CursorIndexOutOfBoundsException: Index -1 requested,
 with a size of 1
                       at
 android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
                       at
 android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
                       at
 android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
                       at
 android.database.CursorWrapper.getString(CursorWrapper.java:137)
                       at android.widget.Toast.<init>(Toast.java:161)
                       at android.widget.Toast.makeText(Toast.java:456)
                       at
 com.example.alex.tableappnavrev1.moveKnox.movetoKnox(moveKnox.java:78)
                       at java.lang.reflect.Method.invoke(Native Method)
                       at
 android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                       at android.view.View.performClick(View.java:5698)
                       at
 android.widget.TextView.performClick(TextView.java:10881)
                       at android.view.View$PerformClick.run(View.java:22565)
                       at android.os.Handler.handleCallback(Handler.java:739)
                       at android.os.Handler.dispatchMessage(Handler.java:95)
                       at android.os.Looper.loop(Looper.java:158)
                       at
 android.app.ActivityThread.main(ActivityThread.java:7231)
                       at java.lang.reflect.Method.invoke(Native Method)
                       at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                       at
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

这是我正在使用的副本:

    public static File createDirectory(File path, String name) throws Exception
 {
     File directory = new File(path, name);
     if (directory.mkdirs()) return directory;
     if (directory.exists()) throw new Exception(String.format("%s already exists", name));

     throw new Exception(String.format("Error creating %s", name));
 }

    public static File copyFile(File src, File path) throws Exception
 {
     try
     {
         if (src.isDirectory())
         {
             if (src.getPath().equals(path.getPath())) throw new Exception();

             File directory = createDirectory(path, src.getName());

             for (File file : src.listFiles()) copyFile(file, directory);

             return directory;
         }
         else
         {
             File file = new File(path, src.getName());

             FileChannel channel = new FileInputStream(src).getChannel();

             channel.transferTo(0, channel.size(), new FileOutputStream(file).getChannel());

             return file;
         }
     }
     catch (Exception e)
     {
         throw new Exception(String.format("Error copying %s "+e,src.getName()));
     }
 }

转向诺克斯方法

 public void movetoKnox(View view)
 {
     count = movefileList.size();//4
     count2 = multiFile.size();//2
     for (int i =0; i<count; i++)
     {
         for( int j=0; j<count2;j++)
         {
             if(movefileList.get(i).equals(multiFile.get(j)))
             {

                 File temp = new File(multiFile.get(j));
                 try{
                     copyFile(temp,chamberLocation);
                 }catch (Exception e)
                 {
                     Toast.makeText(moveKnox.this, "Exception:"+e,Toast.LENGTH_SHORT).show();
                 }

             }
         }
     }

使用LOGCAT删除游戏和运行后

        11-01 17:09:54.171 31656-31656/com.example.alex.tableappnavrev1
V/moveKnox: Exception: java.lang.Exception: Error copying CIB01
java.lang.Exception: Error copying ni110e2 java.lang.Exception: Error copying 042xf82f.i42 java.io.FileNotFoundException:
/storage/6335-3466/Images/China Lake/CIB01/ni110e2/042xf82f.i42: open
failed: EMFILE (Too many open files)
11-01 17:09:54.181 31656-31656/com.example.alex.tableappnavrev1
V/moveKnox: Exception: java.lang.Exception: Error copying CIB05
java.lang.NullPointerException: Attempt to get length of null array
11-01 17:09:54.181 31656-31656/com.example.alex.tableappnavrev1
V/moveKnox: Exception: java.lang.Exception: Error copying JOGA
java.lang.NullPointerException: Attempt to get length of null array
11-01 17:09:54.181 31656-31656/com.example.alex.tableappnavrev1
V/moveKnox: Exception: java.lang.Exception: Error copying TLM50
java.lang.NullPointerException: Attempt to get length of null array
11-01 17:09:54.191 31656-31656/com.example.alex.tableappnavrev1
I/Choreographer: Skipped 960 frames!  The application may be doing too much work on its main thread.
11-01 17:09:54.191 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:54.191 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:54.191 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:54.191 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:54.191 31656-31708/com.example.alex.tableappnavrev1
W/OpenGLRenderer: swapBuffers encountered EGL_BAD_SURFACE on 0x7f99682d40, halting rendering...
11-01 17:09:54.221 31656-31656/com.example.alex.tableappnavrev1
E/ViewSystem: ViewRootImpl #2 Surface is not valid.
11-01 17:09:54.241 31656-31656/com.example.alex.tableappnavrev1
E/ViewSystem: ViewRootImpl #2 Surface is not valid.
11-01 17:09:54.241 31656-31656/com.example.alex.tableappnavrev1
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e9482ae
time:17868638
11-01 17:09:54.251 31656-31708/com.example.alex.tableappnavrev1
D/OpenGLRenderer: endAllStagingAnimators on 0x7f867f2c00
(RippleDrawable) with handle 0x7f99cf5ee0
11-01 17:09:54.531 31656-31656/com.example.alex.tableappnavrev1
D/ViewRootImpl: #3 mView = null
11-01 17:09:55.851 31656-31708/com.example.alex.tableappnavrev1
E/Parcel: dup() failed in Parcel::read, i is 1, fds[i] is -1, fd_count is 2, error: Too many open files
11-01 17:09:55.851 31656-31708/com.example.alex.tableappnavrev1
E/Surface: dequeueBuffer: IGraphicBufferProducer::requestBuffer
failed: -22
11-01 17:09:55.851 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
E/Parcel: dup() failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 2, error: Too many open files
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
E/Surface: dequeueBuffer: IGraphicBufferProducer::requestBuffer
failed: -22
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
E/Parcel: dup() failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 2, error: Too many open files
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
E/Surface: dequeueBuffer: IGraphicBufferProducer::requestBuffer
failed: -22
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
E/Parcel: dup() failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 2, error: Too many open files
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
E/Surface: dequeueBuffer: IGraphicBufferProducer::requestBuffer
failed: -22
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
I/Adreno: DequeueBuffer: dequeueBuffer failed
11-01 17:09:55.861 31656-31708/com.example.alex.tableappnavrev1
W/OpenGLRenderer: swapBuffers encountered EGL_BAD_SURFACE on 0x7f99682040, halting rendering...
11-01 17:09:55.881 31656-31656/com.example.alex.tableappnavrev1
E/ViewSystem: ViewRootImpl #2 Surface is not valid.
11-01 17:10:08.411 31656-31656/com.example.alex.tableappnavrev1
V/ActivityThread: updateVisibility : ActivityRecord{710a9a1 token=android.os.BinderProxy@e9482ae
{com.example.alex.tableappnavrev1/com.example.alex.tableappnavrev1.MainActivity}}
show : true

0 个答案:

没有答案