- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我在使用 google map v2
时遇到问题。
当我启动项目时,我在此应用程序的 log cat 中发现了这一点,我尝试将用户位置存储在 mysql
数据库中。
Target SDK : API 18: Android 4.3
Compile With: API 18: Android 4.3
错误日志:
05-07 14:35:30.947: W/dalvikvm(1206): threadid=1: thread exiting with uncaught exception (group=0xb2a74ba8)
05-07 14:35:30.967: E/AndroidRuntime(1206): FATAL EXCEPTION: main
05-07 14:35:30.967: E/AndroidRuntime(1206): Process: in.wptrafficanalyzer.locationmarkermysql, PID: 1206
05-07 14:35:30.967: E/AndroidRuntime(1206): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationmarkermysql/in.wptrafficanalyzer.locationmarkermysql.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.os.Handler.dispatchMessage(Handler.java:102)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.os.Looper.loop(Looper.java:136)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-07 14:35:30.967: E/AndroidRuntime(1206): at java.lang.reflect.Method.invokeNative(Native Method)
05-07 14:35:30.967: E/AndroidRuntime(1206): at java.lang.reflect.Method.invoke(Method.java:515)
05-07 14:35:30.967: E/AndroidRuntime(1206): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-07 14:35:30.967: E/AndroidRuntime(1206): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-07 14:35:30.967: E/AndroidRuntime(1206): at dalvik.system.NativeStart.main(Native Method)
05-07 14:35:30.967: E/AndroidRuntime(1206): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-07 14:35:30.967: E/AndroidRuntime(1206): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.Activity.setContentView(Activity.java:1929)
05-07 14:35:30.967: E/AndroidRuntime(1206): at in.wptrafficanalyzer.locationmarkermysql.MainActivity.onCreate(MainActivity.java:35)
05-07 14:35:30.967: E/AndroidRuntime(1206): at android.app.Activity.performCreate(Activity.java:5231)
MainActivity.java
package in.wptrafficanalyzer.locationmarkermysql;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
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 MainActivity extends FragmentActivity {
GoogleMap mGoogleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting reference to SupportMapFragment
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// Creating GoogleMap from SupportMapFragment
mGoogleMap = fragment.getMap();
// Enabling MyLocation button for the Google Map
mGoogleMap.setMyLocationEnabled(true);
// Setting OnClickEvent listener for the GoogleMap
mGoogleMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng latlng) {
addMarker(latlng);
sendToServer(latlng);
}
});
// Starting locations retrieve task
new RetrieveTask().execute();
}
// Adding marker on the GoogleMaps
private void addMarker(LatLng latlng) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latlng);
markerOptions.title(latlng.latitude + "," + latlng.longitude);
mGoogleMap.addMarker(markerOptions);
}
// Invoking background thread to store the touched location in Remove MySQL server
private void sendToServer(LatLng latlng) {
new SaveTask().execute(latlng);
}
// Background thread to save the location in remove MySQL server
private class SaveTask extends AsyncTask<LatLng, Void, Void> {
@Override
protected Void doInBackground(LatLng... params) {
String lat = Double.toString(params[0].latitude);
String lng = Double.toString(params[0].longitude);
String strUrl = "http://10.0.2.2/location_marker_mysql/save.php";
URL url = null;
try {
url = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
connection.getOutputStream());
outputStreamWriter.write("lat=" + lat + "&lng="+lng);
outputStreamWriter.flush();
outputStreamWriter.close();
InputStream iStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new
InputStreamReader(iStream));
StringBuffer sb = new StringBuffer();
String line = "";
while( (line = reader.readLine()) != null){
sb.append(line);
}
reader.close();
iStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
// Background task to retrieve locations from remote mysql server
private class RetrieveTask extends AsyncTask<Void, Void, String>{
@Override
protected String doInBackground(Void... params) {
String strUrl = "http://10.0.2.2/location_marker_mysql/retrieve.php";
URL url = null;
StringBuffer sb = new StringBuffer();
try {
url = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream iStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
String line = "";
while( (line = reader.readLine()) != null){
sb.append(line);
}
reader.close();
iStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
new ParserTask().execute(result);
}
}
// Background thread to parse the JSON data retrieved from MySQL server
private class ParserTask extends AsyncTask<String, Void, List<HashMap<String, String>>>{
@Override
protected List<HashMap<String,String>> doInBackground(String... params) {
MarkerJSONParser markerParser = new MarkerJSONParser();
JSONObject json = null;
try {
json = new JSONObject(params[0]);
} catch (JSONException e) {
e.printStackTrace();
}
List<HashMap<String, String>> markersList = markerParser.parse(json);
return markersList;
}
@Override
protected void onPostExecute(List<HashMap<String, String>> result) {
for(int i=0; i<result.size();i++){
HashMap<String, String> marker = result.get(i);
LatLng latlng = new LatLng(Double.parseDouble(marker.get("lat")), Double.parseDouble(marker.get("lng")));
addMarker(latlng);
}
}
}
@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;
}
}
Android Mainfest
<i>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.wptrafficanalyzer.locationmarkermysql"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<!-- Protect the map component of the application using application signature -->
<permission
android:name="in.wptrafficanalyzer.locationmarkermysql.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!-- Allows to receive map -->
<uses-permission android:name="in.wptrafficanalyzer.locationmarkermysql.permission.MAPS_RECEIVE" />
<!-- Used by the Google Maps Android API V2 to download map tiles from Google Maps servers -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Allows the Google Maps Android API V2 to cache map tile data in the device's external storage area -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Allows the Google Maps Android API V2 to use WiFi or mobile cell data (or both) to determine the device's location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Allows the Google Maps Android API V2 to use the Global Positioning System (GPS)
to determine the device's location to within a very small area -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Allows to contact Google Serves -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Google Maps Android API V2 requires OpenGL ES version 2 -->
<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" >
<activity
android:name="in.wptrafficanalyzer.locationmarkermysql.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>
<!-- Specifies the Android API Key, which is obtained from Google API Console -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyARMaABMsbMqdHIwf1jysdyi9rFOsore6o" />
</application>
</manifest>
最佳答案
你失踪了
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
尝试将其添加到您的 list 中..
同时检查您是否正在使用
class = "com.google.android.gms.maps.SupportMapFragment"
为你的 fragment ..
关于android.view.InflateException 二进制 XML 文件行 #11 膨胀类 fragment 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23526081/
您好,所以在我们的项目中,我们使用的是书法库,它没有任何问题,但现在在我添加的一项 Activity 中,它不断崩溃并出现以下堆栈跟踪: 01-23 02:25:32.178 3654-3654/?
I published my application to the Play Store as open beta. I don't get any error when I run it wi
我因为工作室提示 Dialog 而苦苦挣扎已弃用, 所以我又去阅读文档,似乎 Toast也被弃用了。 所以我尝试从 Toast 迁移至Snackbar ,但目前失败...我 我加了 implement
每当我更改屏幕方向时,我的应用程序都会崩溃并出现以下异常。我相信这与 ImageViews 导致模拟器内存不足有关,但我无法理解堆栈跟踪。 在 ProfileActivity.java(我想允许改
InflateException 在使用 glide 加载大量图像时发生。 我做了一些研究并意识到 InflateException 可能不是我的 android 应用程序崩溃的真正原因,真正的问题应
我有更多的 Activity ,我没有任何问题,但是当我开始这个 Activity (Segunda)时它坏了在此 Activity 中,我尝试使用 customView 进行缩放和绘制,但我找不到问
我正在尝试创建一个自定义 View - 手指绘画,但我遇到了这个错误,我不知道如何修复它。谁能告诉我哪里出了问题? 日志: 08-04 08:34:01.171: E/AndroidRuntime(1
我的应用程序出现此错误 Error inflating class android.support.design.widget.FloatingActionButton 我在互联网上搜索错误,我尝试了
我有 recyclerview 项目,我正在尝试编辑它们的外观。我尝试向 recyclerview 的每个项目添加一个 float 操作按钮,但它引发了此错误: android.view.Inflat
我正在尝试与我的 fragment 进行通信,但代码与我不一致并给了我错误 E/AndroidRuntime: FATAL EXCEPTION: main Process
我对应用程序开发仍然很陌生,所以我正在努力创建一个跨越 5 页(我猜是 fragment )的基本音板。在 Android Studio 中创建项目时,我从默认的“选项卡式 Activity ”选项为
我已经做了一些尝试来修复这个错误。由于我不明白,所以我没有其他解决方法。 这是我的 XML -->
所以,我在 android.view.InflateException 方面遇到了很多麻烦,我不完全确定为什么。当我尝试加载 Google map fragment 时会发生这种情况。 对于此错误的任
我遇到了一个错误的痛苦。我有一个 SherlockFragmentActivity 和至少两个 SherlockFragment。两者都使用 onCreateView 来扩充 xml 文件。然而,Lo
启动具有 fragment 的 Activity 时,我不断收到该错误。 这是我的代码的概述: 主页 Activity 从启动 屏幕 Activity 开始 home.xml(每个 fragment
我使用 RingtonePreference 并希望使用默认通知声音作为默认首选项值。为此,我遵循了以下建议:RingtonePreference Default value 可悲的是,实际上我得到了
我的 xml 文件的第 59 行: 错误发生是因为 ?attr/属性。如果我将它替换为#FF00000 或其他内容,一切正常。这种崩溃并不经常发生。 07-28 19:16:46.686
我正在尝试设置一个虚拟测试以开始我的 android 项目。但是我无法让我的应用程序与 Espresso 一起运行。未经测试,该应用程序运行良好。 这是回溯: Running tests Test r
我在实现Jake Wharton's ViewPagerIndicator的时候发现了一些问题.这些是 Logcat 上的内容: 06-19 15:32:02.661: E/AndroidRuntim
我刚刚通过这个 setup 设置了 Robolectric 测试当我测试我的应用程序时,它给我一个错误。 我已将问题缩小到我的自定义 ActionBar 布局 中的 ProgressSpinner。当
我是一名优秀的程序员,十分优秀!