Android-java.lang.实例化异常:can';t实例化类:没有空构造函数
我正在制作一个显示快速拨号的应用程序,但每当我运行该应用程序时,我都会收到消息 java.lang.InstanceException:无法实例化类:没有空构造函数 我该如何解决这个问题Android-java.lang.实例化异常:can';t实例化类:没有空构造函数,java,android,exception,runtime-error,instantiation,Java,Android,Exception,Runtime Error,Instantiation,我正在制作一个显示快速拨号的应用程序,但每当我运行该应用程序时,我都会收到消息 java.lang.InstanceException:无法实例化类:没有空构造函数 我该如何解决这个问题 import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
public class Needle extends View {
private Paint linePaint;
private Path linePath;
private Paint needleScrewPaint;
private Matrix matrix;
private int framePerSeconds = 100;
private long animationDuration = 10000;
private long startTime;
public Needle(Context context) {
super(context);
matrix = new Matrix();
this.startTime = System.currentTimeMillis();
this.postInvalidate();
init();
}
public Needle(Context context, AttributeSet attrs) {
super(context, attrs);
matrix = new Matrix();
this.startTime = System.currentTimeMillis();
this.postInvalidate();
init();
}
public Needle(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
matrix = new Matrix();
this.startTime = System.currentTimeMillis();
this.postInvalidate();
init();
}
private void init(){
linePaint = new Paint();
linePaint.setColor(Color.RED); // Set the color
linePaint.setStyle(Paint.Style.FILL_AND_STROKE); // set the border and fills the inside of needle
linePaint.setAntiAlias(true);
linePaint.setStrokeWidth(5.0f); // width of the border
linePaint.setShadowLayer(8.0f, 0.1f, 0.1f, Color.GRAY); // Shadow of the needle
linePath = new Path();
linePath.moveTo(50.0f, 50.0f);
linePath.lineTo(130.0f, 40.0f);
linePath.lineTo(600.0f, 50.0f);
linePath.lineTo(130.0f, 60.0f);
linePath.lineTo(50.0f, 50.0f);
linePath.addCircle(130.0f, 50.0f, 20.0f, Path.Direction.CW);
linePath.close();
needleScrewPaint = new Paint();
needleScrewPaint.setColor(Color.BLACK);
needleScrewPaint.setAntiAlias(true);
needleScrewPaint.setShader(new RadialGradient(130.0f, 50.0f, 10.0f,
Color.DKGRAY, Color.BLACK, Shader.TileMode.CLAMP));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
long elapsedTime = System.currentTimeMillis() - startTime;
matrix.postRotate(1.0f, 130.0f, 50.0f); // rotate 10 degree every second
canvas.concat(matrix);
canvas.drawPath(linePath, linePaint);
canvas.drawCircle(130.0f, 50.0f, 16.0f, needleScrewPaint);
if(elapsedTime < animationDuration){
this.postInvalidateDelayed(10000 / framePerSeconds);
}
//this.postInvalidateOnAnimation();
invalidate();
}
}
导入android.content.Context;
导入android.graphics.Canvas;
导入android.graphics.Color;
导入android.graphics.Matrix;
导入android.graphics.Paint;
导入android.graphics.Path;
导入android.graphics.RadialGradient;
导入android.graphics.Shader;
导入android.util.AttributeSet;
导入android.view.view;
公共类视图{
私人油漆;
专用路径linePath;
私人涂料;
私有矩阵;
私有整数帧每秒=100;
私有长动画持续时间=10000;
私人长启动时间;
公共针头(上下文){
超级(上下文);
矩阵=新矩阵();
this.startTime=System.currentTimeMillis();
此。postInvalidate();
init();
}
公共指针(上下文、属性集属性){
超级(上下文,attrs);
矩阵=新矩阵();
this.startTime=System.currentTimeMillis();
此。postInvalidate();
init();
}
公共指针(上下文上下文、属性集属性、int-defStyleAttr){
super(上下文、attrs、defStyleAttr);
矩阵=新矩阵();
this.startTime=System.currentTimeMillis();
此。postInvalidate();
init();
}
私有void init(){
linePaint=新油漆();
linePaint.setColor(Color.RED);//设置颜色
linePaint.setStyle(Paint.Style.FILL_和_STROKE);//设置边框并填充针的内部
linePaint.setAntiAlias(真);
linePaint.setStrokeWidth(5.0f);//边框的宽度
linePaint.setShadowLayer(8.0f、0.1f、0.1f、Color.GRAY);//指针的阴影
linePath=新路径();
线路路径。移动到(50.0f,50.0f);
linePath.lineTo(130.0f,40.0f);
linePath.lineTo(600.0f,50.0f);
linePath.lineTo(130.0f,60.0f);
linePath.lineTo(50.0f,50.0f);
直线路径添加圆(130.0f、50.0f、20.0f,路径方向CW);
linePath.close();
针线漆=新漆();
针线漆。设置颜色(颜色。黑色);
needleScrewPaint.setAntiAlias(真);
针头螺纹漆.固定涂层(新径向梯度(130.0f、50.0f、10.0f、,
Color.DKGRAY、Color.BLACK、Shader.TileMode.CLAMP);
}
@凌驾
受保护的void onDraw(画布){
super.onDraw(帆布);
long elapsedTime=System.currentTimeMillis()-startTime;
矩阵。后旋转(1.0f、130.0f、50.0f);//每秒旋转10度
canvas.concat(矩阵);
canvas.drawPath(linePath、linePaint);
画布.画圈(130.0f,50.0f,16.0f,针线漆);
if(elapsedTime
在清单的某个地方,有一个
元素,指示com.needle.views.needle
是活动的子类
而且,在Java代码中的某个地方,您正在调用startActivity()
,其意图是指向com.needle.views.needle
但是,com.needle.views.needle
不是从活动继承的。它继承自视图
。不能将其用作活动
当然欢迎您创建一个从活动
继承的不同类,该类使用指针
作为其用户界面的一部分。您在哪里调用该类指针?请发布整个堆栈跟踪。Strack跟踪,让狗查看rabbit@MicheleLacorte针线是唯一的类,这是主要的activity@CommonsWare“堆栈跟踪”是什么意思?很抱歉,我今天刚开始使用堆栈溢出
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{needle.ibizsmart.com.needle/com.needle.views.Needle}: java.lang.InstantiationException: can't instantiate class com.needle.views.Needle; no empty constructor