Android的故障排除错误显示"不幸的是应用程序已停止工作" [英] Troubleshooting android displaying error"Unfortunately app has stopped working"

查看:138
本文介绍了Android的故障排除错误显示"不幸的是应用程序已停止工作"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了谷歌Android应用程序映射通过月食,没有错误,但是当我在模拟器或Android设备上安装并运行它时,会显示错误消息,不幸的是应用程序已停止工作。
请指导我的故障排除。
这是Java的主要活动文件: -

 包com.example.droidloc;  进口的java.util.List;  进口android.os.Bundle;
 进口android.app.Activity;
   进口android.app.AlertDialog;
  进口android.content.DialogInterface;   进口com.google.android.maps.MapActivity;
   进口com.google.android.maps.MapView;
  进口com.google.android.maps.Overlay;进口android.view.Menu;
进口android.view.MotionEvent; 公共类MainActivity扩展MapActivity {
 MapView的地图;
长启动;
多头止损;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    地图=(图形页面)findViewById(R.id.mainmap);
    map.setBuiltInZoomControls(真);
    敏感的T =新的敏感();
    清单<&叠加GT; overlayList = map.getOverlays();
    overlayList.add(T);
}@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
    //充气菜单;如果是present这增加了项目操作栏。
    。getMenuInflater()膨胀(R.menu.activity_main,菜单);
    返回true;
}敏感类覆盖扩展
{
    @燮pressWarnings(德precation)
    公共布尔onTouchEvent(MotionEvent E,MapView类M)
    {
        如果(e.getAction()== MotionEvent.ACTION_DOWN)
        {
            开始= e.getEventTime();
        }
        如果(e.getAction()== MotionEvent.ACTION_UP)
        {
            停止= e.getEventTime();
        }
        如果(制动 - 起动> 1500)
        {
            AlertDialog警报=新                 AlertDialog.Builder(MainActivity.this).create();
            alert.setTitle(选择一个选项);
            alert.setMessage(选择一个选项花花公子);
            alert.setButton2(一针点,新               DialogInterface.OnClickListener(){                @覆盖
                公共无效的onClick(DialogInterface为arg0,ARG1 INT)
     {
                    // TODO自动生成方法存根                }
            });
            alert.show();
            返回true;        }
        返回false;
    }
    }@覆盖
保护布尔isRouteDisplayed(){
    // TODO自动生成方法存根
    返回false;
}
      }
-------------------------------------------------- -------------------------------------

这是XML文件: -

 <?XML版本=1.0编码=UTF-8&GT?;
   <片段的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
      机器人:ID =@ + ID / mainmap
      机器人:layout_width =match_parent
      机器人:layout_height =match_parent
      机器人:名字=com.google.android.gms.maps.MapFragment
      机器人:启用=真
      机器人:可点击=真
      />-------------------------------------------------- -------------------------------------

这是清单文件: -

 <?XML版本=1.0编码=UTF-8&GT?;
  <清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  包=com.example.droidloc
  安卓版code =1
  机器人:=的versionName1.0>  <用途-SDK
    安卓的minSdkVersion =8
    机器人:targetSdkVersion =16/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
 <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
 <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
      <用途特征
    机器人:glEsVersion =0x00020000
    机器人:要求=真/>   <应用
    机器人:allowBackup =真
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <使用库机器人:名字=com.google.android.maps/>
    <活动
        机器人:名字=com.example.droidloc.MainActivity
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    &所述;元数据
  机器人:名字=com.google.android.maps.v2.API_KEY
  机器人:值=AIzaSyAlHKiaTa8KrABuGHIvcuZ4IiBFifqOu1s/>
  < /用途>  < /清单>


解决方案

有一堆东西不见了。继承人的我所看到的名单,还有一些是从评论:


  1. 您正在扩展它是基于谷歌versio 1地图的Andr​​oid mapActivity。但在XML中使用的是谷歌的mapfragment V2映射机器人。

  2. 您应该延伸FragmentActivity或类似ActionBarActivity从FragmentActivity扩展的任何其他活动。

  3. 您缺少元数据标签清单文件。

  4. 敏SDK版本是8,所以你需要在你使用mapfragment这是可以高于11 API XML使用SupportMapFragment。

i have created an android app on google maps through eclipse,there are no errors but when i install it on emulator or any android device and run it,error message is displayed that "unfortunately app has stopped working". please guide me for the troubleshooting. this is the java main activity file :-

      package com.example.droidloc;

  import java.util.List;

  import android.os.Bundle;
 import android.app.Activity;
   import android.app.AlertDialog;
  import android.content.DialogInterface;

   import com.google.android.maps.MapActivity;
   import com.google.android.maps.MapView;
  import com.google.android.maps.Overlay;

import android.view.Menu;
import android.view.MotionEvent;

 public class MainActivity extends MapActivity {
 MapView map;
long start;
long stop;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map=(MapView)findViewById(R.id.mainmap);
    map.setBuiltInZoomControls(true);
    touchy t =new touchy();
    List<Overlay> overlayList = map.getOverlays();
    overlayList.add(t);
}

@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_main, menu);
    return true;
}

class touchy extends Overlay
{
    @SuppressWarnings("deprecation")
    public boolean onTouchEvent(MotionEvent e,MapView m)
    {
        if(e.getAction()==MotionEvent.ACTION_DOWN)
        {
            start=e.getEventTime();
        }
        if(e.getAction()==MotionEvent.ACTION_UP)
        {
            stop=e.getEventTime();
        }
        if(stop-start>1500)
        {
            AlertDialog alert=new                           

                 AlertDialog.Builder(MainActivity.this).create();
            alert.setTitle("Pick an Option");
            alert.setMessage("Pick an Option dude");
            alert.setButton2("Pin a Point", new        

               DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface arg0, int arg1)      
     {
                    // TODO Auto-generated method stub

                }
            });
            alert.show();
            return true;

        }
        return false ;
    }
    }

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


      }
---------------------------------------------------------------------------------------

This is the xml file :-

   <?xml version="1.0" encoding="utf-8"?>
   <fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mainmap"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"
      android:enabled="true"
      android:clickable="true"
      />

---------------------------------------------------------------------------------------

this is the manifest file :-

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

  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<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="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" >
    <uses-library android:name="com.google.android.maps" />
    <activity
        android:name="com.example.droidloc.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="AIzaSyAlHKiaTa8KrABuGHIvcuZ4IiBFifqOu1s"/>
  </application>

  </manifest>

解决方案

There are a bunch of things missing. Heres a list of what I saw, and some are from comments:

  1. You are extending mapActivity which is based on versio 1 of google maps android. But in xml you are using mapfragment v2 of google maps android.
  2. You should extend FragmentActivity or any other activity like ActionBarActivity that extends from FragmentActivity.
  3. You are missing metadata tag in manifest file.
  4. Min sdk version is 8 so you need to use SupportMapFragment in xml you are using mapfragment which is available above api 11.

这篇关于Android的故障排除错误显示&QUOT;不幸的是应用程序已停止工作&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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