0

我正在开发一个我已经在 Android 版本 4.2.2 和 4.3 上成功测试过的 Android 应用程序,但由于该应用程序还需要广泛的兼容性,我还尝试使用 Gingerbread 2.3.6 对其进行测试,但它崩溃了。使用的库是 android-support-v4 和 v7 应用程序 tomcat 以及 google-play-services。

这是显示的 logcat 日志:

11-04 10:20:54.736: W/dalvikvm(17136): Link of class 'Ldk/thesweetapps/vejviseraktivgravid/MainActivity;' failed
11-04 10:20:54.736: E/dalvikvm(17136): Could not find class 'dk.thesweetapps.vejviseraktivgravid.MainActivity', referenced from method dk.thesweetapps.vejviseraktivgravid.SplashScreen$1.run
11-04 10:20:54.736: W/dalvikvm(17136): VFY: unable to resolve const-class 1319 (Ldk/thesweetapps/vejviseraktivgravid/MainActivity;) in Ldk/thesweetapps/vejviseraktivgravid/SplashScreen$1;
11-04 10:20:54.736: D/dalvikvm(17136): VFY: replacing opcode 0x1c at 0x0004
11-04 10:20:54.736: D/dalvikvm(17136): VFY: dead code 0x0006-0013 in Ldk/thesweetapps/vejviseraktivgravid/SplashScreen$1;.run ()V
11-04 10:20:56.740: W/dalvikvm(17136): threadid=1: thread exiting with uncaught exception (group=0x40015578)
11-04 10:20:56.748: E/AndroidRuntime(17136): FATAL EXCEPTION: main
11-04 10:20:56.748: E/AndroidRuntime(17136): java.lang.NoClassDefFoundError: dk.thesweetapps.vejviseraktivgravid.MainActivity
11-04 10:20:56.748: E/AndroidRuntime(17136):    at dk.thesweetapps.vejviseraktivgravid.SplashScreen$1.run(SplashScreen.java:26)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at android.os.Handler.handleCallback(Handler.java:587)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at android.os.Looper.loop(Looper.java:130)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at java.lang.reflect.Method.invokeNative(Native Method)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at java.lang.reflect.Method.invoke(Method.java:507)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-04 10:20:56.748: E/AndroidRuntime(17136):    at dalvik.system.NativeStart.main(Native Method)
11-04 10:26:01.459: I/Process(17136): Sending signal. PID: 17136 SIG: 9
11-04 10:27:39.236: W/dalvikvm(17338): threadid=1: thread exiting with uncaught exception (group=0x40015578)
11-04 10:27:39.248: E/AndroidRuntime(17338): FATAL EXCEPTION: main
11-04 10:27:39.248: E/AndroidRuntime(17338): java.lang.NoClassDefFoundError: dk.thesweetapps.vejviseraktivgravid.MainActivity
11-04 10:27:39.248: E/AndroidRuntime(17338):    at dk.thesweetapps.vejviseraktivgravid.SplashScreen$1.run(SplashScreen.java:26)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at android.os.Handler.handleCallback(Handler.java:587)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at android.os.Looper.loop(Looper.java:130)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at java.lang.reflect.Method.invokeNative(Native Method)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at java.lang.reflect.Method.invoke(Method.java:507)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-04 10:27:39.248: E/AndroidRuntime(17338):    at dalvik.system.NativeStart.main(Native Method)
11-04 10:32:42.724: I/Process(17338): Sending signal. PID: 17338 SIG: 9
11-04 10:36:34.705: D/dalvikvm(17486): GC_EXTERNAL_ALLOC freed 56K, 48% free 2838K/5379K, external 1596K/2108K, paused 22ms
11-04 10:36:34.771: I/dalvikvm(17486): Failed resolving Ldk/thesweetapps/vejviseraktivgravid/MainActivity; interface 12 'Landroid/app/ActionBar$TabListener;'
11-04 10:36:34.771: W/dalvikvm(17486): Link of class 'Ldk/thesweetapps/vejviseraktivgravid/MainActivity;' failed
11-04 10:36:34.771: E/dalvikvm(17486): Could not find class 'dk.thesweetapps.vejviseraktivgravid.MainActivity', referenced from method dk.thesweetapps.vejviseraktivgravid.SplashScreen$1.run
11-04 10:36:34.771: W/dalvikvm(17486): VFY: unable to resolve const-class 1319 (Ldk/thesweetapps/vejviseraktivgravid/MainActivity;) in Ldk/thesweetapps/vejviseraktivgravid/SplashScreen$1;
11-04 10:36:34.771: D/dalvikvm(17486): VFY: replacing opcode 0x1c at 0x0004
11-04 10:36:34.771: D/dalvikvm(17486): VFY: dead code 0x0006-0013 in Ldk/thesweetapps/vejviseraktivgravid/SplashScreen$1;.run ()V
11-04 10:36:36.775: W/dalvikvm(17486): threadid=1: thread exiting with uncaught exception (group=0x40015578)
11-04 10:36:36.783: E/AndroidRuntime(17486): FATAL EXCEPTION: main
11-04 10:36:36.783: E/AndroidRuntime(17486): java.lang.NoClassDefFoundError: dk.thesweetapps.vejviseraktivgravid.MainActivity
11-04 10:36:36.783: E/AndroidRuntime(17486):    at dk.thesweetapps.vejviseraktivgravid.SplashScreen$1.run(SplashScreen.java:26)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at android.os.Handler.handleCallback(Handler.java:587)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at android.os.Looper.loop(Looper.java:130)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at java.lang.reflect.Method.invokeNative(Native Method)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at java.lang.reflect.Method.invoke(Method.java:507)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-04 10:36:36.783: E/AndroidRuntime(17486):    at dalvik.system.NativeStart.main(Native Method)

MainActivity.java:

import java.util.Calendar;


import android.app.ActionBar;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import dk.thesweetapps.vejviseraktivgravid.Preferences.SettingsActivity;


public class MainActivity extends FragmentActivity implements ActionBar.TabListener {

    AppSectionsPagerAdapter pagerAdapter;
    public static final String tag = "thesweetapps";
    ViewPager viewPager;
    String timeForReminderPreference;
    SharedPreferences sharedPreferences;

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

        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        timeForReminderPreference = sharedPreferences.getString("time_for_reminder", "15:00");
        //It returns the pages/tabs
        SetTabBar();
        SetNotifications();
    }


    private void SetNotifications() {

        Log.e(tag, "inside setNotification");
        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
        Intent myIntent = new Intent(this , Notification.class);  
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);


        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, getHour(timeForReminderPreference));
        calendar.set(Calendar.MINUTE, getMinute(timeForReminderPreference));
        calendar.set(Calendar.SECOND, 00);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
        alarmManager.cancel(pendingIntent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        String changedForReminderPreference = sharedPreferences
                .getString("time_for_reminder", "15:00");
        if(timeForReminderPreference != changedForReminderPreference ){
             timeForReminderPreference = changedForReminderPreference;
             SetNotifications();
        }
    }

    private void SetTabBar() {
        pagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());


        //setting the actionbar
        final ActionBar actionBar = getActionBar();

        Log.d(tag, "setting actionbar");
        //actionBar.setSelectedNavigationItem(1);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        //setting the viewPager
        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(pagerAdapter);
        viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });
        Log.d(tag, "setting viewPager");

        //adding pages to actionbar
        for(int i = 0; i<pagerAdapter.getCount(); i++){
            actionBar.addTab(actionBar.newTab()
                    .setText(pagerAdapter.getPageTitle(i))
                    .setTabListener(this).setIcon(pagerAdapter.getIcon(i)));
        }
        Log.d(tag, "added tabs");
        viewPager.setCurrentItem(1);


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.e(tag, "inside opOptionsItemSelected: "+item.getItemId());
         switch (item.getItemId()) {
            case R.id.action_settings:
                open();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private void open() {
        Log.e(tag, "inside open settings");
        //getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_activity_actions, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction arg1) {
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction arg1) {
        viewPager.setCurrentItem(tab.getPosition());    
    }

    @Override

public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction arg1) {
}

public static int getHour(String time) {
    String[] pieces = time.split(":");

    return (Integer.parseInt(pieces[0]));
}

public static int getMinute(String time) {
    String[] pieces = time.split(":");
    return (Integer.parseInt(pieces[1]));
}

}

闪屏.java

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 2000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}

AndroidManifext.xml

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="18" />

    <!--map xml starts here-->
     <permission
        android:name="dk.thesweetapps.vejviseraktivgravid.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

     <!--  Android API uses OpenGL ES version 2 to render the map. 
     If OpenGL ES version 2 is not installed, your map will not appear -->
     <uses-feature
        android:glEsVersion="0x00020000" 
        android:required="true" />

      <uses-permission android:name="dk.thesweetapps.vejviseraktivgravid.permission.MAPS_RECEIVE" />
      <!-- Used by the API to download map tiles from Google Maps servers. -->
      <uses-permission android:name="android.permission.INTERNET" />
      <!-- External storage for caching. -->
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
      <!-- Allows the API to access Google web-based services. -->
      <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
      <!-- Allows the API to use WiFi or mobile cell data (or both) to determine the device's location. -->
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <!-- Allows the API to use the Global Positioning System (GPS) to determine the device's location to within a very small area.  -->
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

      <!-- map xml ends here -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppBaseTheme" >

         <!-- Specific key for every android app you need to get from 
         https://code.google.com/apis/console left at the API acess bar-->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
             android:value="AIzaSyDrqs5I0mXD7lx_excAQJQT-a7DNbhAu0Q" />

        <activity
            android:name="dk.thesweetapps.vejviseraktivgravid.SplashScreen"
            android:label="@string/app_name">
            android:theme="@android:style/Theme.Holo.Light.NoActionBar">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <activity android:name="dk.thesweetapps.vejviseraktivgravid.MainActivity"
            android:label="@string/app_name"></activity>

        <activity android:label="Personlig indstilling"
            android:name="dk.thesweetapps.vejviseraktivgravid.Preferences.SettingsActivity"></activity>
        <receiver android:name="dk.thesweetapps.vejviseraktivgravid.Notification"></receiver>


    </application>

</manifest>

任何帮助都感激不尽。:)

4

0 回答 0