나는 휴대 전화 카메라로 촬영 한 사진의 OCR을 수행하기 위해 Microsoft Hawaii SDK를 사용하는 Android 앱을 만들고 있습니다. 내 Android 앱을 실행하는 중에 오류가 발생했습니다.NoClassDefFoundError. 그것을 고치는 방법?
package com.example.mobile;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import microsoft.hawaii.sampleappbase.HawaiiBaseAuthActivity;
public class RecognitionActivity extends HawaiiBaseAuthActivity {
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recognition);
tv.setText("Prova");
tv.setVisibility(View.VISIBLE);
}
@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_recognition, menu);
return true;
}
}
나는 것으로 나타났습니다 : RecognitionActivity.Java의 코드가이 있지만
package com.example.mobile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.location.GpsStatus;
import android.location.GpsStatus.Listener;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
public class FotocameraActivity extends Activity {
// dati che servono per la fotocamera
private static final int CAMERA_REQUEST = 100; // un numero a nostro
// piacimento
File tmpFotoFile = null;
byte[] bitmapdata;
ImageView preview;
LocationManager locationManager;
String gps;
final static String ARRAY_BYTE = "ARRAY_BYTE";
final static String GPS = "GPS";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
startGpsTracking();
}
try {
launchCamera();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void startGpsTracking() {
// TODO Auto-generated method stub
locationManager.addGpsStatusListener(gpsListener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 3, myLocationListener);
}
private Listener gpsListener = new Listener(){
public void onGpsStatusChanged(int status){
switch(status){
case GpsStatus.GPS_EVENT_FIRST_FIX:
Log.d(LOCATION_SERVICE,"onGpsStatusChanged First Fix");
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
Log.d(LOCATION_SERVICE, "onGpsStatusChanged Satellite");
break;
case GpsStatus.GPS_EVENT_STARTED:
Log.d(LOCATION_SERVICE, "onGpsStatusChanged Started");
break;
case GpsStatus.GPS_EVENT_STOPPED:
Log.d(LOCATION_SERVICE, "onGpsStatusChanged Stopped");
break;
}
}
};
private LocationListener myLocationListener = new LocationListener(){
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double lng = location.getLongitude(), lat = location.getLatitude();
gps += String.format("%6f", lng) + "#" + String.format("%6f", lat);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
};
private void launchCamera() throws IOException {
// Fase 1
tmpFotoFile = File.createTempFile("OCRPic", null);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); //Uri.fromFile(tmpFotoFile));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap datifoto = null;
Uri picUri = data.getData();
if(picUri != null){
try {
datifoto = android.provider.MediaStore.Images.Media.getBitmap(this.getContentResolver(), picUri);
//datifoto = android.provider.MediaStore.Images.Media.getBitmap(this.getContentResolver(), android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);//Uri.fromFile(tmpFotoFile));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
datifoto.compress(Bitmap.CompressFormat.JPEG, 70, bos);
bitmapdata = bos.toByteArray();
//tmpFotoFile.delete();
SimpleView view = new SimpleView(this, datifoto); // creo l'istanza
// // della // view...
setContentView(view); // e la setto
Intent intentRecognize = new Intent(this, RecognitionActivity.class); **<-Here refers the logcat for the error**
intentRecognize.putExtra(ARRAY_BYTE, bitmapdata);
intentRecognize.putExtra(GPS, gps);
startActivity(intentRecognize);
}
}
}
class SimpleView extends View{
private Bitmap bitmap;
private Paint tmpPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public SimpleView(Context context, Bitmap bitmap) {
super(context);
this.bitmap = Bitmap.createScaledBitmap(bitmap,480,320,false);//ridimensiono l'immagine
}
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawBitmap(bitmap, null , new Rect(0,0,getWidth(),getHeight()),tmpPaint);
}
}
:
이02-07 14:48:59.617: E/AndroidRuntime(24660): FATAL EXCEPTION: main
02-07 14:48:59.617: E/AndroidRuntime(24660): java.lang.NoClassDefFoundError: com.example.mobile.RecognitionActivity
02-07 14:48:59.617: E/AndroidRuntime(24660): at com.example.mobile.FotocameraActivity.onActivityResult(FotocameraActivity.java:143)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.Activity.dispatchActivityResult(Activity.java:4820)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2435)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2476)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1990)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3355)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.access$700(ActivityThread.java:127)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1155)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.os.Looper.loop(Looper.java:137)
02-07 14:48:59.617: E/AndroidRuntime(24660): at android.app.ActivityThread.main(ActivityThread.java:4476)
02-07 14:48:59.617: E/AndroidRuntime(24660): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 14:48:59.617: E/AndroidRuntime(24660): at java.lang.reflect.Method.invoke(Method.java:511)
02-07 14:48:59.617: E/AndroidRuntime(24660): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
02-07 14:48:59.617: E/AndroidRuntime(24660): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
02-07 14:48:59.617: E/AndroidRuntime(24660): at dalvik.system.NativeStart.main(Native Method)
FotocameraActivity.Java의 코드는 이것이다 : 로그 고양이는 이것이다 RecognitionActivity에서 Activity에서 해당 활동을 확장하면 작동하지만 HawaiiBaseAuthActivity를 확장하면 충돌이 발생합니다.
나는 앱이 시작되는 바로 그 순간에 나타나는 로그 캣의 또 다른 메시지,주의 :
02-07 14:48:14.717: E/dalvikvm(24660): Could not find class 'com.example.mobile.RecognitionActivity', referenced from method com.example.mobile.FotocameraActivity.onActivityResult
을하지만 그 활동은 내 작업 공간에 정의되어 있습니다!
누군가가 나를 도와 주시면 대단히 감사하겠습니다.
같은 프로젝트의이 2 개입니까? – njzk2