当使用泽西在Android应用宁静的api我得到这个错误: [英] When using Jersey for restful api in Android app I get this error:

查看:204
本文介绍了当使用泽西在Android应用宁静的api我得到这个错误:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 下面是code,我现在用:

  1. Here is the code that i am using :

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

我应该怎么办?

推荐答案

林不知道这是正确的解决方案。

im not sure this is right solution

C $ C>在你的依赖球衣,JSON 模块/类路径。

according to Jersey deps you need to have jersey-json module in your dependencies/classpath.

如果它的名字是libitv.so该库将被识别,并放置在库\\ armeabi目录中的应用程序目录,apk文件是建立之前。

The library will be recognised if its name is libitv.so and is placed in libs\armeabi directory in your application directory, before the .apk is built.

有时,当库不是完全复制(部分复制),由于一些系统发出的部分库也不会被认可。

Sometimes when the library is not copied completely(partial copy), due to some system issues the partial library too will not be recognized.

有关详细信息,请参阅这里

For more details refer here

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

try this link have some solution

更新:

java.lang.ExceptionInInitializerError

产生的原因: java.lang.UnsatisfiedLinkError中:图书馆jniavutil没有找到

Caused by: java.lang.UnsatisfiedLinkError: Library jniavutil not found

您除了需要libsndfile安装libFLAC。
您可以使用libFLAC你使用任何方法可能安装
得到libsndfile安装...

You need to install libFLAC in addition to libsndfile. You can probably install libFLAC using whatever method you used to get libsndfile installed...

您已经错过了从DDMS日志importent位。寻找一个
行,其中包括所造成的和/或包括多个异常
日志,所以我们可以看看它。

You have missed out the importent bits from the ddms log. Look for a line that includes "caused by" and/or include more of the exception log so we can have a look at it.

您已经与$ C $启用覆盖CPRO编译。将其关闭。

You've compiled with CodePro coverage enabled. Turn it off.

其实这是为了克服这个例外,我们正面临着ADT 17,你必须把你的jar文件到库问题文件夹

Actually this is the problem we are facing with ADT 17 you have to put your jar file into libs folder in order to overcome this exception

在你的项目,所以右键 - >创建一个名称的文件夹的

so right click on your project -->create a folder with name 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

如果这也没有重建工作
一切(包括数据),它会工作。

if this also didn't work rebuilding everything (included data), and it will works.

这篇关于当使用泽西在Android应用宁静的api我得到这个错误:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆