2013-11-03 34 views
2

我已經創建了一個活動,現在我想的eventListener添加到按鈕:的Android :: getViewById在另一活動(不super.onCreate())

但是當我切換到AddEntryActivity我得到一個SuperNotCalledException()。 任何幫助真的很感激!

public class AddEntryActivity extends ActionBarActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_add_entry); 
    ImageButton test = (ImageButton) findViewById(R.id.mg_add_entry_button_save); 
    ... 

這裏是我的activity_add_entry.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity$PlaceholderFragment" 
    android:background="@drawable/radialback"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:id="@+id/mg_overview" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_above="@+id/mg_menu_bar"> 

     <EditText 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:inputType="numberDecimal"> 
     </EditText> 

     <EditText 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:inputType="date"/> 

     <Spinner 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:id="@+id/mg_add_entry_spinner_categories" 
      android:entries="@array/basic_categories_array" 
      android:prompt="@string/abc_activity_chooser_view_see_all"></Spinner> 

     <Button 
      android:id="@+id/mg_add_entry_button_save" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:text="@string/mg_save"/> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/mg_menu_bar" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true"> 
     <ImageButton 
      android:id="@+id/mg_menu_button_add_entry" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:src="@drawable/abc_ic_go"/> 
    </LinearLayout> 

</RelativeLayout> 
+1

你可以發佈logcat輸出。 – Devrim

回答

0

硬盤,沒有看到你的logcat說,但有機會,你要覆蓋在之前的活動類的一些方法(如或onStop) ,並且你錯過了超級電話.-

@Override 
public void onPause() { 
    super.onPause(); 
    // Your stuff 
} 
相關問題