android Map应用程序跟踪错误

时间:2013-07-16 06:13:44

标签: android google-maps android-maps-v2

我正在开发一个android地图应用程序来在地图上放置标记。我正在使用JSON将标记数据从url解析到Place on Map但是我在Log Cat中得到了以下错误。这里是Log Cat

    07-16 11:27:37.771: E/Trace(32163): error opening trace file: No such file or directory (2)
07-16 11:27:37.791: W/dalvikvm(32163): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:27:38.391: W/System.err(32163): Invalid int: ""
07-16 11:27:38.411: W/dalvikvm(32163): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:27:39.961: W/dalvikvm(32163): threadid=1: thread exiting with uncaught exception (group=0x41cdc438)
07-16 11:28:48.851: E/Trace(32327): error opening trace file: No such file or directory (2)
07-16 11:28:48.901: W/dalvikvm(32327): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:28:49.271: W/System.err(32327): Invalid int: ""
07-16 11:28:49.291: W/dalvikvm(32327): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
07-16 11:28:49.871: W/dalvikvm(32327): threadid=1: thread exiting with uncaught exception (group=0x41cdc438)

来源 这是我的源代码

    package pkg.pkg.map3;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;

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

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment; 

import android.graphics.drawable.Drawable;
import android.net.ParseException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;



public class MainActivity extends FragmentActivity  {
    JSONArray jArray;
    String result = null;
    InputStream is = null;
    StringBuilder sb=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //GoogleMap mMap;
        //mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
        GoogleMap mMap = fm.getMap();
        String readTwitterFeed = readpoints();
        double LAT;
        double LANG;
        String INFO; 
        try {
              JSONArray jsonArray = new JSONArray(readTwitterFeed);
              for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                LAT=jsonObject.getDouble("lat");
                LANG=jsonObject.getDouble("lang");
                INFO=jsonObject.getString("info");
                mMap.addMarker(new MarkerOptions().position(new LatLng(LAT, LANG)).title(INFO));
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
    }

    @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;
    }
    public String readpoints() {
        StringBuilder builder = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://202.125.144.34/a/map.php");
        try {
          HttpResponse response = client.execute(httpGet);
          StatusLine statusLine = response.getStatusLine();
          int statusCode = statusLine.getStatusCode();
          if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            builder.append(reader.readLine() + "\n");
            String line;
            while ((line = reader.readLine()) != null) {
              builder.append(line + "\n");
            }
          } else {
            Log.e(MainActivity.class.toString(), "Failed to download file");
          }
        } catch (ClientProtocolException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        return builder.toString();
      }
}

清单

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

    <uses-sdk android:minSdkVersion="10" android:maxSdkVersion="16" android:targetSdkVersion="16"/>

    <permission
        android:name="pkg.pkg.map3.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

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


    <uses-permission android:name="pkg.pkg.map3.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" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_PERMISSION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:debuggable="true" >
        <activity
            android:name="pkg.pkg.map3.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="AIzaSyDhJFrxxmuDGC4EC389AJ9AmyKFc--0S8s" />
    </application>

</manifest>

布局

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

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

</RelativeLayout>

任何人告诉我这个问题可能是什么问题.Plz帮助!

1 个答案:

答案 0 :(得分:0)

将此添加到清单

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

更改为

    <uses-permission android:name="pkg.pkg.map3.maps.permission.MAPS_RECEIVE" />

从我看到你的min sdk是8。

您应该使用SupportMapFragment

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/SupportMapFragment

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

您的活动必须延长FragmentActivity并使用以下内容初始化GoogleMap对象。

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap(); 

同时确保导入以下内容

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment; 

此外,我发现您不是使用asynctaskthread进行与网络相关的操作

HttpResponse response = client.execute(httpGet);

如果您在后蜂窝版本上运行上述内容,则会获得NetWorkOnMainThreadException