3
  1. 这是我正在使用的代码:

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Logger;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import org.apache.commons.codec.binary.Base64;
    
    
     public class Fragment_2 extends Fragment {
    static Logger logger = Logger.getLogger(Fragment_2.class.getSimpleName());
    
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    
     new Thread(new Runnable() {
    
        public void run() {
    
            try {
                 String base64 = null;
                    String imageDataString2 = null;
                    File file = new File("/mnt/sdcard/DCIM/Camera/2013-03-27 00.22.48.jpg");
    
                    try {
                           // Reading a Image file from file system
                           FileInputStream imageInFile = new FileInputStream(file);
                           byte imageData[] = new byte[(int) file.length()];
                           imageInFile.read(imageData);
    
                           // Converting Image byte array into Base64 String
                           String imageDataString = new String(Base64.encodeBase64(imageData));
    
                           imageDataString2 = imageDataString.replace("_", "/");
                           imageDataString2 = imageDataString2.replace("-", "+");
    
                           System.out.println(imageDataString2);
                           base64 = imageDataString2;
                           System.out.println("Image Successfully Manipulated!");
                       } catch (FileNotFoundException e) {
                           System.out.println("Image not found" + e);
                       } catch (IOException ioe) {
                           System.out.println("Exception while reading the Image " + ioe);
                       }                        
                        ClientConfig config = new DefaultClientConfig();
                        Client client = Client.create(config);
                        WebResource service = client.resource(UriBuilder.fromUri("http://xxxxxx:8080/api").build());//change it to the latest URL 
    
                        Form f = new Form();                   
                        f.add("img",base64 );    
    
                        String s = service.post(String.class, f);
    
            } catch (Exception e) {
    
            }           
        }
    
    }).start();                         
     return inflater.inflate(R.layout.fragment_2, container, false);
    }
    
     }
    

这是错误:

03-28 03:50:24.569: W/dalvikvm(20989): Link of class 'Lcom/sun/jersey/core/osgi/OsgiRegistry;' failed
03-28 03:50:24.569: W/dalvikvm(20989): VFY: unable to resolve static method 5977: Lcom/sun/jersey/core/osgi/OsgiRegistry;.getInstance ()Lcom/sun/jersey/core/osgi/OsgiRegistry;
03-28 03:50:24.569: W/dalvikvm(20989): Link of class 'Lcom/sun/jersey/core/osgi/OsgiRegistry;' failed
03-28 03:50:24.569: W/dalvikvm(20989): VFY: unable to find class referenced in signature (Lcom/sun/jersey/core/osgi/OsgiRegistry;)
03-28 03:50:27.379: W/dalvikvm(20989): Exception Ljava/lang/NullPointerException; thrown while initializing Lcom/sun/jersey/core/header/MediaTypes;
03-28 03:50:27.379: W/dalvikvm(20989): threadid=9: thread exiting with uncaught exception (group=0x40018578)
03-28 03:50:27.399: E/AndroidRuntime(20989): FATAL EXCEPTION: Thread-10
03-28 03:50:27.399: E/AndroidRuntime(20989): java.lang.ExceptionInInitializerError
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.core.spi.factory.MessageBodyFactory.getMessageBodyWriterMediaTypes(MessageBodyFactory.java:444)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.api.client.RequestWriter.getMediaType(RequestWriter.java:324)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:282)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:213)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.api.client.Client.handle(Client.java:648)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.api.client.WebResource.post(WebResource.java:251)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.example.programming_fragments.Fragment_2$1.run(Fragment_2.java:91)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at java.lang.Thread.run(Thread.java:1019)
03-28 03:50:27.399: E/AndroidRuntime(20989): Caused by: java.lang.NullPointerException
03-28 03:50:27.399: E/AndroidRuntime(20989):    at javax.ws.rs.core.MediaType.valueOf(MediaType.java:119)
03-28 03:50:27.399: E/AndroidRuntime(20989):    at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
03-28 03:50:27.399: E/AndroidRuntime(20989):    ... 10 more

我应该怎么办?

4

1 回答 1

1

我不确定这是正确的解决方案

根据Jersey deps,您需要jersey-json在依赖项/类路径中有模块。

如果库的名称是 libitv.so 并且在构建 .apk 之前位于应用程序目录的 libs\armeabi 目录中,则该库将被识别。

有时当库没有完全复制(部分复制)时,由于某些系统问题,部分库也将无法识别。

有关更多详细信息,请参阅此处

试试这个链接有一些解决方案

更新:

java.lang.ExceptionInInitializerError

原因:java.lang.UnsatisfiedLinkError:找不到库 jniavutil

除了 libsndfile 之外,您还需要安装 libFLAC。您可能可以使用用于安装 libsndfile 的任何方法安装 libFLAC...

您错过了 ddms 日志中的重要信息。查找包含“由”和/或包含更多异常日志的行,以便我们查看它。

您已在启用 CodePro 覆盖的情况下进行编译。把它关掉。

实际上这是我们在 ADT 17 中面临的问题,您必须将 jar 文件放入 libs 文件夹才能克服此异常

所以右键单击您的项目->创建一个名为libs的文件夹

并按照此步骤

 right click (on libs folder) -->import-->File System-->browse to select your jar file and hit finish and run you project.

在那之后

 right click on the project --> Built Path-->java built path-->add jars select your jar file from your libs folder

如果这也不起作用重建所有内容(包含的数据),它将起作用。

于 2013-03-28T11:04:41.200 回答