我正在开发一个显示以下log cat结果的应用程序..它提到了一个二进制xml文件..问题是我的系统中没有这样的名称的文件...所以这是提到的文件在日志猫???
06-04 07:05:29.080: E/AndroidRuntime(791): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thomas/com.quinoid.thomas.Home}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.os.Handler.dispatchMessage(Handler.java:102)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.os.Looper.loop(Looper.java:136)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-04 07:05:29.080: E/AndroidRuntime(791): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 07:05:29.080: E/AndroidRuntime(791): at java.lang.reflect.Method.invoke(Method.java:515)
06-04 07:05:29.080: E/AndroidRuntime(791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-04 07:05:29.080: E/AndroidRuntime(791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-04 07:05:29.080: E/AndroidRuntime(791): at dalvik.system.NativeStart.main(Native Method)
06-04 07:05:29.080: E/AndroidRuntime(791): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
06-04 07:05:29.080: E/AndroidRuntime(791): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-04 07:05:29.080: E/AndroidRuntime(791): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.Activity.setContentView(Activity.java:1929)
06-04 07:05:29.080: E/AndroidRuntime(791): at com.quinoid.thomas.Home.onCreate(Home.java:12)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.Activity.performCreate(Activity.java:5231)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-04 07:05:29.080: E/AndroidRuntime(791): ... 11 more
06-04 07:05:29.080: E/AndroidRuntime(791): Caused by: java.lang.reflect.InvocationTargetException
06-04 07:05:29.080: E/AndroidRuntime(791): at java.lang.reflect.Constructor.constructNative(Native Method)
06-04 07:05:29.080: E/AndroidRuntime(791): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
06-04 07:05:29.080: E/AndroidRuntime(791): ... 24 more
06-04 07:05:29.080: E/AndroidRuntime(791): Caused by: java.lang.OutOfMemoryError
06-04 07:05:29.080: E/AndroidRuntime(791): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.content.res.Resources.loadDrawable(Resources.java:2110)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.widget.ImageView.<init>(ImageView.java:129)
06-04 07:05:29.080: E/AndroidRuntime(791): at android.widget.ImageView.<init>(ImageView.java:119)
06-04 07:05:29.080: E/AndroidRuntime(791): ... 27 more
06-04 07:05:31.420: I/Process(791): Sending signal. PID: 791 SIG: 9
点击图片交换没有任何问题..点击没有发生..应用程序正在崩溃... 这是源代码:
public class HomePage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_page);
main();
}
@SuppressWarnings("unused")
private void main() {
// TODO Auto-generated method stub
final Button home;
final Button aboutus;
final Button contacts;
final Button clients;
final Button services;
try
{
home = (Button)findViewById(R.id.btnHome);
aboutus = (Button)findViewById(R.id.btnAboutus);
clients = (Button)findViewById(R.id.btnClients);
contacts = (Button)findViewById(R.id.btnContacts);
services = (Button)findViewById(R.id.btnServices);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
home.setBackgroundResource(R.drawable.home1);
Intent myIntent = new Intent(HomePage.this, Home.class);
startActivity(myIntent);
}
});
aboutus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
aboutus.setBackgroundResource(R.drawable.about1);
Intent myIntent = new Intent(HomePage.this, AboutUs.class);
startActivity(myIntent);
}
});
clients.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
clients.setBackgroundResource(R.drawable.clients1);
Intent myIntent = new Intent(HomePage.this, Clients.class);
startActivity(myIntent);
}
});
contacts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
contacts.setBackgroundResource(R.drawable.contacts1);
Intent myIntent = new Intent(HomePage.this, Contacts.class);
startActivity(myIntent);
}
});
services.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
services.setBackgroundResource(R.drawable.services1);
Intent myIntent = new Intent(HomePage.this, Services.class);
startActivity(myIntent);
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_page, menu);
return true;
}
}
布局文件......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/withoutlogo">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="206.38dp"
android:layout_height="340dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="35dp"
android:background="@drawable/arcrail" >
<Button
android:id="@+id/btnHome"
android:layout_width="108dp"
android:layout_height="36dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/home" />
<Button
android:id="@+id/btnContacts"
android:layout_width="108dp"
android:layout_height="36dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/contacts" />
</RelativeLayout>
<Button
android:id="@+id/btnServices"
android:layout_width="117dp"
android:layout_height="39dp"
android:layout_alignBottom="@+id/btnAboutus"
android:layout_alignLeft="@+id/btnAboutus"
android:layout_marginBottom="-80dp"
android:layout_marginLeft="-22.25dp"
android:background="@drawable/services" />
<Button
android:id="@+id/btnAboutus"
android:layout_width="117dp"
android:layout_height="39dp"
android:layout_above="@+id/relativeLayout1"
android:layout_alignLeft="@+id/relativeLayout1"
android:layout_marginBottom="-110dp"
android:layout_marginLeft="-75dp"
android:background="@drawable/about" />
<Button
android:id="@+id/btnClients"
android:layout_width="117dp"
android:layout_height="39dp"
android:layout_alignBottom="@+id/btnAboutus"
android:layout_alignLeft="@+id/btnAboutus"
android:layout_marginBottom="-160dp"
android:layout_marginLeft="-04dp"
android:background="@drawable/clients" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:layout_alignParentTop="true"
android:src="@drawable/header1" />
logcat on button press(我没有使用任何声音文件)
06-05 01:01:46.323: W/EGL_emulation(1191): eglSurfaceAttrib not implemented
06-05 01:01:54.283: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.283: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.283: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.283: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: E/SoundPool(382): error loading /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-05 01:01:54.293: E/SoundPool(382): error loading /system/media/audio/ui/KeypressStandard.ogg
06-05 01:01:54.293: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
06-05 01:01:54.303: E/SoundPool(382): error loading /system/media/audio/ui/KeypressSpacebar.ogg
06-05 01:01:54.303: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
06-05 01:01:54.303: E/SoundPool(382): error loading /system/media/audio/ui/KeypressDelete.ogg
06-05 01:01:54.303: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
06-05 01:01:54.303: E/SoundPool(382): error loading /system/media/audio/ui/KeypressReturn.ogg
06-05 01:01:54.303: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
06-05 01:01:54.303: E/SoundPool(382): error loading /system/media/audio/ui/KeypressInvalid.ogg
06-05 01:01:54.303: W/AudioService(382): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
06-05 01:01:54.303: W/AudioService(382): onLoadSoundEffects(), Error -1 while loading samples
06-05 01:01:54.323: I/ActivityManager(382): START u0 {cmp=com.example.thomas/com.quinoid.thomas.Services} from pid 1191
06-05 01:01:54.583: W/EGL_emulation(1191): eglSurfaceAttrib not implemented
06-05 01:01:57.033: I/ActivityManager(382): Displayed com.example.thomas/com.quinoid.thomas.Services: +2s658ms
答案 0 :(得分:0)
Caused by: java.lang.OutOfMemoryError
因为您用作充气机布局背景的图像尺寸较大(以MB为单位),这就是为什么它会让您出现内存错误,并且系统无法充气,这就是为什么您会得到膨胀例外。
just make that image in KB's and you will get out of this problem.
src to background of your imageview in your xml.
答案 1 :(得分:0)
如果您使用的是如此大的图像,则不应直接使图像渗透,而应使用BitmapFactory,然后在膨胀任何新图像之前释放先前的位图。
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap imageBitmap = null;
int tempWidth = -1;
int tempHeight = -1;
options.inSampleSize = 1;
//calculating sample size
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeFile(file.getAbsolutePath().toString(), options);
tempWidth = options.outWidth;
tempHeight = options.outHeight;
LogUtil.info(TAG, "tempWidth is " + tempWidth);
LogUtil.info(TAG, "tempHeight is " + tempHeight);
while (tempWidth > MAX_LIMIT_EDGE || tempHeight > MAX_LIMIT_EDGE)
{
options.inSampleSize *= 2;
tempWidth /= 2;
tempHeight /= 2;
}
}
catch (OutOfMemoryError e)
{
return null;
}
do
{
if (isOutOfMemoryOccured)
{
options.inSampleSize *= 2;
}
try
{
imageBitmap = BitmapFactory.decodeFile(file.getAbsolutePath().toString(), options);
isOutOfMemoryOccured = false;
}
catch (java.lang.OutOfMemoryError e)
{
LogUtil.info(TAG, "Out of memory occurred to sample size");
isOutOfMemoryOccured = true;
}
}while (isOutOfMemoryOccured);
然后返回位图并在任何地方使用infalte
之后,在通知新资源jst之前调用
bitmap.recycle();
答案 2 :(得分:0)
在应用程序标签下的清单中设置android:largeHeap =“true”。 Android默认允许16 MB运行应用程序,你可以将堆大小增加到24 MB。