Android 应用程序在启动时崩溃 [英] Android Application Crashing on Launch
问题描述
我的 android 应用程序在任何设备上启动时崩溃,代码中没有明显的错误,有人可以帮忙吗?
My android application crashes on launch on any device, there are no noticeable errors in the Code, can anyone help?
这是 MainActivity.java
this is the MainActivity.java
package com.example.smartfood;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends ActionBarActivity {
ImageButton bAdd, bRemove, bEdit, bView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bAdd = (ImageButton) findViewById(R.id.bAdd);
bEdit = (ImageButton) findViewById(R.id.bEdit);
bRemove = (ImageButton) findViewById(R.id.bRemove);
bView = (ImageButton) findViewById(R.id.bView);
bAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, AddNew.class);
startActivity(i);
}
});
bRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Settings.class);
startActivity(i);
}
});
bEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, List.class);
startActivity(i);
}
});
bView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Menu.class);
startActivity(i);
}
});
}
}
这是activity_main.xml
This is activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:weightSum="2" >
<!-- 2 columns -->
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageButton
android:id="@+id/bAdd"
android:scaleType="fitXY"
android:background="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp"
android:src="@drawable/btn1" />
<ImageButton
android:id="@+id/bRemove"
android:scaleType="fitXY"
android:background="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp"
android:src="@drawable/btn2" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageButton
android:id="@+id/bEdit"
android:scaleType="fitXY"
android:background="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp"
android:src="@drawable/btn3" />
<ImageButton
android:id="@+id/bView"
android:scaleType="fitXY"
android:background="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp"
android:src="@drawable/btn4" />
</TableRow>
</TableLayout>
这是 AndroidManifest
This is the AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smartfood"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.smartfood.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>
<activity
android:name="com.example.smartfood.AddNew"
android:label="@string/app_name" />
<activity
android:name="com.example.smartfood.About"
android:label="@string/about" />
<activity
android:name="com.example.smartfood.List"
android:label="@string/List" >
</activity>
<activity
android:name="com.example.smartfood.Menu"
android:label="@string/Menu" >
</activity>
<activity
android:name="com.example.smartfood.Settings"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
如果有人可以帮助我,我将不胜感激?
If anyone could help I would really appreciate it?
这是我的 LogCat
This is my LogCat
11-26 23:15:40.627: W/asset(24889): Copying FileAsset 0x77c708f0 (zip:/data/app/com.example.smartfood-2.apk:/resources.arsc) to buffer size 4924 to make it aligned.
11-26 23:15:40.647: W/dalvikvm(24889): VFY: unable to resolve static field 1783 (Theme) in Landroid/support/v7/appcompat/R$styleable;
11-26 23:15:40.647: W/dalvikvm(24889): VFY: unable to resolve static field 1783 (Theme) in Landroid/support/v7/appcompat/R$styleable;
11-26 23:15:40.647: W/dalvikvm(24889): VFY: unable to resolve static field 1554 (panelMenuListTheme) in Landroid/support/v7/appcompat/R$attr;
11-26 23:15:40.647: W/dalvikvm(24889): VFY: unable to resolve static field 1539 (actionBarTheme) in Landroid/support/v7/appcompat/R$attr;
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve static method 3140: Landroid/support/v4/view/ViewConfigurationCompat;.hasPermanentMenuKey (Landroid/view/ViewConfiguration;)Z
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve static method 3140: Landroid/support/v4/view/ViewConfigurationCompat;.hasPermanentMenuKey (Landroid/view/ViewConfiguration;)Z
11-26 23:15:40.657: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.657: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.657: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve virtual method 6496: Landroid/support/v7/internal/widget/ActionBarContextView;.getLayoutParams ()Landroid/view/ViewGroup$LayoutParams;
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve static field 1539 (actionBarTheme) in Landroid/support/v7/appcompat/R$attr;
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve static field 1647 (abc_screen_simple_overlay_action_mode) in Landroid/support/v7/appcompat/R$layout;
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve static field 1646 (abc_screen_simple) in Landroid/support/v7/appcompat/R$layout;
11-26 23:15:40.657: W/dalvikvm(24889): VFY: unable to resolve static field 1552 (homeAsUpIndicator) in Landroid/support/v7/appcompat/R$attr;
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.667: E/dalvikvm(24889): Could not find class 'android.support.v7.internal.widget.ActionBarContextView', referenced from method android.support.v7.app.ActionBarActivityDelegateBase.startSupportActionModeFromWindow
11-26 23:15:40.667: W/dalvikvm(24889): VFY: unable to resolve new-instance 791 (Landroid/support/v7/internal/widget/ActionBarContextView;) in Landroid/support/v7/app/ActionBarActivityDelegateBase;
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.667: W/dalvikvm(24889): VFY: unable to resolve virtual method 6512: Landroid/support/v7/internal/widget/ActionBarContextView;.killMode ()V
11-26 23:15:40.667: W/dalvikvm(24889): VFY: unable to resolve static field 1611 (action_mode_bar_stub) in Landroid/support/v7/appcompat/R$id;
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/app/ActionBarActivityDelegateBase$2;' failed
11-26 23:15:40.667: W/dalvikvm(24889): Link of class 'Landroid/support/v7/internal/widget/ActionBarContextView;' failed
11-26 23:15:40.677: W/dalvikvm(24889): threadid=1: thread exiting with uncaught exception (group=0x416b7e30)
11-26 23:15:40.677: E/AndroidRuntime(24889): FATAL EXCEPTION: main
11-26 23:15:40.677: E/AndroidRuntime(24889): Process: com.example.smartfood, PID: 24889
11-26 23:15:40.677: E/AndroidRuntime(24889): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:147)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
11-26 23:15:40.677: E/AndroidRuntime(24889): at com.example.smartfood.MainActivity.onCreate(MainActivity.java:14)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.Activity.performCreate(Activity.java:5312)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.ActivityThread.access$800(ActivityThread.java:153)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.os.Handler.dispatchMessage(Handler.java:102)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.os.Looper.loop(Looper.java:157)
11-26 23:15:40.677: E/AndroidRuntime(24889): at android.app.ActivityThread.main(ActivityThread.java:5633)
11-26 23:15:40.677: E/AndroidRuntime(24889): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 23:15:40.677: E/AndroidRuntime(24889): at java.lang.reflect.Method.invoke(Method.java:515)
11-26 23:15:40.677: E/AndroidRuntime(24889): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
11-26 23:15:40.677: E/AndroidRuntime(24889): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
11-26 23:15:40.677: E/AndroidRuntime(24889): at dalvik.system.NativeStart.main(Native Method)
对不起,这是正确的格式化方式,我是stackoverflow的新手
Sorry is this the right way to format this, I'm new to stackoverflow
推荐答案
23:15:40.677: E/AndroidRuntime(24889): Process: com.example.smartfood, PID: 24889 11-26 23:15:40.677: E/AndroidRuntime(24889): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
您似乎没有正确地将 appcompat-v7
库添加到您的 Eclipse 项目中.按照说明添加库项目资源.
It would appear that you did not correctly add the appcompat-v7
library to your Eclipse project. Follow the instructions for adding a library project with resources.
这篇关于Android 应用程序在启动时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!