gpt4 book ai didi

添加手势支持后 Android 崩溃

转载 作者:行者123 更新时间:2023-12-02 09:28:04 25 4
gpt4 key购买 nike

我的应用程序运行良好,尽管没有任何功能,但由于我添加了对手势的支持(改编自教程的代码),它现在在运行时崩溃。

package com.mystraldesign.memorable;

import android.app.Activity;
//import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGestureListener;
import android.graphics.Typeface;
import android.os.Bundle;
//import android.widget.RelativeLayout;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.MotionEvent;
import android.view.Window;
import android.widget.TextView;

public class MemorableActivity extends Activity implements OnGestureListener,OnDoubleTapListener
{
//Define text views
private TextView textView1;
private TextView textView2;
private TextView textView3;
private TextView textView4;

//Gesture Detectors
private GestureDetector gTap;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

gTap = new GestureDetector(this,(android.view.GestureDetector.OnGestureListener) this);

//Remove title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);




//Define textView
textView1 = (TextView) findViewById(R.id.textView1);
textView2 = (TextView) findViewById(R.id.textView2);
textView3 = (TextView) findViewById(R.id.textView3);
textView4 = (TextView) findViewById(R.id.textView4);

//Load font file
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf");

//Set various textViews to font
textView1.setTypeface(type);
textView2.setTypeface(type);
textView3.setTypeface(type);
textView4.setTypeface(type);


}



public boolean onTouchEvent(MotionEvent me){
this.gTap.onTouchEvent(me);
return super.onTouchEvent(me);
}

public boolean onDown(MotionEvent e) {
textView1.setText("Down");
return false;
}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
textView1.setText("Fling");
return false;
}


public void onLongPress(MotionEvent e) {
textView1.setText("Long Press");
}


public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
textView1.setText("Scroll");
return false;
}


public void onShowPress(MotionEvent e) {
textView1.setText("Show Press");
}

public boolean onSingleTapUp(MotionEvent e) {
textView1.setText("Sing Tap Up");
return false;
}

public boolean onDoubleTap(MotionEvent e) {
textView1.setText("Double Tap");
return false;
}

public boolean onDoubleTapEvent(MotionEvent e) {
textView1.setText("Double Tap Event");
return false;
}

public boolean onSingleTapConfirmed(MotionEvent e) {
textView1.setText("Single Tap Confirmed");
return false;
}




}

我从每个方法的开头删除了一个 @override 语句,因为 Eclipse 声明了这些方法的错误,并给出了自动修复以删除 @override 语句。

它还在 public class MemorableActivity extends Activity Implements OnGestureListener,OnDoubleTapListener 行上给出了一个错误:

Multiple markers at this line
- The type MemorableActivity must implement the inherited abstract method
GestureOverlayView.OnGestureListener.onGestureEnded(GestureOverlayView, MotionEvent)
- The type MemorableActivity must implement the inherited abstract method
GestureOverlayView.OnGestureListener.onGestureCancelled(GestureOverlayView, MotionEvent)
- The type MemorableActivity must implement the inherited abstract method
GestureOverlayView.OnGestureListener.onGestureStarted(GestureOverlayView, MotionEvent)
- The type MemorableActivity must implement the inherited abstract method
GestureOverlayView.OnGestureListener.onGesture(GestureOverlayView, MotionEvent)

它建议修复

Add unimplemented methods
Make MemorableActivity abstract
Rename in file
Rename in workspace

我尝试了前两个,但它仍然崩溃,我不确定第二个和第三个是什么/做什么。

日志中似乎没有任何内容,但这是控制台的输出

[2012-04-30 03:54:37 - Memorable] ------------------------------
[2012-04-30 03:54:37 - Memorable] Android Launch!
[2012-04-30 03:54:37 - Memorable] adb is running normally.
[2012-04-30 03:54:38 - Memorable] Performing com.mystraldesign.memorable.MemorableActivity activity launch
[2012-04-30 03:54:38 - Memorable] Automatic Target Mode: launching new emulator with compatible AVD 'Memorable'
[2012-04-30 03:54:38 - Memorable] Launching a new emulator with Virtual Device 'Memorable'
[2012-04-30 03:54:44 - Emulator] 2012-04-30 03:54:44.155 emulator-arm[2796:1107] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.
[2012-04-30 03:54:44 - Memorable] New emulator found: emulator-5554
[2012-04-30 03:54:44 - Memorable] Waiting for HOME ('android.process.acore') to be launched...
[2012-04-30 03:55:36 - Memorable] HOME is up on device 'emulator-5554'
[2012-04-30 03:55:36 - Memorable] Uploading Memorable.apk onto device 'emulator-5554'
[2012-04-30 03:55:41 - Memorable] Installing Memorable.apk...
[2012-04-30 03:55:57 - Memorable] Success!
[2012-04-30 03:55:57 - Memorable] Starting activity com.mystraldesign.memorable.MemorableActivity on device emulator-5554
[2012-04-30 03:56:00 - Memorable] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mystraldesign.memorable/.MemorableActivity }

编辑:

从 Eclipse 添加日志

04-30 05:43:25.339: D/AndroidRuntime(333): Shutting down VM
04-30 05:43:25.339: W/dalvikvm(333): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-30 05:43:25.369: E/AndroidRuntime(333): FATAL EXCEPTION: main
04-30 05:43:25.369: E/AndroidRuntime(333): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mystraldesign.memorable/com.mystraldesign.memorable.MemorableActivity}: java.lang.ClassCastException: com.mystraldesign.memorable.MemorableActivity
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.os.Looper.loop(Looper.java:123)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-30 05:43:25.369: E/AndroidRuntime(333): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 05:43:25.369: E/AndroidRuntime(333): at java.lang.reflect.Method.invoke(Method.java:507)
04-30 05:43:25.369: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-30 05:43:25.369: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-30 05:43:25.369: E/AndroidRuntime(333): at dalvik.system.NativeStart.main(Native Method)
04-30 05:43:25.369: E/AndroidRuntime(333): Caused by: java.lang.ClassCastException: com.mystraldesign.memorable.MemorableActivity
04-30 05:43:25.369: E/AndroidRuntime(333): at com.mystraldesign.memorable.MemorableActivity.onCreate(MemorableActivity.java:33)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-30 05:43:25.369: E/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-30 05:43:25.369: E/AndroidRuntime(333): ... 11 more

最佳答案

您正在实现一种类型的 OnGestureListener 但转换为另一种类型。将您的 Activity 类语句更改为:

public class MemorableActivity extends Activity implements android.view.GestureDetector.OnGestureListener,OnDoubleTapListener 

然后实现必要的方法,您的崩溃应该停止发生。

关于添加手势支持后 Android 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10378524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com