我正在实施CalendarView
,我收到错误
02-12 11:18:39.792: E/Trace(6459): error opening trace file: No such file or directory
(2)02-12 11:19:29.251: E/dalvikvm-heap(6459): Out of memory on a 5242896-byte
allocation.02-12 11:19:30.041: E/AndroidRuntime(6459): FATAL EXCEPTION: main
02-12 11:19:30.041: E/AndroidRuntime(6459): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.docket/com.docket.NHome}: java.lang.RuntimeException: Unable
to start activity ComponentInfo{com.docket/com.docket.Home}:
android.view.InflateException: Binary XML file line #33: Error inflating class
android.widget.CalendarView
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.os.Handler.dispatchMessage(Handler.java:99)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.os.Looper.loop(Looper.java:137)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.main(ActivityThread.java:5041)
02-12 11:19:30.041: E/AndroidRuntime(6459): Caused by: java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.docket/com.docket.Home}:
android.view.InflateException: Binary XML file line #33: Error inflating class
android.widget.CalendarView
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.startActivityNow(ActivityThread.java:2023)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.Activity.setContentView(Activity.java:1881)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
com.docket.Home.onCreate(Home.java:23)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.Activity.performCreate(Activity.java:5104)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-12 11:19:30.041: E/AndroidRuntime(6459): ... 21 more
02-12 11:19:30.041: E/AndroidRuntime(6459): Caused by:
java.lang.reflect.InvocationTargetException
02-12 11:19:30.041: E/AndroidRuntime(6459): at
java.lang.reflect.Constructor.constructNative(Native Method)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-12 11:19:30.041: E/AndroidRuntime(6459): ... 38 more
02-12 11:19:30.041: E/AndroidRuntime(6459): Caused by: java.lang.OutOfMemoryError
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
我的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" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/Home"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/calender"
android:background="@drawable/cbg"
/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
任何人都可以帮我解决这个问题。
提前致谢。
答案 0 :(得分:1)
我尝试了相同的代码并且工作正常。您只需要将清单中的最低API级别更改为11.As CalendarView
支持设备上的API&gt; 11
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
答案 1 :(得分:1)
02-12 11:19:30.041: E/AndroidRuntime(6459): Caused by: java.lang.OutOfMemoryError
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
02-12 11:19:30.041: E/AndroidRuntime(6459): at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
内存解码位图资源。可能你设置为CalendarView
的背景可绘制太大了。将其替换为占用较少内存的较小分辨率图像。