augmented-realitywikitude

Can't load AR experience in wikitude


I need to create AR app to do as in this link: http://www.wikitude.com/external/doc/documentation/latest/android/imagerecognition.html#multipletarget

I wrote a code and tried it, it open a camera, but I think it can't load to use AR experience (index.html)

This is a MainActivity.java code:

NOTE: the path of index.html in th project is: 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();
    }
}

}

This is a 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>

I get this warning in android studio xml preview:

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

Thank you very much


Solution

  • Please have a look at the provided Sample application, which also uses relative paths within the assets folder. Calling architectView.load("index.html") will load file from application's assets folder and architectView.load("yourpath/index.html") the index html-file in yourpath, relative to the assets root directory, no need to use absolute assets-directory.

    There may even be an error in your JS code. Have you tried loading it from assets root folder? Please first try loading a valid sample application and then replace it with your own source code.

    Also have a look at Android remote dubugging to find potential JS errors.

    Kind regards, Andreas

    PS.: Please avoid posting same question to different forums, you already asked this question it in Wikitude Forum.