Start a new topic
Solved

Null pointer Exception architectView.onCreate(config )

02-22 13:47:38.167 4174-4174/? E/AndroidRuntime: FATAL EXCEPTION: main

                                                 Process: com.example.root.myglassapplication, PID: 4174

                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.root.myglassapplication/com.example.root.myglassapplication.MainActivity}: java.lang.NullPointerException

                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2224)

                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2273)

                                                     at android.app.ActivityThread.access$800(ActivityThread.java:138)

                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)

                                                     at android.os.Handler.dispatchMessage(Handler.java:102)

                                                     at android.os.Looper.loop(Looper.java:149)

                                                     at android.app.ActivityThread.main(ActivityThread.java:5045)

                                                     at java.lang.reflect.Method.invokeNative(Native Method)

                                                     at java.lang.reflect.Method.invoke(Method.java:515)

                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

                                                     at dalvik.system.NativeStart.main(Native Method)

                                                  Caused by: java.lang.NullPointerException

                                                     at com.example.root.myglassapplication.MainActivity.buildView(MainActivity.java:150)

                                                     at com.example.root.myglassapplication.MainActivity.onCreate(MainActivity.java:71)

                                                     at android.app.Activity.performCreate(Activity.java:5235)

                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1089)

                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2188)

                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2273) 

                                                     at android.app.ActivityThread.access$800(ActivityThread.java:138) 

                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236) 

                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 

                                                     at android.os.Looper.loop(Looper.java:149) 

                                                     at android.app.ActivityThread.main(ActivityThread.java:5045) 

                                                     at java.lang.reflect.Method.invokeNative(Native Method) 

                                                     at java.lang.reflect.Method.invoke(Method.java:515) 

                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 

                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 

                                                     at dalvik.system.NativeStart.main(Native Method) 

02-22 13:47:38.177 530-855/? W/ActivityManager: Force finishing activity com.example.root.myglassapplication/.MainActivity









 * An {@link Activity} showing a tuggable "Hello World!" card.
* <p>
* The main content view is composed of a one-card {@link CardScrollView} that provides tugging
* feedback to the user when swipe gestures are detected.
* If your Glassware intends to intercept swipe gestures, you should set the content view directly
* and use a {@link com.google.android.glass.touchpad.GestureDetector}.
*
* @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
*/
public class MainActivity extends Activity {

/**
* {@link CardScrollView} to use as the main content view.
*/

private static final String wikiKey = "IA7oG3lTkt9vG+m5HXqHX9eGl4GsTON5fTSJufnxAOxv0aFP8lUDChDkb3J5BmGkZiXz6TA0jTf+KW9cdwRxtRbqNk+gpH95V2U7JryNIRjAoCV6V/OD0tJM+LoB3hLBdzh/BRHqrZMpit6DpnboXlcFTrl/dgscfylyBISBBalTYWx0ZWRfX3HaHRhwzW1K+wnYIxsMY7nwmsH/YoaUVW+fKnWpMV1t7A4QUJ/7qQuVf+PAUHdGrD5N0HDOGiV7kPsDC04D58eHCPGaO9oxweIjpJZcfNvaIGucyXt0gFpItJ1kAFPUGcRDn+4I5yQ8I8Fr17bBCl4vjfjeW+OeXL7SKwpoFwqUCi5+sYbD+q6csDtPImOgoPcJ0I8dRkwX6/hFG0b46xJG9og4WE6iPJfC6TqutxE9byQNfrvehNBChxEIqlNUIrpi4cwOnM1vuxHZIzpnN7tp77BSDMbixt4FgrvttkB7DyA/Q+pWaKWgTG6j/eN5lLPuANfhYqkEaXNXxZcLzv3nf0WsCVlerhe4L5n3uBpH42JYypMl92YQzoF2LGuDW6FNOZLKTgLNuI2oM4mD2NSv4af0nH+svKHHuXSaxPEAU0A4PIV+ReX60g1Kd+Zxgmmqa8HWSXk44Exu08/TaZ8zo7ICnno20A==";

private CardScrollView mCardScroller;
private static final int SPEECH_REQUEST = 0;
private PubNubUtil pubNubUtil;
private static final String PUBLISH_SUBSCRIBE_KEY = "demo";
private static final String ANDROID_DEVICE = "Google_Glass";
private static final String CHANNEL_NAME = "awesomeChannel";

private ArchitectView architectView = null;


/**
* "Hello World!" {@link View} generated by {@link #buildView()}.
*/
private View mView;

@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);

mView = buildView();

mCardScroller = new CardScrollView(this);
mCardScroller.setAdapter(new CardScrollAdapter() {
@Override
public int getCount() {
return 1;
}

@Override
public Object getItem(int position) {
return mView;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
return mView;
}

@Override
public int getPosition(Object item) {
if (mView.equals(item)) {
return 0;
}
return AdapterView.INVALID_POSITION;
}
});
// Handle the TAP event.
mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Plays disallowed sound to indicate that TAP actions are not supported.
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.playSoundEffect(Sounds.DISALLOWED);
}
});
//myPubNubInit();
getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
setContentView(mCardScroller);
//displaySpeechRecognizer();
//pubNubInit();
}

@Override
protected void onResume() {
super.onResume();
mCardScroller.activate();
}

@Override
protected void onPause() {
mCardScroller.deactivate();
super.onPause();
}

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

this.architectView.onPostCreate();
try {
this.architectView.load( "index.html" );
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
*/
private View buildView() {
CardBuilder card = new CardBuilder(this, CardBuilder.Layout.EMBED_INSIDE);

//card.setText(R.string.hello_world);
card.setEmbeddedLayout(R.layout.activity_main);

this.architectView = (ArchitectView)this.findViewById( R.id.architectView );
final ArchitectView.ArchitectConfig config = new ArchitectView.ArchitectConfig(wikiKey);
Log.e("Key",config.getKey());
this.architectView.onCreate(config );

return card.getView();
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

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




1 Comment

Good morning,



have you tried running the unaltered sample app that is included in the SDK package? I'd be interested to know whether that works for you or not.


Also, would you mind checking this.architectView for null before calling onCreate on it in buildView? I'd like to know whether that's the problem or not.



- Daniel


Login or Signup to post a comment