2013-03-28 67 views
3
  1. 這裏是我使用的代碼:當使用澤西在Android應用寧靜的API,我得到這個錯誤:

    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 

我該怎麼辦?

+0

引起:java.lang.NullPointerException 03-28 03:50:27.399:E/AndroidRuntime(20989):在javax.ws.rs.core.MediaType.valueOf(MediaType.java:119).... – 2013-03-28 11:00:26

回答

1

林不知道這是正確的解決方案,根據你需要有jersey-json模塊在你的依賴/ classpath中Jersey deps

如果庫的名稱爲libitv.so,並且在建立.apk之前將其放入應用程序目錄中的libs \ armeabi目錄中,它將被識別。

有時,當庫沒有完全複製(部分複製)時,由於某些系統問題,部分庫也無法識別。

欲瞭解更多詳情,請參閱here

試試這個link有一些解決方案

更新:

java.lang.ExceptionInInitializerError 

產生的原因:java.lang.UnsatisfiedLinkError:圖書館jniavutil沒有找到

您需要安裝除libsndfil外還有libFLAC即 您可以使用您使用 得到libsndfile安裝

您已經錯過了從DDMS日誌importent位任何方法... libFLAC可能安裝。查找 行,其中包含「由......引起」和/或包含更多異常 日誌,以便我們可以查看它。

您已啓用CodePro覆蓋進行編譯。把它關掉。

其實這是我們面臨與ADT 17,你必須把你的jar文件到庫爲了克服這個異常

所以右鍵點擊你的項目文件夾中的問題 - >創建一個文件夾名

,並按照該步驟中

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 

如果這也沒有工作重建 一切(包括數據),它會起作用。

+0

我在我的依賴關係/ classpath中有球衣捆綁,是不是夠了 – 2013-03-28 11:10:44

+0

@MosabAldahayyat嘗試我的更新鏈接它有一些解決方案它會幫助你 – Sathish 2013-03-28 11:13:13

+0

@MosabAldahayyat嘗試更新的答案 – Sathish 2013-03-28 11:21:29

相關問題