こんにちは、Google マップをアプリに挿入するために Android アプリのヘルプが必要になりますが、そのたびにアプリがクラッシュします。問題を見つけるのを手伝ってくれる人がいる場合は、以下にコードを挿入します。コードで。
Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maret.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<permission
android:name="com.maret.toilet.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="com.maret.toilet.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="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.maret.toilet.MainActivity"
android:label="@string/app_name" >
<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="***MY_API_KEY****"/>
</application>
</manifest>
ここに私の activity_main.xml があります
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My Location"
android:onClick="getLocation"
android:layout_weight="0"
/>
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
ここに私の MainActivity.java があります
package com.maret.maps;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
私のエラーログ
03-19 08:41:45.552: E/Trace(641): error opening trace file:
No such file or directory (2)
03-19 08:41:45.861: D/AndroidRuntime(641):
Shutting down VM
03-19 08:41:45.872: W/dalvikvm(641):
threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-19 08:41:45.891: E/AndroidRuntime(641): FATAL EXCEPTION: main
03-19 08:41:45.891: E/AndroidRuntime(641):
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maret.toilet/com.maret.toilet.MainActivity}: android.view.InflateException:
Binary XML file line #15: Error inflating class fragment
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.os.Looper.loop(Looper.java:137)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.main(ActivityThread.java:4745)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.reflect.Method.invokeNative(Native Method)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.reflect.Method.invoke(Method.java:511)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-19 08:41:45.891: E/AndroidRuntime(641):
at dalvik.system.NativeStart.main(Native Method)
03-19 08:41:45.891: E/AndroidRuntime(641):
Caused by: android.view.InflateException:
Binary XML file line #15: Error inflating class fragment
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Activity.setContentView(Activity.java:1867)
03-19 08:41:45.891: E/AndroidRuntime(641):
at com.maret.toilet.MainActivity.onCreate(MainActivity.java:12)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Activity.performCreate(Activity.java:5008)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-19 08:41:45.891: E/AndroidRuntime(641): ... 11 more
03-19 08:41:45.891: E/AndroidRuntime(641):
Caused by: android.app.Fragment$InstantiationException:
Unable to instantiate fragment com.google.android.gms.maps.MapFragment:
make sure class name exists, is public, and has an empty constructor that is public
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Fragment.instantiate(Fragment.java:584)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Fragment.instantiate(Fragment.java:552)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Activity.onCreateView(Activity.java:4656)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-19 08:41:45.891: E/AndroidRuntime(641): ... 21 more
03-19 08:41:45.891: E/AndroidRuntime(641):
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
03-19 08:41:45.891: E/AndroidRuntime(641):
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-19 08:41:45.891: E/AndroidRuntime(641):
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-19 08:41:45.891: E/AndroidRuntime(641):
at android.app.Fragment.instantiate(Fragment.java:574)
03-19 08:41:45.891: E/AndroidRuntime(641): ... 24 more
これが新しいレイアウトとアクティビティです
これは main.xml です
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
* ここに私の main.java があります * *
package com.maret.maps;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
アプリがクラッシュしたときの新しい LOGCAT は次のとおりです**
SupportMapFragment は android.app.Fragment 03-21 12:23:04.452: E/AndroidRuntime(958): android.app.Fragment.instantiate(Fragment.java:577) 03-21 12:23:04.452 にキャストできません: E/AndroidRuntime(958): android.app.Fragment.instantiate(Fragment.java:552) 03-21 12:23:04.452: E/AndroidRuntime(958): android.app.Activity.onCreateView(Activity.java) :4656) 03-21 12:23:04.452: E/AndroidRuntime(958): android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 03-21 12:23:04.452: E/AndroidRuntime(958): ... 21 詳細 03-21 12:23:07.973: I/Process(958): シグナルを送信しています。PID: 958 SIG: 9 android.app.Activity.onCreateView(Activity.java:4656) 03-21 12:23:04.452: E/AndroidRuntime(958): android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 03-21 12 :23:04.452: E/AndroidRuntime(958): ... 21 more 03-21 12:23:07.973: I/Process(958): シグナルを送信しています。PID: 958 SIG: 9 android.app.Activity.onCreateView(Activity.java:4656) 03-21 12:23:04.452: E/AndroidRuntime(958): android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 03-21 12 :23:04.452: E/AndroidRuntime(958): ... 21 more 03-21 12:23:07.973: I/Process(958): シグナルを送信しています。PID: 958 SIG: 9