Android Application Crashing on Launch

2019-03-04 13:29发布

问题:

My android application crashes on launch on any device, there are no noticeable errors in the Code, can anyone help?

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);
            }
        });

 }
}

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>

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?

EDIT:

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)

Sorry is this the right way to format this, I'm new to stackoverflow

回答1:

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

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.