0

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

** *代码摘要:

通过代码,我们试图通过手动滑动来更改文本字段中的文本。当用户从右向左滑动手时,文本应变为 Left ....等等。当我们运行应用程序时出现以下错误,请帮助我们解决它。*

**

我已经阅读了许多与我的错误相关的类似错误,但没有一个可以解决我的错误。

请帮忙

我们收到以下错误:

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>

4

1 回答 1

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. 实例化 - in onCreate(), aftersetContentView

    et = (EditText) findViewById(R.id.editText1);
    r  = (Button) findViewById(R.id.BtnResume);
    p  = (Button) findViewById(R.id.BtnPause);
    
于 2013-04-13T20:08:39.413 回答