我已经缩减了 15-puzzle 的代码,这是由 opencv4android 作为示例提供的。现在缩短的代码在其原始文档位置运行良好,但在我将它们复制到其他地方设置的 helloworld 项目后,程序崩溃,Logcat 设置 MainActivity 的 NoClassFoundDefError。我试图查看 manifest.xml 但仍然无法找出问题的原因。你能帮助我吗?谢谢!
下面是我的代码:
1.puzzle15Activity
package org.opencv.samples.puzzle15;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.text.method.*;
import android.widget.Toast;
import android.view.View;
import android.view.*;
public class puzzle15Activity extends Activity
{
SampleCvViewBase mView=null;
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this)
{
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
mView=new SampleCvViewBase(mAppContext);
setContentView(mView);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2,this,mOpenCVCallBack);
}
}
2.SampleCvViewBase
package org.opencv.samples.puzzle15;
import java.util.List;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.VideoCapture;
import org.opencv.highgui.Highgui;
import org.opencv.core.Scalar;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import org.opencv.core.*;
import org.opencv.calib3d.Calib3d;
class SampleCvViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable {
int t;
Scalar s=new Scalar(100,100,100,100);
Scalar s1=new Scalar(1);
Scalar s2=new Scalar(100);
byte []t1={1,0,0,1};
int []t2={5,4,3,2};
int[] t3;
Mat mrgba;
Mat m1,m2,m3;
public int[] list={1,2,3};
@Override
public SampleCvViewBase(Context context) {
super(context);
mrgba=new Mat(4,4,CvType.CV_16S,s);
mrgba.create(4,4,CvType.CV_8UC(15));
m1=new Mat(2,2,CvType.CV_8U,s1);
m2=new Mat(2,2,CvType.CV_32S,s2);
m3=new Mat(2,2,CvType.CV_32S,s2);
m1.put(0,0,t1);
m2.put(0,0,t2);
t3=new int[4];
m2.get(0,0,t3);
t3[1]=200;
m2.put(0,0,t3);
m2.copyTo(m3);
}
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
}
public void surfaceCreated(SurfaceHolder holder) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
public void run() {}
}