获取android.view.InflateException:二进制XML文件行#20:错误膨胀类片段

时间:2013-05-28 03:52:16

标签: android

您好我是新手,我正在编写一个包含4个标签和V2 Google Map的应用。我的代码显示没有错误,但我收到了LogCat:

05-16 07:02:52.558: W/dalvikvm(2395): Unable to resolve superclass of Lcom/rmcsos/rmcsosapp/VendorMapActivity; (15) 
05-16 07:02:52.598: W/dalvikvm(2395): Link of class   com/rmcsos/rmcsosapp/VendorMapActivity;' failed 
05-16 07:02:52.598: E/dalvikvm(2395): Could not find class  com.rmcsos.rmcsosapp.VendorMapActivity', referenced from method   
com.rmcsos.rmcsosapp.MainActivity.onCreate 
05-16 07:02:52.618:       W/dalvikvm(2395): VFY: unable to resolve const-class 52   
(Lcom/rmcsos/rmcsosapp/VendorMapActivity;) in   Lcom/rmcsos/rmcsosapp/MainActivity; 
05-16 07:02:52.618:   D/dalvikvm(2395): VFY: replacing opcode 0x1c at 0x0084 05-16   
07:02:52.908: D/dalvikvm(2395): GC_FOR_ALLOC freed 65K, 3% free   
9891K/10179K, paused 71ms 05-16 07:02:52.918: I/dalvikvm-heap(2395): 
Grow heap (frag case) to 10.329MB for 614416-byte allocation 05-16   
07:02:53.099: D/dalvikvm(2395): GC_CONCURRENT freed <1K, 4% free   
10490K/10823K, paused 14ms+16ms 05-16 07:02:53.398:   
D/AndroidRuntime(2395): Shutting down VM 05-16 07:02:53.398:   
W/dalvikvm(2395): threadid=1: thread exiting with uncaught exception 
(group=0x409961f8) 05-16 07:02:53.458: E/AndroidRuntime(2395): FATAL 
EXCEPTION: main 05-16 07:02:53.458: E/AndroidRuntime(2395):   
java.lang.RuntimeException: Unable to start activity   
ComponentInfo{com.example.androidtablayout/com.rmcsos.rmcsosapp.MainActivity}:
android.view.InflateException: Binary XML file line #20: Error   
inflating class fragment 05-16 07:02:53.458: E/AndroidRuntime(2395):
    at    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.app.ActivityThread.access$600(ActivityThread.java:122) 05-16 
07:02:53.458: E/AndroidRuntime(2395):   at   
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146) 
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.os.Handler.dispatchMessage(Handler.java:99) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.os.Looper.loop(Looper.java:137) 05-16 07:02:53.458:   
E/AndroidRuntime(2395):     at   
android.app.ActivityThread.main(ActivityThread.java:4340) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
java.lang.reflect.Method.invokeNative(Native Method) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
java.lang.reflect.Method.invoke(Method.java:511) 05-16 07:02:53.458: 
E/AndroidRuntime(2395):     at   
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
dalvik.system.NativeStart.main(Native Method) 05-16 07:02:53.458:   
E/AndroidRuntime(2395): Caused by: android.view.InflateException:   
Binary XML file line #20: Error inflating class fragment 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 05-16  
07:02:53.458: E/AndroidRuntime(2395):   at   
android.view.LayoutInflater.rInflate(LayoutInflater.java:742) 05-16  
07:02:53.458: E/AndroidRuntime(2395):   at   
android.view.LayoutInflater.inflate(LayoutInflater.java:489) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.view.LayoutInflater.inflate(LayoutInflater.java:396) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.view.LayoutInflater.inflate(LayoutInflater.java:352) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.app.Activity.setContentView(Activity.java:1835) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
com.rmcsos.rmcsosapp.MainActivity.onCreate(MainActivity.java:16)   
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.app.Activity.performCreate(Activity.java:4465) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-16 07:02:53.458: E/AndroidRuntime(2395):     at   
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
05-16 07:02:53.458: E/AndroidRuntime(2395):     ... 11 more 05-16   
07:02:53.458: E/AndroidRuntime(2395): Caused by:   
java.lang.NullPointerException: name == null 05-16 07:02:53.458:   
E/AndroidRuntime(2395):     at   
java.lang.VMClassLoader.findLoadedClass(Native Method) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
java.lang.ClassLoader.findLoadedClass(ClassLoader.java:354) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
java.lang.ClassLoader.loadClass(ClassLoader.java:491) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
java.lang.ClassLoader.loadClass(ClassLoader.java:461) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.app.Fragment.instantiate(Fragment.java:562) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.app.Fragment.instantiate(Fragment.java:540) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.app.Activity.onCreateView(Activity.java:4235) 05-16   
07:02:53.458: E/AndroidRuntime(2395):   at   
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
05-16 07:02:53.458: E/AndroidRuntime(2395):     ... 22 more 05-16   
07:07:53.868: I/Process(2395): Sending signal. PID: 2395 SIG: 9 

这是我的Main_Activity.java文件:

package com.rmcsos.rmcsosapp;
      public class MainActivity extends TabActivity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          TabHost tabHost = getTabHost();

          TabSpec reviews_spec = tabHost.newTabSpec("");
          reviews_spec.setIndicator("", getResources().getDrawable(R.drawable.reviews));
          Intent reviews_Intent = new Intent(this, ReviewsActivity.class);
          reviews_spec.setContent(reviews_Intent);

          TabSpec myaccount_spec = tabHost.newTabSpec("");
          myaccount_spec.setIndicator("", getResources().getDrawable(R.drawable.myaccount));
          Intent myaccount_Intent = new Intent(this, MyAccountActivity.class);
          myaccount_spec.setContent(myaccount_Intent);

          // Tab for Settings
          TabSpec settings_spec = tabHost.newTabSpec("");
          settings_spec.setIndicator("", getResources().getDrawable(R.drawable.settings));
          Intent settings_Intent = new Intent(this, SettingsActivity.class);
          settings_spec.setContent(settings_Intent);

          //Tab for Maps
          TabSpec map_spec = tabHost.newTabSpec("");
          map_spec.setIndicator("",getResources().getDrawable(R.drawable.map));
          Intent map_Intent = new Intent(this, VendorMapActivity.class);
          map_spec.setContent(map_Intent);

          // Adding all TabSpec to TabHost
          tabHost.addTab(map_spec); //Adding map tab
          tabHost.addTab(reviews_spec); // Adding reviews tab
          tabHost.addTab(myaccount_spec); // Adding my_account tab
          tabHost.addTab(settings_spec); // Adding settings tab



      } }

这是我的Android Manifest:

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

    <uses-sdk android:minSdkVersion="11"
        android:targetSdkVersion="17"/>
    <permission
    android:name="com.arthur.sos.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />


    <uses-permission android:name="com.arthur.sos.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:icon="@drawable/rmcsos" android:label="@string/app_name" android:allowBackup="true">
        <uses-library android:name="com.google.android.maps"/>
        <activity android:name="com.rmcsos.rmcsosapp.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>

        <!--  My Account Activity -->
        <activity android:name="com.rmcsos.rmcsosapp.MyAccountActivity" />

        <!--  Settings Activity -->
        <activity android:name="com.rmcsos.rmcsosapp.SettingsActivity" />

        <!--  Reviews Activity -->
        <activity android:name="com.rmcsos.rmcsosapp.ReviewsActivity" />
        <!-- Map Activity -->
        <activity android:name="com.rmcsos.rmcsosapp.VendorMapActivity"/>

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

    </application>
</manifest>

这是我的VendorMapActivity.java,这是地图的位置:

package com.rmcsos.rmcsosapp;
public class VendorMapActivity extends FragmentActivity {
      static final LatLng Whittier = new LatLng(33.9417909, -117.9861795);
      private GoogleMap map;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();

        @SuppressWarnings("unused")
        Marker W1 = map.addMarker(new MarkerOptions().position(Whittier).title("Whittier").snippet("Re/Max").icon(BitmapDescriptorFactory.
                fromResource(R.drawable.rmcsos)));
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(Whittier, 15));

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

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
          return null;
      }
        return (LinearLayout)inflater.inflate(R.layout.maps, container, false);
    }   
}

这是地图片段的XML:

<?xml version="1.0" encoding="utf-8"?>
<!-- Please note when ready for production, you may wan to change "fill_parent" to: "match_parent"-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

      <!-- Screen Design for the map -->
  <TextView android:text="@string/maptext"
            android:padding="15dip"
            android:textSize="18sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
      <fragment
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="com.google.android.gms.maps.MapFragment" />

</LinearLayout>

任何帮助都是欣赏它,我是一个新手,我正在努力去理解。谢谢!!!

0 个答案:

没有答案