0

我正在尝试编辑 BluetoothChat 应用程序。我想将 GPS 数据从一部带有原始蓝牙聊天的手机发送到另一部带有我修改过的 BT-Chat 的手机。这个想法是从第一部电话发送像“54.12345 55.23455”这样的经度和纬度。第二个应该检查输入消息并将其显示在谷歌地图的主要活动中。

我已经制作了一个带有片段的 googlemap 应用程序,它运行良好!现在我尝试从 BT-Chat 中更改 main.xml,就像在我的 googlemaps xml 中一样。它应该有一个文本视图来显示 gps 数据、一个地图片段和一个小列表视图,但我只得到一些我不理解的错误......通过在片段下制作一个带有列表视图的 main.xml 是否有问题?

日志猫:

10-31 09:19:50.785: E/BluetoothChat(31615): +++ ON CREATE +++
10-31 09:19:50.890: D/AndroidRuntime(31615): Shutting down VM
10-31 09:19:50.890: W/dalvikvm(31615): threadid=1: thread exiting with uncaught exception (group=0x415102a0)
10-31 09:19:50.895: E/AndroidRuntime(31615): FATAL EXCEPTION: main
10-31 09:19:50.895: E/AndroidRuntime(31615): java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.example.android.BluetoothChat/com.example.android.BluetoothChat.Bluetooth    Chat}: android.view.InflateException: Binary XML file line #13: Error inflating class  fragment
10-31 09:19:50.895: E/AndroidRuntime(31615):    at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.os.Looper.loop(Looper.java:137)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.ActivityThread.main(ActivityThread.java:4898)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at java.lang.reflect.Method.invokeNative(Native Method)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at java.lang.reflect.Method.invoke(Method.java:511)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at dalvik.system.NativeStart.main(Native Method)
10-31 09:19:50.895: E/AndroidRuntime(31615): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Activity.setContentView(Activity.java:1924)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at com.example.android.BluetoothChat.BluetoothChat.onCreate(BluetoothChat.java:90)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Activity.performCreate(Activity.java:5206)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
10-31 09:19:50.895: E/AndroidRuntime(31615):    ... 11 more
10-31 09:19:50.895: E/AndroidRuntime(31615): 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
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Fragment.instantiate(Fragment.java:584)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Fragment.instantiate(Fragment.java:552)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Activity.onCreateView(Activity.java:4849)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
10-31 09:19:50.895: E/AndroidRuntime(31615):    ... 21 more
10-31 09:19:50.895: E/AndroidRuntime(31615): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
10-31 09:19:50.895: E/AndroidRuntime(31615):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-31 09:19:50.895: E/AndroidRuntime(31615):    at android.app.Fragment.instantiate(Fragment.java:574)
10-31 09:19:50.895: E/AndroidRuntime(31615):    ... 24 more

我使用 Galaxy S1+ 和 Galaxy S3 进行调试。

主.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" >

<TextView
    android:id="@+id/gps_data"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F8F8ff" />

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.00"
    class="com.google.android.gms.maps.MapFragment" /> 

<ListView
    android:id="@+id/in"
    android:layout_width="match_parent"
    android:layout_height="66dp"
    android:layout_weight="0.00"
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll" />

</LinearLayout>

我已经设法从传入消息中获取 gps 数据,但是由于 main.xml 中的片段,该应用程序将无法运行。

原谅我的英语不好!:(

4

0 回答 0