不幸的是,通过单击下一步按钮从Google map activity移到addReminder Activity时,我收到了停止的错误消息。我没有收到任何语法错误。请尽快回复我,我是Android上的新手。

AddReminder.java

public class AddReminder extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_reminder);
    }

    public void AddEventPlace(){
        Intent intent= new Intent(this, AddEventPlace.class);
        startActivity(intent);
    }

    }


AddEventPlace XML:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.champ.remindme2.AddEventPlace" />


AddEventPlace.java

public class AddEventPlace extends FragmentActivity implement OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_event_place);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}}


AddReminder.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.champ.remindme2.AddReminder"
android:background="@drawable/back">
......
<Button
    android:id="@+id/NextButton"
    android:background="@drawable/blue_botton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next"
    style="@style/ButtonText"
    android:onClick="AddEventPlace"
    android:layout_alignTop="@+id/BackButton"
    android:layout_alignRight="@+id/imageView6" />


清单文件

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.champ.remindme2">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Login">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Menu" />
    <activity android:name=".signup" />
    <activity android:name=".AddReminder" />
    <activity android:name=".add_place" />
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />
    <activity
        android:name=".AddEventPlace"
        android:label="@string/title_activity_add_event_place"></activity>
</application>
</manifest>


logcat错误:

java.lang.IllegalStateException: Could not find method AddEventPlace(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'NextButton'
                                                                               at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:321)
                                                                               at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:280)
                                                                               at android.view.View.performClick(View.java:4780)
                                                                               at android.view.View$PerformClick.run(View.java:19866)
                                                                               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:5254)
                                                                               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:903)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

最佳答案

将AddEventPlace方法更改为

public void AddEventPlace(View v){
    Intent intent= new Intent(this, AddEventPlace.class);
    startActivity(intent);
}

09-18 23:45