2014-01-18 119 views
0

http://umut.tekguc.info/en/content/google-android-map-v2-step-step复制了Android代码这是使用Google Maps v2的应用程序。我生成我的Api密钥并运行应用程序。当我在真实设备上运行应用程序时,应用程序有一些问题,我可以看到消息:您的应用程序意外停止。 我附上了代码和logCat。Android应用程序无法运行

Mainactivity.java

package info.tekguc.umut.googlemapsmapsandroidv2; 

import info.tekguc.umut.googlemapsmapsandroidv2.R; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 


import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MainActivity extends Activity { 

    private GoogleMap mMap; 

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

     mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
     mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
     final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097); 
     Marker ciu = mMap.addMarker(new MarkerOptions() 
            .position(CIU).title("My Office")); 
    } 

    @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; 
    } 

} 

activity_main.xml中

<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=".MainActivity" > 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/hello_world" /> 
        <fragment 
         android:id="@+id/map" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         class="com.google.android.gms.maps.MapFragment"/> 
       </RelativeLayout> 

的AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?> 
      <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
       package="info.tekguc.umut.googlemapsmapsandroidv2" 
       android:versionCode="1" 
       android:versionName="1.0" > 

       <uses-sdk 
        android:minSdkVersion="14" 
        android:targetSdkVersion="17" /> 

        <permission 
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" 
        android:protectionLevel="signature"></permission> 
       <uses-permission 
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/> 
       <uses-permission 
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
       <uses-permission 
        android:name="android.permission.INTERNET"/> 
       <uses-permission 
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
       <uses-permission 
        android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
       <uses-permission 
        android:name="android.permission.ACCESS_FINE_LOCATION"/> 

       <uses-feature 
        android:glEsVersion="0x00020000" 
        android:required="true"/> 

       <application 
        android:allowBackup="true" 
        android:icon="@drawable/ic_launcher" 
        android:label="@string/app_name" 
        android:theme="@style/AppTheme" > 
         <meta-data 
         android:name="com.google.android.maps.v2.API_KEY" 
         android:value="AIzaSyDciL7-T3BphxGv2q-A77vNrcyJQ_sTrgI"/> 
<meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 
        <activity 
         android:name="info.tekguc.umut.googlemapsmapsandroidv2.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> 
       </application> 

      </manifest> 

logcat的:

01-18 18:55:11.437: W/dalvikvm(9874): VFY: unable to resolve virtual method 11035: Linfo/tekguc/umut/googlemapsmapsandroidv2/MainActivity;.getFragmentManager()Landroid/app/FragmentManager; 
01-18 18:55:11.437: D/dalvikvm(9874): VFY: replacing opcode 0x6e at 0x0008 
01-18 18:55:11.437: D/dalvikvm(9874): VFY: dead code 0x000b-0045 in Linfo/tekguc/umut/googlemapsmapsandroidv2/MainActivity;.onCreate (Landroid/os/Bundle;)V 
01-18 18:55:11.445: I/ApplicationPackageManager(9874): cscCountry is not German : XEC 
01-18 18:55:11.460: W/dalvikvm(9874): threadid=1: thread exiting with uncaught exception (group=0x40018578) 
01-18 18:55:11.476: E/AndroidRuntime(9874): FATAL EXCEPTION: main 
01-18 18:55:11.476: E/AndroidRuntime(9874): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.tekguc.umut.googlemapsmapsandroidv2/info.tekguc.umut.googlemapsmapsandroidv2.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.os.Looper.loop(Looper.java:130) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.ActivityThread.main(ActivityThread.java:3687) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at java.lang.reflect.Method.invoke(Method.java:507) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at dalvik.system.NativeStart.main(Native Method) 
01-18 18:55:11.476: E/AndroidRuntime(9874): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.Activity.setContentView(Activity.java:1657) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at info.tekguc.umut.googlemapsmapsandroidv2.MainActivity.onCreate(MainActivity.java:21) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  ... 11 more 
01-18 18:55:11.476: E/AndroidRuntime(9874): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/info.tekguc.umut.googlemapsmapsandroidv2-1.apk] 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.createView(LayoutInflater.java:471) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) 
01-18 18:55:11.476: E/AndroidRuntime(9874):  ... 20 more 
+0

引起:java.lang.ClassNotFoundException:android.view.fragment在加载器中dalvik.system.PathClassLoader [/data/app/info.tekguc.umut.googlemapsmapsandroidv2-1.apk]你是否尝试在模拟器上运行它? – piotrpo

+0

@piotrpo不,我没有尝试模拟器,因为我没有安装谷歌播放服务。 – bucek

+0

@piotrpo有没有什么办法可以让我的手机工作? – bucek

回答

0

也许你可以使用简单的JavaScript作为替代这样的。

将此代码写在记事本中另存为html。

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>Marker Animations</title> 
    <style> 
     html, body, #map-canvas { 
     height: 100%; 
     margin: 0px; 
     padding: 0px 
     } 
    </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
    <script> 
// The following example creates a marker in location1, location2 
// using a DROP animation. Clicking on the marker will toggle 
// the animation between a BOUNCE animation and no animation. 


var location1 = new google.maps.LatLng(-7.298716, 112.766686); 
var location2 = new google.maps.LatLng(-7.298716, 112.766868); 
var marker; 
var map; 
var image = 'marks.png'; 
var info; 
var data = '<div id="content">'+ 
'</div>'+ 
'<h1 id="first" class="first">Your Title </h1>'+ 
'<div id="body">'+ 
'<p>type your body here'+ 
'</p>'+ 
'<p><a href="link">Read More...</a></p>'+ 
'</div>'+ 
'</div>'; 

function initialize() { 
    var mapOptions = { 
    zoom: 17, 
    center: location1 
    }; 

    map = new google.maps.Map(document.getElementById('map-canvas'), 
      mapOptions); 

    marker = new google.maps.Marker({ 
    map:map, 
    draggable:true, 
    icon: image, 
    animation: google.maps.Animation.DROP, 
    position: location2 
    }); 

    google.maps.event.addListener(marker, 'click', toggleBounce); 
} 

function toggleBounce() { 

    if (marker.getAnimation() != null) { 
    marker.setAnimation(null); 
    info.close(); 
    } else { 
    marker.setAnimation(google.maps.Animation.BOUNCE); 
    info = new google.maps.InfoWindow({ 
    content: data 
    }).open(map, marker); 

    } 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

    </script> 
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    </body> 
</html> 

html插入资产的文件夹,然后用webviewactivity_main.xml

<WebView 
     android:id="@+id/web" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

MainActivity.java

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.webkit.WebView; 

public class MainActivity extends Activity { 
    WebView webView; 

    @SuppressLint("SetJavaScriptEnabled") 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     webView = (WebView) findViewById(R.id.web); 
     webView.loadUrl("file:///android_asset/file.html"); 
     webView.getSettings().setJavaScriptEnabled(true); 

    } 

    @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; 
    } 

} 

希望能有所帮助。对不起,我的英文