无法在wikitude中加载AR体验

时间:2015-01-27 23:59:22

标签: augmented-reality wikitude

我需要在此链接中创建AR应用: 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 studio 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

非常感谢

1 个答案:

答案 0 :(得分:1)

请查看提供的示例应用程序,该应用程序还使用assets文件夹中的相对路径。 调用 architectView.load(&#34; index.html&#34;)将从应用程序的资源文件夹和 architectView.load(&#34; yourpath / index)加载文件。 html&#34;)你路径中的索引html文件,相对于资产根目录,不需要使用绝对资产目录。

您的JS代码中甚至可能存在错误。您是否尝试从assets根文件夹加载它? 请先尝试加载valid sample application,然后将其替换为您自己的源代码。

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

亲切的问候, 安德烈亚斯

PS。:请避免在不同的论坛上发布相同的问题,您已经在Wikitude Forum中提出了这个问题。