我是android开发的新手,希望大家能帮助我。我从互联网上得到了这个 androidVNC 查看器源代码。当我在模拟器中运行 androidVNC 应用程序时,它将自动退出,然后我在 LogCat 中出现以下错误。任何人都可以帮助我吗?谢谢。
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{android.androidVNC/android.androidVNC.VncCanvasActivity}: java.lang.ClassCastException: com.antlersoft.android.zoomer.ZoomControls cannot be cast to android.widget.ZoomControls
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.antlersoft.android.zoomer.ZoomControls cannot be cast to android.widget.ZoomControls
at android.androidVNC.VncCanvasActivity.onCreate(VncCanvasActivity.java:585)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
... 11 more
这是 ZoomControls java 文件:
package com.antlersoft.android.zoomer;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ZoomButton;
public class ZoomControls extends LinearLayout {
private final ZoomButton mZoomIn;
private final ZoomButton mZoomOut;
private final ImageButton mZoomKeyboard;
public ZoomControls(Context context) {
this(context, null);
}
public ZoomControls(Context context, AttributeSet attrs) {
super(context, attrs);
setFocusable(false);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.zoom_controls, this, // we are the parent
true);
mZoomIn = (ZoomButton) findViewById(R.id.zoomIn);
mZoomOut = (ZoomButton) findViewById(R.id.zoomOut);
mZoomKeyboard = (ImageButton) findViewById(R.id.zoomKeys);
}
public void setOnZoomInClickListener(OnClickListener listener) {
mZoomIn.setOnClickListener(listener);
}
public void setOnZoomOutClickListener(OnClickListener listener) {
mZoomOut.setOnClickListener(listener);
}
public void setOnZoomKeyboardClickListener(OnClickListener listener) {
mZoomKeyboard.setOnClickListener(listener);
}
/*
* Sets how fast you get zoom events when the user holds down the
* zoom in/out buttons.
*/
public void setZoomSpeed(long speed) {
mZoomIn.setZoomSpeed(speed);
mZoomOut.setZoomSpeed(speed);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
/* Consume all touch events so they don't get dispatched to the view
* beneath this view.
*/
return true;
}
public void show() {
fade(View.VISIBLE, 0.0f, 1.0f);
}
public void hide() {
fade(View.GONE, 1.0f, 0.0f);
}
private void fade(int visibility, float startAlpha, float endAlpha) {
AlphaAnimation anim = new AlphaAnimation(startAlpha, endAlpha);
anim.setDuration(500);
startAnimation(anim);
setVisibility(visibility);
}
public void setIsZoomInEnabled(boolean isEnabled) {
mZoomIn.setEnabled(isEnabled);
}
public void setIsZoomOutEnabled(boolean isEnabled) {
mZoomOut.setEnabled(isEnabled);
}
@Override
public boolean hasFocus() {
return mZoomIn.hasFocus() || mZoomOut.hasFocus();
}
}
这是 zoom_controls XML 文件:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ZoomButton android:id="@+id/zoomOut"
android:background="@drawable/btn_zoom_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton android:id="@+id/zoomKeys"
android:background="@android:drawable/ic_dialog_dialer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ZoomButton android:id="@+id/zoomIn"
android:background="@drawable/btn_zoom_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</merge>