Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将按钮放入浮动按钮中?_Java_Android_Google Maps_Android Maps V2 - Fatal编程技术网

Java 如何将按钮放入浮动按钮中?

Java 如何将按钮放入浮动按钮中?,java,android,google-maps,android-maps-v2,Java,Android,Google Maps,Android Maps V2,我似乎不知道该怎么办。单击浮动按钮后,我的应用程序崩溃,因为我没有在清单中声明SecondActivity.java 这里是activity_maps.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schema

我似乎不知道该怎么办。单击浮动按钮后,我的应用程序崩溃,因为我没有在清单中声明SecondActivity.java

这里是activity_maps.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:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity">



        <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=".MapsActivity"
            tools:layout="@android:layout/simple_spinner_dropdown_item" />


        <ImageButton
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:id="@+id/imagebutton"
            android:src="@drawable/ic_pin_drop_black_24dp"
            />
        </RelativeLayout>
我创建了第二个活动 activty_second.xml

           <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout        xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical" android:layout_width="match_parent"
          android:layout_height="match_parent">

        <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=".MapsActivity"
            tools:layout="@android:layout/simple_spinner_dropdown_item" />

          <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Lagos Mainland"
            android:padding="8dp"
            android:background="#53fed0"
            android:id="@+id/buttonMaps"
            android:layout_marginLeft="90dp"
            android:layout_marginStart="90dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            />

         <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hospital"
            android:id="@+id/buttonMaps2"
            android:layout_marginTop="35dp"
            android:layout_below="@+id/buttonMaps"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:clickable="true"
            android:background="@color/colorAccent" />

         <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bus Stops"
            android:id="@+id/buttonMaps3"
            android:clickable="true"
            android:layout_marginTop="35dp"
            android:background="@color/colorAccent"
            android:layout_below="@+id/buttonMaps2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
         <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Taxi"
            android:id="@+id/buttonMaps4"
            android:layout_below="@+id/buttonMaps3"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="35dp"
            android:clickable="true"
            android:background="@color/colorAccent" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gas Station"
            android:id="@+id/buttonMaps5"
            android:layout_marginTop="35dp"
            android:clickable="true"
            android:background="@color/colorAccent"
            android:layout_below="@+id/buttonMaps4"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
           <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Park"
            android:id="@+id/buttonMaps6"
            android:layout_marginTop="35dp"
            android:clickable="true"
            android:background="@color/colorAccent"
            android:layout_below="@+id/buttonMaps5"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

             </LinearLayout>
我的Android清单

     <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"

        package="com.example.android.multidex.myapplication">
        android:theme="@android:style/AppTheme"
         <uses-permission android:name="android.permission.INTERNET"/>
         <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
         <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
         <uses-permission    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>


        <!--
             The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
             Google Maps Android API v2, but you must specify either coarse or fine
             location permissions for the 'MyLocation' functionality. 
        -->
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"    />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"   />

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="Android Map"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            android:name="android.support.multidex.MultiDexApplication">
            <!--
                 The API key for Google Maps-based APIs is defined as a string resource.
                 (See the file "res/values/google_maps_api.xml").
                 Note that the API key is linked to the encryption key used to sign the APK.
                 You need a different API key for each encryption key, including the release key that is used to
                 sign the APK for publishing.
                 You can define the keys for the debug and release targets in src/debug/ and src/release/. 
            -->

            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="" />
            <activity
                android:name=".MapsActivity"
                android:label="Map">
                <activity
                    android:name=".SecondActivity"/>

                </activity>

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>


        </application>

        </manifest>

您在清单中以错误的方式声明了您的活动,请执行以下操作:

<activity
                android:name=".MapsActivity"
                android:label="Map">

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
</activity>
<activity android:name=".SecondActivity"/>


你能提供崩溃日志吗?在
浮动按钮
中放置按钮意味着什么?你的清单中嵌套了
第二个活动
,我认为这是导致崩溃的原因problem@ZekeDran我的意思是当我点击浮动按钮时,我希望按钮出现。请问我如何将第二个活动从巢中移出
     <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"

        package="com.example.android.multidex.myapplication">
        android:theme="@android:style/AppTheme"
         <uses-permission android:name="android.permission.INTERNET"/>
         <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
         <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
         <uses-permission    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>


        <!--
             The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
             Google Maps Android API v2, but you must specify either coarse or fine
             location permissions for the 'MyLocation' functionality. 
        -->
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"    />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"   />

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="Android Map"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            android:name="android.support.multidex.MultiDexApplication">
            <!--
                 The API key for Google Maps-based APIs is defined as a string resource.
                 (See the file "res/values/google_maps_api.xml").
                 Note that the API key is linked to the encryption key used to sign the APK.
                 You need a different API key for each encryption key, including the release key that is used to
                 sign the APK for publishing.
                 You can define the keys for the debug and release targets in src/debug/ and src/release/. 
            -->

            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="" />
            <activity
                android:name=".MapsActivity"
                android:label="Map">
                <activity
                    android:name=".SecondActivity"/>

                </activity>

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>


        </application>

        </manifest>
FATAL EXCEPTION: main
                                                                        android.content.ActivityNotFoundException: Unable to find explicit activity   class {com.example.user.naviapp/com.example.user.naviapp.SecondActivity}; have you declared this activity in your AndroidManifest.xml?
                                                                          at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
                                                                          at android.app.Instrumentation.execStartActivity(Instrumentation.java:1388)
                                                                          at android.app.Activity.startActivityForResult(Activity.java:3190)
                                                                          at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871)
                                                                          at android.app.Activity.startActivity(Activity.java:3297)
                                                                          at com.example.user.naviapp.MapsActivity$1.onClick(MapsActivity.java:49)
                                                                          at android.view.View.performClick(View.java:3558)
                                                                          at android.view.View$PerformClick.run(View.java:14157)
                                                                          at android.os.Handler.handleCallback(Handler.java:605)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                          at android.os.Looper.loop(Looper.java:137)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:4514)
                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:511)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
                                                                          at dalvik.system.NativeStart.main(Native Method)
<activity
                android:name=".MapsActivity"
                android:label="Map">

                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
</activity>
<activity android:name=".SecondActivity"/>