无法在 wikitude 加载 AR 体验

Can't load AR experience in wikitude

我需要创建 AR 应用程序来执行此操作 link: http://www.wikitude.com/external/doc/documentation/latest/android/imagerecognition.html#multipletarget

我写了一个代码试了一下,它打开了一个摄像头,但我认为它无法加载使用AR体验(index.html)

这是一个MainActivity.java代码:

注意:index.html在项目中的路径是:assets/miarec/index.hmtl

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.wikitude.architect.ArchitectView;
import java.io.IOException;

 public class MainActivity extends ActionBarActivity {

 ArchitectView architectView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.architectView = (ArchitectView)this.findViewById( R.id.architectView );
    final ArchitectView.ArchitectConfig config = new ArchitectView.ArchitectConfig( "3Axht4JgkVsnCHOuwl76PM0NDRnpRNL5PwwrPd1kgIN7aAP5sGJxBp3hvA3SIE+zrzwaqvulTUb7hhYz1/iQJiY9M3K8825GHJkssi5nHP8ZhtdoIo0z2fV2PkGUY9DzmVG/z2f3Uu8FKyulXFFegYEQZcvSCVIYvBmI6y0MIAFTYWx0ZWRfX6IIZxx4haqZxXDO5sj4bWkWKn2INx38uRuDKzaF6TVj7NV2MpeQeOvWWWGx7TKLL8DfOO8W4ARCSicBw6Vmejq7WMFQuMvte1y+r6rxZ2irjTBd8IpiAezUX8cxpy26SNbd1Gm+PWdjizE3Yqqr3/mi5NcDWlGm3GICiCeFvDNFgwryW7kPG6JTjhWA3GiUTfUE7AAJI349ZbtisyhP8YLzRvPUIc8t9nKs0aEMCme3e3CNiacl7rAuUWI7YNYD28GQ9EpTwAL8F29tV1n3dcXhxyuKfyptft71DI1SVVQ67/3UNml6bA06R3ZZiwyYD1f9l/Kfz5Q6RaFGXBL6vKHKwSt0vfeul2lmB4N1FJ+6GCSsB8cvIyhq3QtMQhbG9CiihTlsF9WVQdIVtbXFuGo=" /* license key */ );
    this.architectView.onCreate( config );

}

@Override
protected void onPostCreate( final Bundle savedInstanceState ) {
    super.onPostCreate( savedInstanceState );

    if ( this.architectView != null ) {

        // call mandatory live-cycle method of architectView
        this.architectView.onPostCreate();

        try {
            // load content via url in architectView, ensure '<script src="architect://architect.js"></script>' is part of this HTML file, have a look at wikitude.com's developer section for API references

            String s= getAssets().open("miarec/index.html").toString();
            this.architectView.load(getAssets().open("miarec/index.html").toString());



        } catch (IOException e1) {
            e1.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.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onResume() {
    super.onResume();

    this.architectView.onResume();
}

@Override
protected void onPause() {
    super.onPause();

    // call mandatory live-cycle method of architectView
    if ( this.architectView != null ) {
        this.architectView.onPause();


    }


}

@Override
protected void onStop() {
    super.onStop();
}

@Override
protected void onDestroy() {
    super.onDestroy();

    // call mandatory live-cycle method of architectView
    if ( this.architectView != null ) {
        this.architectView.onDestroy();
    }
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    if ( this.architectView != null ) {
        this.architectView.onLowMemory();
    }
}

}

这是一个 activity_main.xml:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"   
 android:layout_width="match_parent"
android:layout_height="match_parent"  
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"   
tools:context=".MainActivity">

    <com.wikitude.architect.ArchitectView android:id="@+id/architectView"
        android:layout_width="fill_parent" android:layout_height="fill_parent"/>

</RelativeLayout>

我在 android 工作室 xml 预览中收到此警告:

Rendering Problems The following classes could not be instantiated:
- com.wikitude.architect.ArchitectView (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show        
sample data when shown in the IDE  Exception Details   
java.lang.NullPointerException   at   
com.wikitude.architect.ArchitectView.e  at   
com.wikitude.architect.ArchitectView.a  at 
com.wikitude.architect.ArchitectView.<init>  at   
com.wikitude.architect.ArchitectView.<init>  at

非常感谢

请查看提供的示例应用程序,它也在资产文件夹中使用相对路径。 调用 architectView.load("index.html") 将从应用程序的资产文件夹和 architectView.load("yourpath/index.html") index html-yourpath中的文件,相对于assets根目录,无需使用绝对assets-directory.

你的JS代码甚至可能有错误。您是否尝试过从 assets 根文件夹加载它? 请先尝试加载一个valid sample application,然后用您自己的源代码替换它。

另请查看 Android remote dubugging 以查找潜在的 JS 错误。

亲切的问候, 安德烈亚斯

PS.: 请避免将相同的问题发布到不同的论坛,您已经在 Wikitude Forum.

中提出过这个问题