2016-04-28 2 views
0

Nun, die Sache ist, wenn ich diese setSupportActionBar (Symbolleiste) von der Aktivität add_event löschen, funktioniert es, die Aktivität add_event öffnet und alle Schaltflächen und TextEdits auf zeigen der Bildschirm, aber zeigen Sie keine Schaltfläche auf der Symbolleiste, nur die Symbolleiste, sauber, und wenn ich diese setSupportActionBar -Methode setzen, stürzt es ab, wenn ich die Aktivität aufrufen (add_event).Ich bekomme meine App abgestürzt, wenn ich die Methode implementieren setSupportActionBar

Kann jemand erklären, was passiert? Vielen Dank im Voraus :)

Ich habe einige Codes hier setzen, aber ihr Jungs können das gesamte Projekt in meinem GitHub herunterladen

https://github.com/dennysfarias/RemindIt

public class MainActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    //setting toolbar 
    Toolbar toolbar = (Toolbar)findViewById(R.id.my_toolbar); 
    setSupportActionBar(toolbar); 
} 


public void callactAddEvt(){ 
    Intent callAddEvt = new Intent(MainActivity.this, add_event.class); 
    MainActivity.this.startActivity(callAddEvt); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu){ 
    getMenuInflater().inflate(R.menu.menu, menu); 
    return true; 
} 


//put the options inside the 3dot menu 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.action_settings: 
      // User chose the "Settings" item, show the app settings UI... 
      Toast.makeText(getApplicationContext(), "Settings Option Pressed", Toast.LENGTH_SHORT).show(); 
      return true; 

     case R.id.action_addevent: 
      //User chose the AddEvent action, whom calls the com.ddtec.remindit.add_event activity 
      callactAddEvt(); 
      Toast.makeText(getApplicationContext(), "Add Event Option Pressed", Toast.LENGTH_SHORT).show(); 

      return true; 
     default: 
      // If we got here, the user's action was not recognized. 
      // Invoke the superclass to handle it. 
      Toast.makeText(getApplicationContext(), "No Option Pressed", Toast.LENGTH_SHORT).show(); 

      return super.onOptionsItemSelected(item); 

    } 
} 
} 

Das ist mein MainActivity es funktioniert gut, ich versuche, das auf meinem Handy und es sieht gut aus.

Jetzt bin zeige ich werde meine zweite Tätigkeit

public class add_event extends AppCompatActivity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.add_event); 

    Toolbar toolbar = (Toolbar)findViewById(R.id.my_toolbar2); 
    setSupportActionBar(toolbar); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu){ 
    getMenuInflater().inflate(R.menu.menu_add_event, menu); 
    return true; 
} 




@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.action_addfinish: 
      // User chose the Done action, saving the event... 
      Toast.makeText(getApplicationContext(), "Finish/Save Option Pressed", Toast.LENGTH_SHORT).show(); 

      return true; 

     case R.id.action_cancel: 
      // User chose the Cancel action, leaving without saving the current event... 
      Toast.makeText(getApplicationContext(), "Cancel Option Pressed", Toast.LENGTH_SHORT).show(); 

      return true; 

     case R.id.action_settings: 
      Toast.makeText(getApplicationContext(), "Settings Option Pressed", Toast.LENGTH_SHORT).show(); 

      return true; 


     default: 
      // If we got here, the user's action was not recognized. 
      // Invoke the superclass to handle it. 
      Toast.makeText(getApplicationContext(), "No Option Pressed", Toast.LENGTH_SHORT).show(); 

      return super.onOptionsItemSelected(item); 

    } 
} 
} 

Meine add_event Aktivität Layout-Datei

<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    tools:context=".add_event"> 
 

 
    <android.support.v7.widget.Toolbar 
 
     android:id="@+id/my_toolbar2" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="?attr/actionBarSize" 
 
     android:background="?attr/colorPrimary" 
 
     android:elevation="4dp"/> 
 

 

 

 
    <RelativeLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_centerHorizontal="true" 
 
     android:layout_below="@+id/my_toolbar2"> 
 

 
     <EditText 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:id="@+id/editText" 
 
      android:hint="Event Name" 
 
      android:layout_alignParentTop="true" 
 
      android:layout_alignParentStart="true" 
 
      android:layout_marginTop="37dp" 
 
      android:layout_margin="10dp" /> 
 

 
     <EditText 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:id="@+id/editText2" 
 
      android:hint="Event Location" 
 
      android:layout_below="@+id/editText" 
 
      android:layout_alignParentLeft="true" 
 
      android:layout_margin="10dp" /> 
 

 
     <EditText 
 
      android:layout_width="200dp" 
 
      android:layout_height="wrap_content" 
 
      android:inputType="date" 
 
      android:ems="10" 
 
      android:id="@+id/editText3" 
 
      android:layout_alignParentStart="true" 
 
      android:hint="Event Date" 
 
      android:layout_below="@+id/editText2" 
 
      android:layout_alignParentLeft="true" 
 
      android:layout_margin="10dp" /> 
 

 
     <EditText 
 
      android:layout_width="120dp" 
 
      android:layout_height="wrap_content" 
 
      android:inputType="time" 
 
      android:ems="10" 
 
      android:id="@+id/editText4" 
 
      android:hint="Event Time" 
 
      android:layout_marginLeft="10dp" 
 
      android:layout_marginRight="10dp" 
 
      android:layout_alignTop="@+id/editText3" 
 
      android:layout_alignEnd="@+id/editText2" /> 
 

 
     <EditText 
 
      android:layout_width="fill_parent" 
 
      android:layout_height="200dp" 
 
      android:inputType="textMultiLine" 
 
      android:ems="10" 
 
      android:id="@+id/editText5" 
 
      android:hint="Event Description" 
 
      android:layout_alignParentStart="true" 
 
      android:layout_below="@+id/editText4" 
 
      android:layout_alignParentLeft="true" 
 
      android:layout_margin="10dp" /> 
 
    </RelativeLayout> 
 

 

 
</RelativeLayout>

Und hier meine Style.xml

<resources> 


<!-- Base application theme. --> 
<style name="AppThemeWithNoAB" parent="Theme.AppCompat.NoActionBar"> 
    <item name="colorPrimary">@color/my_primary</item> 
    <item name="colorPrimaryDark">@color/my_primary_dark</item> 
    <item name="colorAccent">@color/my_accent</item> 
    <item name="android:textColorPrimary">@color/my_primary_text</item> 
    <item name="android:textColorSecondary">@color/my_secondary_text</item> 
    <item name="android:windowBackground">@color/window_background</item> 

    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 


</style> 

Die Logcat

04-27 14:13:30.197 241-519/? D/RouteManager: doReconsiderRouting: DONE 
 
04-27 14:13:30.197 241-519/? D/EVENT_THREAD: void CEventThread::run() Do poll with timeout: -1 
 
04-27 14:13:30.197 241-520/? E/TinyAlsaStream: getFramesAvailable: Unable to get available frames 
 
04-27 14:13:30.197 241-520/? E/TinyAlsaStream: getFramesAvailable: Unable to get available frames 
 
04-27 14:13:30.197 241-520/? E/TinyAlsaStream: getFramesAvailable: Unable to get available frames 
 
04-27 14:13:30.197 241-520/? E/TinyAlsaStream: getFramesAvailable: Unable to get available frames 
 
04-27 14:13:30.207 525-1054/system_process V/WindowManager: Adding window Window{30cae9cd u0 com.ddtec.remindit/com.ddtec.remindit.add_event} at 8 of 27 (after Window{368d2628 u0 com.ddtec.remindit/com.ddtec.remindit.MainActivity}) 
 
04-27 14:13:30.327 11735-11735/com.ddtec.remindit D/AndroidRuntime: Shutting down VM 
 
04-27 14:13:30.327 11735-11735/com.ddtec.remindit E/AndroidRuntime: FATAL EXCEPTION: main 
 
                    Process: com.ddtec.remindit, PID: 11735 
 
                    android.view.InflateException: Couldn't resolve menu item onClick handler ClearAll in class com.ddtec.remindit.add_event 
 
                     at android.support.v7.view.SupportMenuInflater$InflatedOnMenuItemClickListener.<init>(SupportMenuInflater.java:242) 
 
                     at android.support.v7.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:443) 
 
                     at android.support.v7.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:479) 
 
                     at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:196) 
 
                     at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118) 
 
                     at com.ddtec.remindit.add_event.onCreateOptionsMenu(add_event.java:25) 
 
                     at android.app.Activity.onCreatePanelMenu(Activity.java:3632) 
 
                     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:341) 
 
                     at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:85) 
 
                     at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:258) 
 
                     at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:85) 
 
                     at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:454) 
 
                     at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61) 
 
                     at android.os.Handler.handleCallback(Handler.java:739) 
 
                     at android.os.Handler.dispatchMessage(Handler.java:95) 
 
                     at android.os.Looper.loop(Looper.java:135) 
 
                     at android.app.ActivityThread.main(ActivityThread.java:5310) 
 
                     at java.lang.reflect.Method.invoke(Native Method) 
 
                     at java.lang.reflect.Method.invoke(Method.java:372) 
 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
 
                     at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114) 
 
                    Caused by: java.lang.NoSuchMethodException: ClearAll [interface android.view.MenuItem] 
 
                     at java.lang.Class.getMethod(Class.java:664) 
 
                     at java.lang.Class.getMethod(Class.java:643) 
 
                     at android.support.v7.view.SupportMenuInflater$InflatedOnMenuItemClickListener.<init>(SupportMenuInflater.java:240) 
 
                     at android.support.v7.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:443)  
 
                     at android.support.v7.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:479)  
 
                     at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:196)  
 
                     at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)  
 
                     at com.ddtec.remindit.add_event.onCreateOptionsMenu(add_event.java:25)  
 
                     at android.app.Activity.onCreatePanelMenu(Activity.java:3632)  
 
                     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:341)  
 
                     at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:85)  
 
                     at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:258)  
 
                     at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:85)  
 
                     at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:454)  
 
                     at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)  
 
                     at android.os.Handler.handleCallback(Handler.java:739)  
 
                     at android.os.Handler.dispatchMessage(Handler.java:95)  
 
                     at android.os.Looper.loop(Looper.java:135)  
 
                     at android.app.ActivityThread.main(ActivityThread.java:5310)  
 
                     at java.lang.reflect.Method.invoke(Native Method)  
 
                     at java.lang.reflect.Method.invoke(Method.java:372)  
 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)  
 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)  
 
                     at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114)  
 
04-27 14:13:30.327 525-1034/system_process W/ActivityManager: Force finishing activity 1 com.ddtec.remindit/.add_event 
 
04-27 14:13:30.337 525-1034/system_process W/ActivityManager: Force finishing activity 2 com.ddtec.remindit/.MainActivity 
 
04-27 14:13:30.357 186-186/? I/upi_ug31xx: [get_daemon_uevent_request]: uevent_request = 0 (0000)

+0

Haben Sie etwas getan, bevor Sie eine Frage stellen? – duggu

Antwort

1

In Ihrem menu_add_event.xml auf Linie No: 13 Sie hinzugefügt haben 'android: onClick = "ClearAll"'. Dies verursacht das Problem. Entfernen Sie diese Zeile oder fügen Sie in Ihrer Aktivität die folgende Funktion hinzu.

public boolean ClearAll(MenuItem item) { 
// actions 
} 
+0

Mann, ich kann nicht glauben, hahah Nur das ... das war von einer Methode, die ich verwendet, um meine ListView zu löschen, wenn Sie andere Dinge testen ... Ich weiß nicht, warum die IDE nicht als ein Fehler angezeigt. Aber danke, es funktioniert jetzt gut :) –

+0

IDE wird nicht darauf hinweisen, die Stack-Trace tut. – cyroxis

Verwandte Themen