10

首先,我知道有很多关于这个主题的问题/答案,我已经阅读了其中的大部分但仍然得到错误:

05-17 02:57:06.522: E/AndroidRuntime(17073): java.lang.NoClassDefFoundError: ar.com.package.android.MainActivity

在我将 Eclipse 从 21 更新到 22 之前,该项目运行良好。

我已尽我所能:我检查了清单;清理项目;检查了我的构建路径,尝试了不同 android 版本的应用程序,将 java 合规性级别设置为 1.6(也包括库)等等。我只是不知道问题出在哪里。

这是我的清单,我找不到任何问题:

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

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/> 

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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"/>

<permission
    android:name="ar.com.package.android.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="ar.com.package.android.permission.MAPS_RECEIVE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light.DarkActionBar" 
    android:hardwareAccelerated="true">


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


    <activity
        android:name="ar.com.package.android.SplashScreen"
        android:label="@string/app_name"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
        android:windowSoftInputMode="stateHidden"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="ar.com.package.android.MainActivity"
        android:logo="@drawable/logo"
        android:screenOrientation="portrait" 
        android:windowSoftInputMode="stateHidden"
         >
    </activity>

    <activity
        android:name="ar.com.package.android.SearchForm"
        android:label="@string/title_activity_search_form"
        android:parentActivityName="ar.com.package.android.MainActivity"
        >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ar.com.package.android.MainActivity" />
    </activity>

</application>

</manifest>

欢迎任何帮助。我会继续研究,如果我得到答案,我会发布它。

编辑

这是 MainActivity 代码:

package ar.com.package.android;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;
import com.actionbarsherlock.view.*;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnCloseListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenListener;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

@SuppressLint("NewApi")
public class MainActivity extends SlidingFragmentActivity {

private SlidingMenu menu;
private Toast toast;
private long lastBackPressTime = 0;
private GoogleMap map;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // slidemenu
    setBehindContentView(R.layout.menu);

    setSlidingActionBarEnabled(false);

    menu = getSlidingMenu();
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffset(100);
    menu.setFadeDegree(0.35f);
    menu.setSlidingEnabled(false);

    menu.setOnCloseListener(new OnCloseListener() {
        @Override
        public void onClose() {
            menu.setSlidingEnabled(false);
        }
    });

    menu.setOnOpenListener(new OnOpenListener() {
        @Override
        public void onOpen() {
            menu.setSlidingEnabled(true);
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    // ---slide menu

    map = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map)).getMap();

    // Getting Google Play availability status
    int status = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(getBaseContext());

    if (status != ConnectionResult.SUCCESS) {

        Toast.makeText(this, "Google Maps no esta disponible.",
                Toast.LENGTH_LONG).show();

    } else {


        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
                -26.8175915814614, -65.22274105834958), 13));

        // Enabling MyLocation Layer of Google Map
        map.setMyLocationEnabled(true);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getSupportMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        toggle();
        return true;

    case R.id.action_search:
        final int RESULT = 1;
        startActivityForResult(new Intent(MainActivity.this,
                SearchForm.class), RESULT);
        return true;

    case R.id.action_lineas:
        showDialogLineas();
        return true;

    case R.id.action_acercade:
        showDialogAcercaDe();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && !menu.isMenuShowing()) {

        if (this.lastBackPressTime < System.currentTimeMillis() - 4000) {
            toast = Toast.makeText(this,
                    "Presione Atrás nuevamente para cerrar",
                    Toast.LENGTH_LONG);
            toast.show();
            this.lastBackPressTime = System.currentTimeMillis();
        } else {
            if (toast != null) {
                toast.cancel();
            }
            super.onBackPressed();
        }

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

public void onResultadosClicked(View view) {
    showMenu();
}

public void showDialogLineas(){
    DialogFragment dialog = new LineasDialog();
    dialog.show(getSupportFragmentManager(), "Lineas");
}

public void showDialogAcercaDe(){
    DialogFragment dialog = new AcercaDeDialog();
    dialog.show(getSupportFragmentManager(), "Acerca");
}
}
4

1 回答 1

34

尝试转到Project -> Properties -> Java Build Path -> Order & Export并确保为您的项目和您正在使用的所有其他库项目检查Android Private Libraries 。

于 2013-05-17T07:43:29.903 回答