Android Touch免费手势识别应用程序错误

时间:2013-04-13 19:14:41

标签: android gesture-recognition

我们正在构建一个关于无触摸手势识别的Android应用程序。

** * CODE摘要:

  

通过代码,我们试图通过手动更改文本字段中的文本   刷卡。当用户从右向左滑动手时,文本   应该改为左......等等。当我们运行应用程序时,我们得到以下   错误,请帮我们解决。*

**

我读过manny与我的错误相关的类似错误,没有一个能解决我的错误。

请帮助

我们收到以下错误:

04-14 00:05:39.393: E/AndroidRuntime(333): FATAL EXCEPTION: main   04-14 00:05:39.393: E/AndroidRuntime(333): java.lang.RuntimeException: Unable to instantiate activity  ComponentInfo{com.grex/com.grex.MainActivity}: java.lang.ClassNotFoundException: com.grex.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.grex-1.apk]
04-14 00:05:39.393: E/AndroidRuntime(333): at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.os.Handler.dispatchMessage(Handler.java:99) 
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.os.Looper.loop(Looper.java:123)
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.app.ActivityThread.main(ActivityThread.java:3683) 
04-14 00:05:39.393: E/AndroidRuntime(333):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-14 00:05:39.393: E/AndroidRuntime(333):  at java.lang.reflect.Method.invoke(Method.java:507)
04-14 00:05:39.393: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-14 00:05:39.393: E/AndroidRuntime(333):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-14 00:05:39.393: E/AndroidRuntime(333):  at dalvik.system.NativeStart.main(Native Method) 
04-14 00:05:39.393: E/AndroidRuntime(333): Caused by: java.lang.ClassNotFoundException: com.grex.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.grex-1.apk]
04-14 00:05:39.393: E/AndroidRuntime(333):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-14 00:05:39.393: E/AndroidRuntime(333):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-14 00:05:39.393: E/AndroidRuntime(333):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-14 00:05:39.393: E/AndroidRuntime(333):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

任何人都可以通过vch来解决这个问题

主要活动:

package com.grex;

//import com.grex.R; import com.nanocritical.nanogest.Nanogest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.nanocritical.nanogest.Nanogest;
import com.nanocritical.nanogest.Nanogest.Gesture;
import com.nanocritical.nanogest.Nanogest;

public class MainActivity extends Activity implements Nanogest.GestureListener {
    private Nanogest ngest;
    EditText et= (EditText) findViewById(R.id.editText1);
    Button r= (Button) findViewById(R.id.BtnResume);
    Button p= (Button) findViewById(R.id.BtnPause);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try{
        super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            ngest = new Nanogest(this, this, null);
            et.getText().toString();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onResume() {
        try{
            super.onResume();
            ngest.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPause() {
        try{
            super.onPause();
            ngest.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onGesture(Nanogest.Gesture gesture, double timestamp) {
        try{
            switch (gesture) {
            case SWIPE_LEFT:
                onLeft();
                break;
            case SWIPE_RIGHT:
                onRight();
                break;
            case SWIPE_UP:
                onUp();
                break;
            case SWIPE_DOWN:
                onDown();
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void onDown() {
        // TODO Auto-generated method stub
        try{
            et.setText(R.string.down);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void onUp() {
        // TODO Auto-generated method stub
        try{
            et.setText(R.string.up);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void onRight() {
        // TODO Auto-generated method stub
        try{
            et.setText(R.string.right);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void onLeft() {
        // TODO Auto-generated method stub
        try{
            et.setText(R.string.left);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

清单文件:

  

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:debuggable="true">
    <activity
        android:name="com.grex.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
     

1 个答案:

答案 0 :(得分:0)

行:

EditText et= (EditText) findViewById(R.id.editText1);
Button r= (Button) findViewById(R.id.BtnResume);
Button p= (Button) findViewById(R.id.BtnPause);

应该分为两个阶段:

  1. 宣言 - 与现在相同:

    EditText et = null;
    Button   r  = null;
    Button   p  = null;
    
  2. 即时消息 - onCreate()之后setContentView

    et = (EditText) findViewById(R.id.editText1);
    r  = (Button) findViewById(R.id.BtnResume);
    p  = (Button) findViewById(R.id.BtnPause);