问题描述
下面是我的日志猫。可惜我不是一个职业,从logcat中读取错误,所以请大家帮我:)
12月5日至30日:12:16.510:我/的System.out(838):我们做了这么远1
12月5日至30日:12:17.230:我/的System.out(838):我们做了这么远2
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:无法解决的异常类748(LCOM / fasterxml /杰克逊/核心/ JsonParseException;)
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:无法找到地址0x2a异常处理程序
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:拒绝LCOM /例子/ bitmapdisplay / MainActivity $ URLArray; .doInBackground([Ljava /朗/无效;)Ljava /朗/无效;
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:在拒绝运code符进行0x002a
12月5日至30日:12:17.250:W / dalvikvm(838):VFY:拒绝LCOM /例子/ bitmapdisplay / MainActivity $ URLArray; .doInBackground([Ljava /朗/无效;)Ljava /朗/无效;
12月5日至30日:12:17.250:W / dalvikvm(838):验证拒绝类LCOM /例子/ bitmapdisplay / MainActivity $ URLArray;
12月5日至30日:12:17.250:D / AndroidRuntime(838):关闭VM
12月5日至30日:12:17.250:W / dalvikvm(838):主题ID = 1:螺纹未捕获的异常(组= 0xb1adaba8)退出
12月5日至30日:12:17.270:E / AndroidRuntime(838):致命异常:主要
12月5日至30日:12:17.270:E / AndroidRuntime(838):工艺:com.example.bitmapdisplay,PID:838
12月5日至30日:12:17.270:E / AndroidRuntime(838):java.lang.VerifyError:COM /例子/ bitmapdisplay / MainActivity $ URLArray
12月5日至30日:12:17.270:E / AndroidRuntime(838):在com.example.bitmapdisplay.MainActivity.onCreate(MainActivity.java:72)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.Activity.performCreate(Activity.java:5231)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.ActivityThread.access $ 800(ActivityThread.java:135)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.os.Handler.dispatchMessage(Handler.java:102)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.os.Looper.loop(Looper.java:136)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在android.app.ActivityThread.main(ActivityThread.java:5017)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在java.lang.reflect.Method.invokeNative(本机方法)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在java.lang.reflect.Method.invoke(Method.java:515)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12月5日至30日:12:17.270:E / AndroidRuntime(838):在dalvik.system.NativeStart.main(本机方法)
12月5日至30日:12:30.390:I /流程(838):发送信号。 PID:838 SIG:9
下面是logcat的code,这里是我的Java code。这似乎是问题,从线程URLArray来,因为,因为看到在logcat中,该系统甚至不打印第三届我们做了这么远:
包com.example.bitmapdisplay;进口java.io.ByteArrayInputStream中;
进口java.io.ByteArrayOutputStream中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.net.HttpURLConnection中;
进口java.net.MalformedURLException;
进口的java.net.URL;
进口java.net.URLConnection中;
进口的java.util.ArrayList;进口org.apache.http.HttpEntity;
进口org.apache.http.Htt presponse;
进口org.apache.http.HttpStatus;
进口org.apache.http.client.methods.HttpGet;
进口org.apache.http.impl.client.DefaultHttpClient;进口com.fasterxml.jackson.core.JsonParseException;进口android.R;
进口android.app.Activity;
进口android.app.ProgressDialog;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.graphics.drawable.BitmapDrawable;
进口android.os.AsyncTask;
进口android.os.Bundle;
进口android.util.Log;
进口android.widget.ArrayAdapter;
进口android.widget.GridView;
进口android.widget.ImageView;
公共类MainActivity延伸活动{ / **
*位图项目呐DIMAGE显示
* /
位图图像;
BitmapDrawable BD;
ImageView的温度;
ProgressDialog PD; / **
* JSON网址
* /
URL网址; / **
*从JSON文件数据
* /
ArrayList的<串GT;网址;
ArrayList的< ImageView的>图像; JsonParsing OBJ; 字符串json_link_str = \"http://api.tumblr.com/v2/blog/humansofnewyork.com/posts?api_key=7ag2CJXOuxuW3vlVS5wQG6pYA6a2ZQcSCjzZsAp2pDbVwf3xEk¬es_info=true&filter=text\";
INT计数器;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
的System.out.println(我们做了这么远1);
super.onCreate(savedInstanceState);
的setContentView(com.example.bitmapdisplay.R.layout.image_container); 计数器= 0;
照片=新的ArrayList< ImageView的>();
网址=新的ArrayList<串GT;(); 的System.out.println(我们做了这么远2); 新URLArray()执行();
} / **
*填充ListView控件
* /
私人无效fillGridView(){ ArrayAdapter< ImageView的>适配器=新ArrayAdapter< ImageView的>(这一点,com.example.bitmapdisplay.R.layout.image_container,图像); GridView的网格=(GridView控件)findViewById(com.example.bitmapdisplay.R.id.gvImages); grid.setAdapter(适配器); } 公共类URLArray扩展的AsyncTask<太虚,太虚,太虚> { 公共URLArray(){ } @覆盖
保护无效doInBackground(虚空...... PARAMS){
尝试{
的System.out.println(我们做了这么远3); 网址json_link =新的URL(json_link_str); JsonParsing parse_images =新JsonParsing(json_link); 尝试{
parse_images.parseFile(3,URL)的;
的System.out.println(我们做了这么远4); }赶上(JsonParseException E){
// TODO自动生成catch块
e.printStackTrace();
}赶上(IOException异常五){
// TODO自动生成catch块
e.printStackTrace();
} OBJ = parse_images;
}赶上(MalformedURLException的E){
// TODO自动生成catch块
e.printStackTrace();
} 返回null;
} @覆盖
保护无效onPostExecute(无效ARG){
super.on preExecute();
的System.out.println(我们做了这么远5); 网址= obj.getURLs();
新TheTask()执行();
} }
类TheTask扩展的AsyncTask<太虚,太虚,太虚>
{
@覆盖
保护无效doInBackground(虚空...... PARAMS){ 的System.out.println(我们做了这么远6); PD =新ProgressDialog(MainActivity。本);
pd.show();
的System.out.println(我们做了这么远7); 尝试
{
INT计数器= 0;
对于(ImageView的温度:图像){ 图像= downloadBitmap(urls.get(计数器));
temp.setImageBitmap(图片);
images.add(临时);
反++;
}
}
赶上(例外五)
{
e.printStackTrace();
}
返回null;
} @覆盖
保护无效onPostExecute(虚空结果){ 的System.out.println(我们做了这么远8); super.onPostExecute(结果);
pd.dismiss();
如果(形象!= NULL)
{
fillGridView();
} }
}
私人位图downloadBitmap(字符串URL){
//用来初始化默认的HTTP客户端对象
最后DefaultHttpClient客户端=新DefaultHttpClient(); //形成HttoGet要求
最终HTTPGET调用getRequest =新HTTPGET(URL);
尝试{ HTT presponse响应= client.execute(调用getRequest); //检查成功200 OK
。最终诠释状态code = response.getStatusLine()的getStatus code(); 如果(状态code!= HttpStatus.SC_OK){
Log.w(ImageDownloader,错误+状态code +
而从检索位图+网址);
返回null; } 最终HttpEntity实体= response.getEntity();
如果(实体!= NULL){
为InputStream的InputStream = NULL;
尝试{
//从流获取内容
的InputStream = entity.getContent(); //解码流数据回图像位图理解的android
图像= BitmapFactory.de codeStream(InputStream的);
} {最后
如果(的InputStream!= NULL){
inputStream.close();
}
entity.consumeContent();
}
}
}赶上(例外五){
//你可以提供一个IOException异常更明确的错误信息
getRequest.abort();
Log.e(ImageDownloader,出事了,而+
从检索位图+ URL + e.toString());
} 返回形象;
}
}
问题的关键就在这里。
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:无法解决的异常类748(LCOM / fasterxml /杰克逊/核心/ JsonParseException;)
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:无法找到地址0x2a异常处理程序
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:拒绝LCOM /例子/ bitmapdisplay / MainActivity $ URLArray; .doInBackground([Ljava /朗/无效;)Ljava /朗/无效;
12月5日至30日:12:17.240:W / dalvikvm(838):VFY:在拒绝运code符进行0x002a
12月5日至30日:12:17.250:W / dalvikvm(838):VFY:拒绝LCOM /例子/ bitmapdisplay / MainActivity $ URLArray; .doInBackground([Ljava /朗/无效;)Ljava /朗/无效;
12月5日至30日:12:17.250:W / dalvikvm(838):验证拒绝类LCOM /例子/ bitmapdisplay / MainActivity $ URLArray;
,这一切从那里下坡。
看起来
(距杰克逊可能是其他类)不会被纳入您的APK JsonParseException。如果他们没有被Eclipse的出口可能发生这种情况。
而不是将其添加为一个外部库,只需将杰克逊核心xxxjar
在库
文件夹你的Android项目的,它应该足以确保这一点。
Here is my log cat. Unfortunately I am not a pro in reading errors from logcat so please help me :)
05-30 12:12:16.510: I/System.out(838): We made it this far 1
05-30 12:12:17.230: I/System.out(838): We made it this far 2
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to resolve exception class 748 (Lcom/fasterxml/jackson/core/JsonParseException;)
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to find exception handler at addr 0x2a
05-30 12:12:17.240: W/dalvikvm(838): VFY: rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.240: W/dalvikvm(838): VFY: rejecting opcode 0x0d at 0x002a
05-30 12:12:17.250: W/dalvikvm(838): VFY: rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.250: W/dalvikvm(838): Verifier rejected class Lcom/example/bitmapdisplay/MainActivity$URLArray;
05-30 12:12:17.250: D/AndroidRuntime(838): Shutting down VM
05-30 12:12:17.250: W/dalvikvm(838): threadid=1: thread exiting with uncaught exception (group=0xb1adaba8)
05-30 12:12:17.270: E/AndroidRuntime(838): FATAL EXCEPTION: main
05-30 12:12:17.270: E/AndroidRuntime(838): Process: com.example.bitmapdisplay, PID: 838
05-30 12:12:17.270: E/AndroidRuntime(838): java.lang.VerifyError: com/example/bitmapdisplay/MainActivity$URLArray
05-30 12:12:17.270: E/AndroidRuntime(838): at com.example.bitmapdisplay.MainActivity.onCreate(MainActivity.java:72)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.Activity.performCreate(Activity.java:5231)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.os.Looper.loop(Looper.java:136)
05-30 12:12:17.270: E/AndroidRuntime(838): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-30 12:12:17.270: E/AndroidRuntime(838): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 12:12:17.270: E/AndroidRuntime(838): at java.lang.reflect.Method.invoke(Method.java:515)
05-30 12:12:17.270: E/AndroidRuntime(838): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-30 12:12:17.270: E/AndroidRuntime(838): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-30 12:12:17.270: E/AndroidRuntime(838): at dalvik.system.NativeStart.main(Native Method)
05-30 12:12:30.390: I/Process(838): Sending signal. PID: 838 SIG: 9
Here is the logcat code and here is my Java code. It seems like the problems are coming from the thread URLArray because, as seen in the logcat, the system doesn't even print the third "we made it this far":
package com.example.bitmapdisplay;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import com.fasterxml.jackson.core.JsonParseException;
import android.R;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class MainActivity extends Activity {
/**
* Bitmap items na dimage displaying
*/
Bitmap image;
BitmapDrawable bd;
ImageView temp;
ProgressDialog pd;
/**
* JSON URL
*/
URL url;
/**
* Data from JSON file
*/
ArrayList<String> urls;
ArrayList<ImageView> images;
JsonParsing obj;
String json_link_str = "http://api.tumblr.com/v2/blog/humansofnewyork.com/posts?api_key=7ag2CJXOuxuW3vlVS5wQG6pYA6a2ZQcSCjzZsAp2pDbVwf3xEk¬es_info=true&filter=text";
int counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println(" We made it this far 1");
super.onCreate(savedInstanceState);
setContentView(com.example.bitmapdisplay.R.layout.image_container);
counter = 0;
images = new ArrayList<ImageView>();
urls = new ArrayList<String>();
System.out.println(" We made it this far 2");
new URLArray().execute();
}
/**
* Fills the ListView
*/
private void fillGridView() {
ArrayAdapter<ImageView> adapter = new ArrayAdapter<ImageView>(this, com.example.bitmapdisplay.R.layout.image_container,images);
GridView grid = (GridView) findViewById(com.example.bitmapdisplay.R.id.gvImages);
grid.setAdapter(adapter);
}
public class URLArray extends AsyncTask<Void, Void, Void > {
public URLArray() {
}
@Override
protected Void doInBackground(Void...params ) {
try {
System.out.println(" We made it this far 3");
URL json_link = new URL(json_link_str);
JsonParsing parse_images = new JsonParsing(json_link);
try {
parse_images.parseFile(3, urls);
System.out.println(" We made it this far 4");
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
obj = parse_images;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void arg) {
super.onPreExecute();
System.out.println(" We made it this far 5");
urls = obj.getURLs();
new TheTask().execute();
}
}
class TheTask extends AsyncTask<Void,Void,Void>
{
@Override
protected Void doInBackground(Void... params) {
System.out.println(" We made it this far 6");
pd = new ProgressDialog(MainActivity .this);
pd.show();
System.out.println(" We made it this far 7");
try
{
int counter = 0;
for (ImageView temp : images) {
image = downloadBitmap(urls.get(counter));
temp.setImageBitmap(image);
images.add(temp);
counter++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
System.out.println(" We made it this far 8");
super.onPostExecute(result);
pd.dismiss();
if(image!=null)
{
fillGridView();
}
}
}
private Bitmap downloadBitmap(String url) {
// initilize the default HTTP client object
final DefaultHttpClient client = new DefaultHttpClient();
//forming a HttoGet request
final HttpGet getRequest = new HttpGet(url);
try {
HttpResponse response = client.execute(getRequest);
//check 200 OK for success
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("ImageDownloader", "Error " + statusCode +
" while retrieving bitmap from " + url);
return null;
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
// getting contents from the stream
inputStream = entity.getContent();
// decoding stream data back into image Bitmap that android understands
image = BitmapFactory.decodeStream(inputStream);
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
} catch (Exception e) {
// You Could provide a more explicit error message for IOException
getRequest.abort();
Log.e("ImageDownloader", "Something went wrong while" +
" retrieving bitmap from " + url + e.toString());
}
return image;
}
}
The key problem is here
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to resolve exception class 748 (Lcom/fasterxml/jackson/core/JsonParseException;)
05-30 12:12:17.240: W/dalvikvm(838): VFY: unable to find exception handler at addr 0x2a
05-30 12:12:17.240: W/dalvikvm(838): VFY: rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.240: W/dalvikvm(838): VFY: rejecting opcode 0x0d at 0x002a
05-30 12:12:17.250: W/dalvikvm(838): VFY: rejected Lcom/example/bitmapdisplay/MainActivity$URLArray;.doInBackground ([Ljava/lang/Void;)Ljava/lang/Void;
05-30 12:12:17.250: W/dalvikvm(838): Verifier rejected class Lcom/example/bitmapdisplay/MainActivity$URLArray;
and it all goes downhill from there.
Looks like JsonParseException
(and possibly other classes from Jackson) are not being included in your APK. This could happen if they're not being exported by Eclipse.
Instead of adding it as an external library, just place jackson-core-x.x.x.jar
in the libs
folder of your Android project and it should be enough to ensure this.
这篇关于杰克逊使用Android的解析器崩溃的VerifyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!