应用程序崩溃意图从谷歌地图开始

时间:2014-02-13 02:38:03

标签: java android google-maps android-intent

地图活动的Java代码

package com.schweigert.drinkingbuddy;

import android.app.Activity;
import android.os.Bundle;


public class BarMaps extends Activity {



protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.barmaps);


}
}

XML代码

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


</fragment>

启动意图的Java代码

    maps.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v) {


                Intent openMap = new Intent("com.schweigert.drinkingbuddy.BarMaps");
                startActivity(openMap);


        }

    });

当我在我的模拟器上运行此代码时,我已在我的计算机上设置它会显示“除非您更新Google Play服务,否则此应用程序不会运行。但是当我在物理设备上运行它时,它只是超时而且说该应用程序已停止工作。为什么我的模拟器和物理设备之间的错误有这样的差异?

编辑:

package com.schweigert.drinkingbuddy;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;


public class StartingPoint extends Activity {

double numDrinks;
int counter;
EditText standardDrinks;
Button bacIntent, maps, drinks;
TextView display;
Bundle testBundle;
@Override
protected void onCreate(Bundle testBundle) {
    super.onCreate(testBundle);
    setContentView(R.layout.activity_starting_point);
    counter = 0;
    bacIntent = (Button) findViewById(R.id.bacIntent);
    maps = (Button) findViewById(R.id.Maps);
    drinks = (Button) findViewById(R.id.drinks);


    bacIntent.setOnClickListener(new Button.OnClickListener(){
        @Override
        public void onClick(View v){


            try{
                Intent openBac = new Intent("com.schweigert.drinkingbuddy.BloodAlcoholContent");
                startActivity(openBac);
            }
            catch(Exception e)
            {
                display.setText("my d" + e);
            }
            }



    });

    maps.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try{
                Intent openMap = new Intent("com.schweigert.drinkingbuddy.MainActivity");
                startActivity(openMap);
            }
            catch(Exception e){
                display.setText("my d"+ e);
            }
        }

    });

    drinks.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try{
                Intent openDrinkMenu = new Intent("com.schweigert.drinkingbuddy.DrinkType");
                startActivity(openDrinkMenu);
            }
            catch(Exception e){
                display.setText("my d:" + e);
            }
        }

    });


}
}

1 个答案:

答案 0 :(得分:0)

所以我尝试了一个与不再存在的textview进行交互的catch,然后我的清单设置不正确。感谢Shivan的帮助。