私はフラグメントがクラッシュして「地図を表示」ボタンをクリックしたときに地図を表示しようとしていますが、「残念なことに」appnameが「停止しました」というメッセージが表示されます。フラグメントボタンのクリックでマップアクティビティを呼び出す
Homefrag.javaこれは私のボタンの場所です。
package com.example.nardx.traveldirectoryzc;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ViewFlipper;
/**
* Created by nardx on 10/5/2016.
*/
public class HomeFrag extends Fragment {
View myView;
Button btnView1;
Context context;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.home, container, false);
context = myView.getContext();
ViewFlipper MyViewFlipper = (ViewFlipper)myView.findViewById(R.id.viewflipper);
MyViewFlipper.setAutoStart(true);
MyViewFlipper.setFlipInterval(3000);
MyViewFlipper.startFlipping();
btnView1 = (Button)myView.findViewById(R.id.btton1);
btnView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(context, GoogleMaps.class);
getActivity().startActivity(myIntent);
}
});
return myView;
}
}
これは、これは私のGoogleマップの活動である私のhome.xmlの彼xmlファイル
<?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">
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/zamboanga1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/stacruz3"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:src="@drawable/sta1"/>
<TextView
android:id="@+id/textv1"
android:layout_below="@id/viewflipper"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zamboanga City is called “Asia’s Latin City” because of its Spanish-tinged Chabacano dialect – dating back to the earliest foreign occupation of the Philippines in the 1600’s. This musical language is a huge part of Zamboangeño culture. You’ll find a lot of its influence in local song and dance."
/>
<Button
android:id="@+id/btton1"
android:layout_below="@id/textv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/textv1"
android:onClick="dismissListener"
android:text="View Map"/>
</RelativeLayout>
あるGoogleMap.java
package com.example.nardx.traveldirectoryzc;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class GoogleMaps extends AppCompatActivity implements OnMapReadyCallback{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google_maps);
SupportMapFragment mapFragment= (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public void onMapReady(GoogleMap googleMap){
LatLng sydney = new LatLng(-33.867, 151.206);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
googleMap.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
}
そして最後にGoogleマップ
<?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.nardx.traveldirectoryzc.GoogleMaps">
<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"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nardx.traveldirectoryzc.GoogleMaps"
/>
</RelativeLayout>
のためのXMLは、これは私がこのプロジェクトを完了するために必要な唯一のものです。うまくいけば誰かが私を助けるだろう。 Logcatエラー
10-10 18:30:39.710 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.711 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.712 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.712 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.721 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.726 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.727 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.735 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.747 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.750 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.762 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.nardx.traveldirectoryzc.MainActivity.access$super
10-10 18:30:39.905 18402-18402/com.example.nardx.traveldirectoryzc E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
10-10 18:31:04.772 18402-18402/com.example.nardx.traveldirectoryzc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.nardx.traveldirectoryzc, PID: 18402
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.nardx.traveldirectoryzc/com.example.nardx.traveldirectoryzc.GoogleMaps}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1634)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1430)
at android.app.Activity.startActivityForResult(Activity.java:3509)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3461)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
at android.app.Activity.startActivity(Activity.java:3712)
at android.app.Activity.startActivity(Activity.java:3680)
at com.example.nardx.traveldirectoryzc.HomeFrag$1.onClick(HomeFrag.java:37)
at android.view.View.performClick(View.java:4472)
at android.view.View$PerformClick.run(View.java:18779)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
たManifest.xml
<permission
android:name="com.myapp.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.myapp.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBbLehM0lsP_K27w0TxEDcG7HI5oiJk3ag" />
<activity android:name=".GoogleMap"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
>
</activity>
</application>
</manifest>
を追加したManifest.xml
に追加します。 '
KENdi