Reputation: 17
I'm very new to Android programming and am trying to create a helloWorld application for Google Glasses. I'm having a little problem though:
Here's the stack Trace:
04-06 02:10:49.300: E/AndroidRuntime(724): FATAL EXCEPTION: main
04-06 02:10:49.300: E/AndroidRuntime(724): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld/com.example.helloworld.MainActivity}: java.lang.RuntimeException: Stub!
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.os.Handler.dispatchMessage(Handler.java:99)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.os.Looper.loop(Looper.java:137)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-06 02:10:49.300: E/AndroidRuntime(724): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 02:10:49.300: E/AndroidRuntime(724): at java.lang.reflect.Method.invoke(Method.java:511)
04-06 02:10:49.300: E/AndroidRuntime(724): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-06 02:10:49.300: E/AndroidRuntime(724): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-06 02:10:49.300: E/AndroidRuntime(724): at dalvik.system.NativeStart.main(Native Method)
04-06 02:10:49.300: E/AndroidRuntime(724): Caused by: java.lang.RuntimeException: Stub!
04-06 02:10:49.300: E/AndroidRuntime(724): at com.google.android.glass.app.Card.<init>(Card.java:10)
04-06 02:10:49.300: E/AndroidRuntime(724): at com.example.helloworld.MainActivity.onCreate(MainActivity.java:23)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.Activity.performCreate(Activity.java:4465)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-06 02:10:49.300: E/AndroidRuntime(724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-06 02:10:49.300: E/AndroidRuntime(724): ... 11 more
04-06 02:10:49.520: I/dalvikvm(724): threadid=3: reacting to signal 3
04-06 02:10:49.540: I/dalvikvm(724): Wrote stack traces to '/data/anr/traces.txt'
04-06 02:10:49.840: I/dalvikvm(724): threadid=3: reacting to signal 3
04-06 02:10:49.850: I/dalvikvm(724): Wrote stack traces to '/data/anr/traces.txt'
the .xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloworld.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data android:name="com.google.android.glass.VoiceTrigger" android:resource="@xml/voice_trigger" />
</activity>
</application>
</manifest>
and the main activity:
package com.example.helloworld;
import com.google.android.glass.app.Card;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
Card card = new Card(this);
card.setText("Hello world!");
card.setFootnote("androidzeitgeist.com");
setContentView(card.toView());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello_world, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_hello_world,
container, false);
return rootView;
}
}
}
I've tried running it on an android device, on an emulator, everything, and nothing had worked for me. I'd be really glad if someone could help me. Many thanks in advance!
Upvotes: 1
Views: 3451
Reputation: 2963
I modified your code slightly and it works now. You didn't provide your layout file so I made one, make sure to use it. Note you have some parts of using fragments in your activity, I just removed them since they weren't being used fully. I also commented out your menu code.
Main Activity
package com.example.helloworld;
import com.google.android.glass.app.Card;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
Card card = new Card(this);
card.setText("Hello world!");
card.setFootnote("androidzeitgeist.com");
setContentView(card.toView());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.hello_world, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Layout XML (res/layout/activity_hello_world.xml)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.com.glass.cardscrollview.MainActivity"
tools:ignore="MergeRootFrame" />
The result is:
Upvotes: 0
Reputation: 66886
Normally, this shows up when you try to run Android code in your IDE. The copies of the API that you download to compile against are not actually functional. If you try to access any of the methods in that library, it throws an exception like:
Caused by: java.lang.RuntimeException: Stub!
I see you appear to be running on the device. By any chance have you accidentally packaged the stub Android API code with your app? (For example, in Maven, did you not set the dependency to provided
?) It may be that your app is accessing the fake version of Android APIs and not the device.
Upvotes: 1
Reputation:
You need to put all your code in the onCreateView
of the PlaceholderFragment
class, before: return rootView;
This the new way to code in android.
Upvotes: 1