本文介绍了ClassNotFoundException的为Android应用程序定制的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下异常...
08-12 14:19:41.564:ERROR / AndroidRuntime(797):抛出java.lang.ClassNotFoundException:com.widgets.utils.CustomRoundedCornerImageView装载机dalvik.system所致。 PathClassLoader [。]
我创建了一个自定义的ImageView即 com.widgets.utils.CustomRoundedCornerImageView ,并在布局XML使用它。该CustomRoundedCornerImageView.java是在类路径与其他类。
CustomRoundedCornerImageView.java
包com.widgets.utils;
进口android.content.Context;
进口android.graphics.Bitmap;
进口android.graphics.Bitmap.Config;
进口android.graphics.Canvas;
进口android.graphics.Paint;
进口android.graphics.PorterDuff.Mode;
进口android.graphics.PorterDuffXfermode;
进口android.graphics.Rect;
进口android.graphics.RectF;
进口android.graphics.drawable.BitmapDrawable;
进口android.graphics.drawable.Drawable;
进口android.util.AttributeSet;
进口android.widget.ImageView;
公共类CustomRoundedCornerImageView扩展ImageView的{
公共CustomRoundedCornerImageView(上下文的背景下){
超(上下文);
}
公共CustomRoundedCornerImageView(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
}
公共CustomRoundedCornerImageView(上下文的背景下,ATTRS的AttributeSet,
INT defStyle){
超(背景下,ATTRS,defStyle);
}
@覆盖
保护无效的OnDraw(帆布油画){
可绘制绘制= getDrawable();
位图B =((BitmapDrawable)可拉伸).getBitmap();
点阵位图= b.copy(Bitmap.Config.ARGB_8888,真正的);
位图roundBitmap = getRoundedCornerBitmap(位图,30);
canvas.drawBitmap(roundBitmap,0,0,NULL);
}
公共静态位图getRoundedCornerBitmap(位图位图,诠释像素){
位图roundedBitmap = Bitmap.createBitmap(bitmap.getWidth(),位图
.getHeight(),Config.ARGB_8888);
帆布油画=新的Canvas(roundedBitmap);
最终诠释色= 0xff424242;
最终的涂料粉刷=新的油漆();
最终矩形矩形=新的Rect(0,0,bitmap.getWidth(),bitmap.getHeight());
最后RectF rectF =新RectF(RECT);
最终浮动roundPx =像素;
paint.setAntiAlias(真正的);
canvas.drawARGB(0,0,0,0);
paint.setColor(颜色);
canvas.drawRoundRect(rectF,roundPx,roundPx,油漆);
paint.setXfermode(新PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(位图,矩形,矩形,油漆);
返回roundedBitmap;
}
}
layout.xml
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / picture_frame
机器人:layout_width =70px
机器人:layout_height =70px
机器人:重力=中心
机器人:layout_marginTop =5像素
机器人:layout_marginLeft =40PX
机器人:可聚焦=假
机器人:能见度=隐形
机器人:背景=@可绘制/ picture_frame>
< com.widgets.utils.CustomRoundedCornerImageView
机器人:ID =@ + ID /图片
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:scaleType =centerCrop
机器人:可聚焦=FALSE/>
< / LinearLayout中>
你能不能帮我,为什么我得到了ClassNotFoundException?
解决方案
< com.widgets.utils.CustomRoundedCornerImageView
机器人:ID =@ + ID /图片
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:scaleType =centerCrop
机器人:可聚焦=FALSE/>
在此,你必须改变
< ImageView的类=com.widgets.utils.CustomRoundedCornerImageView
机器人:ID =@ + ID /图片
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:scaleType =centerCrop
机器人:可聚焦=FALSE/>
I am getting following exception...
08-12 14:19:41.564: ERROR/AndroidRuntime(797): Caused by: java.lang.ClassNotFoundException: com.widgets.utils.CustomRoundedCornerImageView in loader dalvik.system.PathClassLoader[.]
I have created a custom ImageView i.e. com.widgets.utils.CustomRoundedCornerImageView and using it in a layout xml . The CustomRoundedCornerImageView.java is in class path with other classes.
CustomRoundedCornerImageView.java
package com.widgets.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
public class CustomRoundedCornerImageView extends ImageView {
public CustomRoundedCornerImageView(Context context) {
super(context);
}
public CustomRoundedCornerImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomRoundedCornerImageView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
Bitmap b = ((BitmapDrawable)drawable).getBitmap() ;
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
Bitmap roundBitmap = getRoundedCornerBitmap(bitmap,30);
canvas.drawBitmap(roundBitmap, 0,0 , null);
}
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap roundedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(roundedBitmap);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return roundedBitmap;
}
}
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/picture_frame"
android:layout_width="70px"
android:layout_height="70px"
android:gravity="center"
android:layout_marginTop="5px"
android:layout_marginLeft="40px"
android:focusable="false"
android:visibility="invisible"
android:background="@drawable/picture_frame">
<com.widgets.utils.CustomRoundedCornerImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:focusable="false" />
</LinearLayout>
Can you help me why I am getting ClassNotFoundException ?
解决方案
<com.widgets.utils.CustomRoundedCornerImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:focusable="false" />
in this you have to change
<ImageView class="com.widgets.utils.CustomRoundedCornerImageView"
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:focusable="false" />
这篇关于ClassNotFoundException的为Android应用程序定制的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!