错误:找不到符号类Builder

时间:2016-06-08 18:18:50

标签: java android face-detection

我一步一步地遵循本教程https://www.sitepoint.com/face-detection-in-android-with-google-play-services/

尽管如此,我还是面临一些我无法通过stackoverflow解决的错误。

带有麻烦的代码如下:

super.onCreate(savedInstanceState);     的setContentView(R.layout.activity_main);

InputStream stream = getResources().openRawResource(R.raw.image01);
Bitmap bitmap = BitmapFactory.decodeStream(stream);
FaceDetector detector = new FaceDetector.Builder(getApplicationContext())
        .setTrackingEnabled(false)
        .build();


Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


//create a frame from the bitmap and run face detection on the frame
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<Face> faces = detector.detect(frame);

TextView faceCountView = (TextView) findViewById(R.id.face_count);
faceCountView.setText(faces.size() + "faces detected");

detector.release();

我得到了这些错误:

  

C:\用户\ XXX \ FaceDetectionDemo \应用\ SRC \主\的java \ COM \示例\ XXX \ facedetectiondemo \ MainActivity.java   错误:(40,49)错误:找不到符号类构建器错误:(51,21)   错误:找不到符号类Face Error:(51,43)错误:找不到   符号方法检测(帧)错误:(56,17)错误:找不到符号   方法release()错误:任务执行失败   &#39;:应用程序:compileDebugJavaWithJavac&#39;

build.gradle具有正确的依赖关系

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.android.gms:play-services:8.1.0'
}

我尝试使用此条目cannot find symbol class "Builder" enter image description here uilder?rq = 1但它不起作用

[已安装的SDK工具]

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。然后我找到了这个解决方案它对我有用:你必须删除库。

改变这个:

import android.media.FaceDetector;

为:

import com.google.android.gms.vision.face.FaceDetector;