不幸的是app停了?

时间:2013-02-27 20:13:43

标签: android

我已经通过了很多例子,但仍然无法找到解决方案。 我是Android开发的新手,所以我在网上关注基本教程。 我按照谷歌地图v2 android教程

mainActivity.java

 package com.example.midlandtest;

 import android.app.Activity;
 import android.os.Bundle;
 import android.view.Menu;
 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.Marker;
 import com.google.android.gms.maps.model.MarkerOptions;

 public class MainActivity extends Activity {
 static final LatLng HAMBURG = new LatLng(53.558, 9.927);
 static final LatLng KIEL = new LatLng(53.551, 9.993);
 private GoogleMap map;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
 Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
    .title("Hamburg"));
 Marker kiel = map.addMarker(new MarkerOptions()
    .position(KIEL)
    .title("kiel")
    .snippet("Kiel is cool")
    .icon(BitmapDescriptorFactory
        .fromResource(R.drawable.ic_launcher)));

  // Move the camera instantly to hamburg with a zoom of 15.
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

  // Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
}

} 

main.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"
tools:context=".MainActivity" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />

 </RelativeLayout>  

清单

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

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

<permission
    android:name="midlandtest.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

   <uses-permission android:name="midlandtest.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" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="midlandtest.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="removed my api key for privacy reasons" />
   </application>

  </manifest>

这是我的logcat日志。 请帮助。

02-27 20:11:26.448: D/AndroidRuntime(5858): Shutting down VM
02-27 20:11:26.458: W/dalvikvm(5858): threadid=1: thread exiting with uncaught exception (group=0x40a2a1f8)
02-27 20:11:26.458: E/AndroidRuntime(5858): FATAL EXCEPTION: main
02-27 20:11:26.458: E/AndroidRuntime(5858): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.midlandtest/midlandtest.MainActivity}: java.lang.ClassNotFoundException: midlandtest.MainActivity
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.os.Looper.loop(Looper.java:137)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at java.lang.reflect.Method.invokeNative(Native Method)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at java.lang.reflect.Method.invoke(Method.java:511)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at dalvik.system.NativeStart.main(Native Method)
02-27 20:11:26.458: E/AndroidRuntime(5858): Caused by: java.lang.ClassNotFoundException: midlandtest.MainActivity
02-27 20:11:26.458: E/AndroidRuntime(5858):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
02-27 20:11:26.458: E/AndroidRuntime(5858):     at    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
02-27 20:11:26.458: E/AndroidRuntime(5858):     ... 11 more
02-27 20:11:26.778: I/dalvikvm(5858): threadid=3: reacting to signal 3
02-27 20:11:26.778: I/dalvikvm(5858): Wrote stack traces to '/data/anr/traces.txt'
02-27 20:11:26.998: I/dalvikvm(5858): threadid=3: reacting to signal 3
02-27 20:11:26.998: I/dalvikvm(5858): Wrote stack traces to '/data/anr/traces.txt'

我使用运行4.0.4的Android平板电脑来测试应用程序。 我将应用程序目标设置为google api 4.0.3,因为我被告知在不同的教程中使用它。 请帮帮我们,这让我发疯了

更新了LOGCAT LOG !!

02-27 20:44:28.847: W/dalvikvm(6614): VFY: unable to resolve static field 876 (MapAttrs) in Lcom/google/android/gms/R$styleable;
02-27 20:44:28.847: D/dalvikvm(6614): VFY: replacing opcode 0x62 at 0x000e
02-27 20:44:28.847: D/AndroidRuntime(6614): Shutting down VM
02-27 20:44:28.857: W/dalvikvm(6614): threadid=1: thread exiting with uncaught exception (group=0x40a2a1f8)
02-27 20:44:28.857: E/AndroidRuntime(6614): FATAL EXCEPTION: main
02-27 20:44:28.857: E/AndroidRuntime(6614): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
02-27 20:44:28.857: E/AndroidRuntime(6614):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.Activity.onCreateView(Activity.java:4269)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.Activity.setContentView(Activity.java:1862)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at com.example.midlandtest.MainActivity.onCreate(MainActivity.java:23)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.Activity.performCreate(Activity.java:4492)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.os.Looper.loop(Looper.java:137)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at java.lang.reflect.Method.invokeNative(Native Method)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at java.lang.reflect.Method.invoke(Method.java:511)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-27 20:44:28.857: E/AndroidRuntime(6614):     at dalvik.system.NativeStart.main(Native Method)
02-27 20:44:29.177: I/dalvikvm(6614): threadid=3: reacting to signal 3
02-27 20:44:29.177: I/dalvikvm(6614): Wrote stack traces to '/data/anr/traces.txt'
02-27 20:44:30.477: I/dalvikvm(6614): threadid=3: reacting to signal 3
02-27 20:44:30.487: I/dalvikvm(6614): Wrote stack traces to '/data/anr/traces.txt'
02-27 20:44:30.507: I/Process(6614): Sending signal. PID: 6614 SIG: 9
02-27 20:46:09.467: W/dalvikvm(6657): VFY: unable to resolve static field 876 (MapAttrs) in Lcom/google/android/gms/R$styleable;
02-27 20:46:09.467: D/dalvikvm(6657): VFY: replacing opcode 0x62 at 0x000e
02-27 20:46:09.477: D/AndroidRuntime(6657): Shutting down VM
02-27 20:46:09.477: W/dalvikvm(6657): threadid=1: thread exiting with uncaught exception (group=0x40a2a1f8)
 02-27 20:46:09.487: E/AndroidRuntime(6657): FATAL EXCEPTION: main
 02-27 20:46:09.487: E/AndroidRuntime(6657): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
02-27 20:46:09.487: E/AndroidRuntime(6657):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.Activity.onCreateView(Activity.java:4269)
 02-27 20:46:09.487: E/AndroidRuntime(6657):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.Activity.setContentView(Activity.java:1862)
 02-27 20:46:09.487: E/AndroidRuntime(6657):    at com.example.midlandtest.MainActivity.onCreate(MainActivity.java:23)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.Activity.performCreate(Activity.java:4492)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.os.Looper.loop(Looper.java:137)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at java.lang.reflect.Method.invokeNative(Native Method)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at java.lang.reflect.Method.invoke(Method.java:511)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-27 20:46:09.487: E/AndroidRuntime(6657):     at dalvik.system.NativeStart.main(Native Method)
02-27 20:46:09.787: I/dalvikvm(6657): threadid=3: reacting to signal 3
02-27 20:46:09.807: I/dalvikvm(6657): Wrote stack traces to '/data/anr/traces.txt'
02-27 20:46:10.107: I/dalvikvm(6657): threadid=3: reacting to signal 3
02-27 20:46:10.107: I/dalvikvm(6657): Wrote stack traces to '/data/anr/traces.txt'

1 个答案:

答案 0 :(得分:3)

变化:

<activity
    android:name="midlandtest.MainActivity"
    android:label="@string/app_name" >

<activity
    android:name="com.example.midlandtest.MainActivity"
    android:label="@string/app_name" >

您当前的代码告诉Android在名为MainActivity的程序包中查找midlandtest。但是,您的包名为com.example.midlandtest。这导致您获得ClassNotFoundException例外。