android.view.inflateException:二进制XML文件行#11:错误膨胀类片段

android.view.inflateException:二进制XML文件行#11:错误膨胀类片段,第1张

概述嗨,我在 Android中有点新,我正在开发一个显示和映射一些标记的代码.我使用了2个按钮,一个用于查看地图,另一个用于添加信息.问题是,我第一次点击显示地图,它显示,但当我回到“mainmenu”并再次点击显示地图时,只需显示黑屏并显示此错误: android.view.inflateException: Binary XML file line #11: Error inflating cla 嗨,我在 Android中有点新,我正在开发一个显示和映射一些标记的代码.我使用了2个按钮,一个用于查看地图,另一个用于添加信息.问题是,我第一次点击显示地图,它显示,但当我回到“mainmenu”并再次点击显示地图时,只需显示黑屏并显示此错误:

androID.vIEw.inflateException: Binary XML file line #11: Error inflating class fragment 

我正在使用API​​ 16,如果我没有错,我应该像我正在做的那样使用MapFragmet,而不是扩展Fragment,因为它在旧版本中使用,不是吗?

我的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" >    <fragment        androID:ID="@+ID/map"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"          />    <ImageVIEw        androID:ID="@+ID/logo"        androID:layout_wIDth="60dp"        androID:layout_height="60dp"        androID:layout_alignRight="@+ID/map"        androID:layout_aligntop="@+ID/map"        androID:contentDescription="@string/hintlogo"        androID:src="@drawable/logo" /></relativeLayout>

我的清单

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="uri.br.rs"    androID:versionCode="1"    androID:versionname="1.0" >    <uses-sdk        androID:minSdkVersion="11"        androID:targetSdkVersion="16" /><!-- Permissão para exibir o mapa -->    <permission        androID:name="uri.br.rs.permission.MAPS_RECEIVE"        androID:protectionLevel="signature"/>    <uses-permission androID:name="uri.br.rs.permission.MAPS_RECEIVE"/><!-- Permissão para interner,entre outros -->    <uses-permission androID:name="androID.permission.INTERNET"/>    <uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE"/>    <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE"/>    <uses-permission androID:name="com.Google.androID.provIDers.gsf.permission.READ_GSERVICES"/><!-- Estas permissões não são necessárias para usar o         Google Maps AndroID API v2,mas são recomendadas. -->    <uses-permission androID:name="androID.permission.ACCESS_COARSE_LOCATION"/>    <uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION"/><!-- Permissão para usar o OpenGL -->    <uses-feature        androID:glEsversion="0x00020000"        androID:required="true"/>        <application        androID:allowBackup="true"        androID:icon="@drawable/logo"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" ><!-- Chave do Google Maps AndroID,regisTrada no site do Google Apis -->        <Meta-data            androID:name="com.Google.androID.maps.v2.API_KEY"            androID:value="some_key"/>        <activity            androID:name="uri.br.rs.TudoImoveis"            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>

我的班级名为TudoImoveis:

package uri.br.rs;import java.util.ArrayList;import java.util.List;import com.Google.androID.gms.maps.CameraUpdate;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.MarkerOptions;import androID.os.Bundle;import androID.app.Activity;import androID.app.AlertDialog;import androID.content.DialogInterface;import androID.content.Intent;import androID.database.Cursor;import androID.database.sqlite.sqliteDatabase;import androID.vIEw.LayoutInflater;import androID.vIEw.Menu;import androID.vIEw.VIEw;import androID.Widget.AdapterVIEw;import androID.Widget.ArrayAdapter;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.ImageVIEw;import androID.Widget.ListVIEw;import androID.Widget.TextVIEw;import androID.Widget.Toast;import androID.Widget.AdapterVIEw.OnItemClickListener;public class TudoImoveis extends Activity {    String login = "admin",senha= "admin",loginaux,senhaaux;    int guardaID;// Dados do banco    sqliteDatabase bancoDados = null;    Cursor cursor;// Dados do mapa    GoogleMap map;    final LatLng stgo = new LatLng(-29.191357,-54.866588);    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        Toast.makeText(getApplicationContext(),"On Created!",Toast.LENGTH_LONG).show();        menuPrincipal(); //chama menu inicial    }    @OverrIDe      public boolean onCreateOptionsMenu(Menu menu) {        getMenuInflater().inflate(R.menu.tudo_imoveis,menu);        return true;      }// ---------------------------------------------- Chama a tela inicial ----------------------------------------------    public voID menuPrincipal(){        setContentVIEw(R.layout.principal);        button btFechar = (button) findVIEwByID(R.ID.btfechar);        button btVer = (button) findVIEwByID(R.ID.btVer);        button btAnunciar = (button) findVIEwByID(R.ID.btAnunciar);        button btLogar = (button) findVIEwByID(R.ID.btLogar);        TextVIEw tvlogin = (TextVIEw) findVIEwByID(R.ID.tvLogin);        TextVIEw tvsenha = (TextVIEw) findVIEwByID(R.ID.tvSenha);        EditText etLogin = (EditText) findVIEwByID(R.ID.etLogin);        EditText etSenha = (EditText) findVIEwByID(R.ID.etSenha);// Deixa login invisível        tvlogin.setVisibility(VIEw.INVISIBLE);        tvsenha.setVisibility(VIEw.INVISIBLE);        etLogin.setVisibility(VIEw.INVISIBLE);        etSenha.setVisibility(VIEw.INVISIBLE);        btLogar.setVisibility(VIEw.INVISIBLE);// Botão ver        btVer.setonClickListener(new VIEw.OnClickListener() {            public voID onClick(VIEw arg0) {                abreOuCriaBanco();                mostraMapa();                Toast.makeText(getApplicationContext(),"Mapa",Toast.LENGTH_SHORT).show();            }        });// Botão Anunciar        btAnunciar.setonClickListener(new VIEw.OnClickListener() {            public voID onClick(VIEw v) {                abreOuCriaBanco();                logar();                            }        });// Botão fechar            btFechar.setonClickListener(new VIEw.OnClickListener() {                public voID onClick(VIEw arg0) {                    sairsistema();                }            });    }// ------------------------------------------- Função mostraMapa() ---------------------------------------------------    public voID mostraMapa(){        try{        setContentVIEw(R.layout.mapa);        ImageVIEw logo = (ImageVIEw) findVIEwByID(R.ID.logo);        map = ((MapFragment) getFragmentManager().findFragmentByID(R.ID.map)).getMap();        // utiliza-se este método para versões superiores ao AndroID 3.0 com import da biblioteca        // import com.Google.androID.gms.maps.MapFragment;        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(stgo,15);        map.animateCamera(update);// Ao clicar na imagem        logo.setonClickListener(new VIEw.OnClickListener() {            public voID onClick(VIEw arg0) {                menuPrincipal();                //bancoDados.close();                Toast.makeText(getApplicationContext(),"Menu Principal",Toast.LENGTH_SHORT).show();            }        });// Se não tem dados carrega a casa            if (buscaDados()==true){                map = ((MapFragment) getFragmentManager().findFragmentByID(R.ID.map)).getMap();                map.addMarker(new MarkerOptions()                            .position(new LatLng(-29.187648,-54.864245))                                .Title("Duque de Caxias,513,apt. 403")                                .icon(BitmapDescriptorFactory.fromresource(R.drawable.casa)));            }// Se tem dados 1º de maneira estática pra ver se funciona            if (buscaDados()==false){                map = ((MapFragment) getFragmentManager().findFragmentByID(R.ID.map)).getMap();                map.addMarker(new MarkerOptions()                                .position(new LatLng(-29.187648,-54.864245))                                .Title("Falso,apt. 403")                                .icon(BitmapDescriptorFactory.fromresource(R.drawable.casa)));                Toast.makeText(getApplicationContext(),"Não existem registros!",Toast.LENGTH_SHORT).show();            }        }catch (Exception e){Toast.makeText(getApplicationContext(),"Erro: "+e,Toast.LENGTH_SHORT).show();}    }
解决方法 将您的课程扩展到Fragmentactivity

检查是否添加了Google play服务以正确构建路径

转到项目|属性选择“订购和导出”选项卡中的“Java构建路径”部分,选择Googleplay服务并清理你的项目

总结

以上是内存溢出为你收集整理的android.view.inflateException:二进制XML文件行#11:错误膨胀类片段全部内容,希望文章能够帮你解决android.view.inflateException:二进制XML文件行#11:错误膨胀类片段所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1125092.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存