运行时调试错误 [英] Debug Error while running

查看:268
本文介绍了运行时调试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试与给予我的previous问题,这是给我的错误在谷歌地图两种解决方案,原因是我在我的例子混合API1和API2 code结构,但在我得到这个理由我的问题我又创建2个实例之一API1和第二的API2但在任何例子我还没有得到解决方案,它不能运行我的应用程序成片,并给了我的问题,如:

 应用程序停止unexpectedly.please再试一次。
 

所以,任何人都可以帮助我exacltly在那里我错了,我打算把API1例子,API2的例子我的整个code与本论坛。


谷歌地图API1例如

AndroidManifest

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.example.googlemapapi1_21march
安卓版code =1
机器人:VERSIONNAME =1.0>

<使用-SDK安卓的minSdkVersion =7/>

<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_LOCATION/>
<应用机器人:图标=@可绘制/ ic_launcher机器人:标签=@字符串/ APP_NAME>
    <使用库机器人:名称=com.google.android.maps/>
    <活动机器人:标签=@字符串/ APP_NAME机器人:名称=。MapMarkerActivity>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>
< /舱单>
 

MainLayout.XML

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>

< com.google.android.maps.MapView
    机器人:ID =@ + ID /图形页面
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:启用=真
    机器人:可点击=真
    机器人:apiKey =0l4​​sCTTyRmXTNo7k8DREHvEaLar2UmHGwnhZVHQ
    />

<的LinearLayout机器人:ID =@ + ID /缩放
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_centerHorizo​​ntal =真
    />
< / RelativeLayout的>
 

MainActivity.java

 公共类GM1_21_MarchMainActivity扩展MapActivity {

图形页面图形页面;
@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_gm1_21__march_main);

     图形页面=(图形页面)findViewById(R.id.mapView);
        的LinearLayout zoomLayout =(的LinearLayout)findViewById(R.id.zoom);
        查看ZOOMVIEW = mapView.getZoomControls();

        zoomLayout.addView(ZOOMVIEW,
            新LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        mapView.displayZoomControls(真正的);

}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.activity_gm1_21__march_main,菜单);
    返回true;
}

@覆盖
保护的布尔isRouteDisplayed(){
    // TODO自动生成方法存根
    返回false;
}

 }
 


谷歌地图API2例如

AndroidManifest

 < XML版本=1.0编码=UTF-8&GT?;

<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.example.googlemapapi2_21march
安卓版code =1
机器人:VERSIONNAME =1.0>

<用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =17/>

<允许机器人:名称=com.example.googlemapapi2_21march.permission.MAPS_RECEIVE安卓的ProtectionLevel =签名/>
<使用-权限的Andr​​oid:名称=com.example.googlemapapi2_21march.permission.MAPS_RECEIVE/>
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>
<使用-权限的Andr​​oid:名称=com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_LOCATION/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_FINE_LOCATION/>

<用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/>

<应用
    机器人:allowBackup =真
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>

    <活动
        机器人:名称=com.example.googlemapapi2_21march.GMAPI2_MainActivity
        机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>

            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;

 < /用途>

 &所述;元数据
 机器人:名称=com.google.android.maps.v2.API_KEY
 机器人:值=AIzaSyAy_I76CpPtTMq3X6P8y78OamvLf_yaHJI/>

 < /舱单>
 

MainLayout.XML

 < XML版本=1.0编码=UTF-8&GT?;

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>

<片段
    机器人:名称=com.google.android.gms.maps.SupportMapFragment
    的xmlns:地图=htt​​p://schemas.android.com/apk/res-auto
    机器人:ID =@ + ID /图
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/>
< / LinearLayout中>
 

MainActivity.java

 公共类GMAPI2_MainActivity延伸活动{

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_gmapi2__main);
}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.activity_gmapi2__main,菜单);
    返回true;
}

  }
 

解决方案

对于谷歌地图API V2,为我所看到现在使用的是错误的活动为您的地图布局。您正在使用 SupportMapFragment 片段,并在那里你必须使用 FragmentActivity 对象,而不是一个简单的活动。尝试将其更改为 FragmentActivity

和告诉我们发生了什么变化。

I have tried with both solutions given for my previous problem which was giving me error in Google Map, the reason was I was mixing API1 and API2 code structure in my example, but after I got this reason of my problem I have again create 2 examples one for API1 and second for API2 but in any of example I had not got solution it can not run my application into tablet and gives me problem like:

"Application stopped unexpectedly.please try again". 

So anybody can help me exacltly where I'm wrong, I'm going to put my whole code of API1 example and API2 example with this forum.


Google Map API1 example

AndroidManifest

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

<uses-sdk android:minSdkVersion="7" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps" />
    <activity android:label="@string/app_name" android:name=".MapMarkerActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

MainLayout.XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent">

<com.google.android.maps.MapView 
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0l4sCTTyRmXTNo7k8DREHvEaLar2UmHGwnhZVHQ"
    />

<LinearLayout android:id="@+id/zoom" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    /> 
</RelativeLayout>

MainActivity.java

    public class GM1_21_MarchMainActivity extends MapActivity {

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

     mapView = (MapView) findViewById(R.id.mapView);
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
        View zoomView = mapView.getZoomControls(); 

        zoomLayout.addView(zoomView, 
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(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.activity_gm1_21__march_main, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

 }


Google Map API2 example

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapapi2_21march"
android:versionCode="1"
android:versionName="1.0" >

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

<permission android:name="com.example.googlemapapi2_21march.permission.MAPS_RECEIVE"     android:protectionLevel="signature"/>
<uses-permission  android:name="com.example.googlemapapi2_21march.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-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="com.example.googlemapapi2_21march.GMAPI2_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>

 <meta-data
 android:name="com.google.android.maps.v2.API_KEY"
 android:value="AIzaSyAy_I76CpPtTMq3X6P8y78OamvLf_yaHJI" />

 </manifest>

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

<fragment
    android:name="com.google.android.gms.maps.SupportMapFragment"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

MainActivity.java

     public class GMAPI2_MainActivity extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_gmapi2__main, menu);
    return true;
}

  }

解决方案

For the Google Maps API V2, for what I see now you are using the wrong Activity for your map layout. You are using the SupportMapFragment fragment, and there for you have to use the FragmentActivity object and not a simple Activity. try to change it to FragmentActivity.

And tell us what changed.

这篇关于运行时调试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆