2013-04-13 2 views
0

Мы создаем приложение для Android при распознавании жестов без касания.Приложение для распознавания жестов Android без знака Ошибка

** * Резюме КОД:

By the code we are trying to change the text in the textfield via hand Swipes. When the user swipes his hand from right to left , the text should change to Left ....and So on. When we run the app we get below error, please help us resolve it.*

**

Я прочитал 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) 

Может кто-нибудь sugesst пути от 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(); 
     } 
    } 
} 

Manifest файл:

<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

Это поможет, если вы вывесили ключевые биты кода (например, класс верхней и OnCreate для деятельности) и манифест. –

+0

Отправьте свой файл манифеста и MainActivity onCreate. –

+1

Я отредактировал и упомянул в нем manifest.xml и основное действие – user2278134

ответ

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. Instantation - в onCreate(), после того, как setContentView

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

ps. Это ускорит получение ответов, если вы отформатируете код, чтобы его было легко читать перед отправкой - я потратил около 10 минут на повторное форматирование кода, прежде чем я смог бы разобраться, что происходит! –

+0

srry neil для проблемы с редактированием ... Я сделал изменения, которые вы сказали, но теперь код дает ошибку - он не может найти и переменную et в onDown(), onUp(), onLeft() и onRight() , Ошибка говорит: et не может быть разрешена. – user2278134

+0

Извините, мои ответы были не совсем ясными, я обновил его. –

Смежные вопросы