Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
cleopatra douglas
Courses Plus Student 45 Pointserror in super.oncreate
i am working on the ribbit app, the EditFriendsActivity, but when i run the app and click on it i the action bar, i get error from the log pointing to my theme and the super.oncreate line, how do i resolve this.
3 Answers
Alice Spencer
12,273 PointsCan you post your code? That will help discover the actual problem. If you need help posting code use the Markdown Cheatsheet
cleopatra douglas
Courses Plus Student 45 PointsThis is my MainActivity
\\package com.amebo.inhit;
import android.annotation.TargetApi; import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.Window;
import com.parse.ParseAnalytics; import com.parse.ParseObject; import com.parse.ParseQuery; import com.parse.ParseUser;
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
public static final String TAG = MainActivity.class.getSimpleName();
/** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which * will keep every loaded fragment in memory. If this becomes too memory * intensiveo, it may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */ SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpened(getIntent());
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null) {
navigateToLogin();
}
else {
Log.i(TAG, currentUser.getUsername());
}
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(this,
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
@Override
protected void onResume() {
super.onResume();
ParseQuery<ParseObject> query = new ParseQuery(ParseConstants.CLASS_MUSIC);
query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
}
private void navigateToLogin() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch(itemId) {
case R.id.action_logout:
ParseUser.logOut();
navigateToLogin();
break;
case R.id.action_edit_profile:
Intent intent = new Intent(this, EditProfileActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
}
\\
This is my EditProfileActivity with nothing in it yet....and it still crashes
\\package com.amebo.inhit;
import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;
public class EditProfileActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.edit_profile, 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);
}
} \\
and this is the log
\\12-20 22:05:21.373: D/dalvikvm(1283): GC_FOR_ALLOC freed 320K, 11% free 3192K/3564K, paused 19ms, total 29ms 12-20 22:05:21.545: D/dalvikvm(1283): GC_FOR_ALLOC freed 22K, 9% free 3377K/3708K, paused 5ms, total 23ms 12-20 22:05:21.561: D/dalvikvm(1283): GC_FOR_ALLOC freed 3K, 9% free 3472K/3808K, paused 13ms, total 13ms 12-20 22:05:21.609: I/dalvikvm-heap(1283): Grow heap (frag case) to 4.510MB for 1127532-byte allocation 12-20 22:05:21.637: D/dalvikvm(1283): GC_FOR_ALLOC freed <1K, 7% free 4573K/4912K, paused 27ms, total 27ms 12-20 22:05:21.701: I/MainActivity(1283): cleopatra 12-20 22:05:22.045: D/libEGL(1283): loaded /system/lib/egl/libEGL_genymotion.so 12-20 22:05:22.077: D/(1283): HostConnection::get() New Host Connection established 0xb876c108, tid 1283 12-20 22:05:22.089: D/libEGL(1283): loaded /system/lib/egl/libGLESv1_CM_genymotion.so 12-20 22:05:22.093: D/libEGL(1283): loaded /system/lib/egl/libGLESv2_genymotion.so 12-20 22:05:22.145: W/EGL_genymotion(1283): eglSurfaceAttrib not implemented 12-20 22:05:22.149: E/OpenGLRenderer(1283): Getting MAX_TEXTURE_SIZE from GradienCache 12-20 22:05:22.153: E/OpenGLRenderer(1283): MAX_TEXTURE_SIZE: 8192 12-20 22:05:22.213: E/OpenGLRenderer(1283): Getting MAX_TEXTURE_SIZE from Caches::initConstraints() 12-20 22:05:22.217: E/OpenGLRenderer(1283): MAX_TEXTURE_SIZE: 8192 12-20 22:05:22.229: D/OpenGLRenderer(1283): Enabling debug mode 0 12-20 22:05:22.805: I/Choreographer(1283): Skipped 31 frames! The application may be doing too much work on its main thread. 12-20 22:05:25.929: W/EGL_genymotion(1283): eglSurfaceAttrib not implemented 12-20 22:05:27.353: D/AndroidRuntime(1283): Shutting down VM 12-20 22:05:27.353: W/dalvikvm(1283): threadid=1: thread exiting with uncaught exception (group=0xa4cf6b20) 12-20 22:05:27.393: E/AndroidRuntime(1283): FATAL EXCEPTION: main 12-20 22:05:27.393: E/AndroidRuntime(1283): Process: com.amebo.inhit, PID: 1283 12-20 22:05:27.393: E/AndroidRuntime(1283): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amebo.inhit/com.amebo.inhit.EditProfileActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.ActivityThread.access$800(ActivityThread.java:135) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.os.Handler.dispatchMessage(Handler.java:102) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.os.Looper.loop(Looper.java:136) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.ActivityThread.main(ActivityThread.java:5001) 12-20 22:05:27.393: E/AndroidRuntime(1283): at java.lang.reflect.Method.invokeNative(Native Method) 12-20 22:05:27.393: E/AndroidRuntime(1283): at java.lang.reflect.Method.invoke(Method.java:515) 12-20 22:05:27.393: E/AndroidRuntime(1283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 12-20 22:05:27.393: E/AndroidRuntime(1283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 12-20 22:05:27.393: E/AndroidRuntime(1283): at dalvik.system.NativeStart.main(Native Method) 12-20 22:05:27.393: E/AndroidRuntime(1283): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:147) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:139) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123) 12-20 22:05:27.393: E/AndroidRuntime(1283): at com.amebo.inhit.EditProfileActivity.onCreate(EditProfileActivity.java:12) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.Activity.performCreate(Activity.java:5231) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 12-20 22:05:27.393: E/AndroidRuntime(1283): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 12-20 22:05:27.393: E/AndroidRuntime(1283): ... 11 more 12-20 22:05:30.313: I/Process(1283): Sending signal. PID: 1283 SIG: 9 \\
Stephen Goodwin
5,479 PointsDid you forget to include this in you manifest?