我在项目中创建的任何新类都会得到 NoClassDefFound

发布于 2024-11-07 05:31:52 字数 14623 浏览 0 评论 0原文

我有一个奇怪的问题。我的项目中有一个类,当我运行它时,它启动正常。我把这个类放在我的项目中(我有一些包和一些类),我把它放在AndroidManifest中,但是当我运行时我得到NoClassDefFound。我意识到我在项目中执行的任何新课程都会收到此错误。谁能帮助我吗?我不知道这个错误的任何解决方案..请帮助..

这是我的课程:

package com.ShoppingList;

import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;
import java.util.ArrayList;
import java.util.List;

public class ShopsOnMap extends MapActivity {
    private MapView map=null;
    private MyLocationOverlay me=null;

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

        map=(MapView)findViewById(R.id.map);

        map.getController().setCenter(getPoint
                (40.76793169992044,-173.98180484771729));
        map.getController().setZoom(17);
        map.setBuiltInZoomControls(true);

        Drawable marker=getResources().getDrawable(R.drawable.pushpin);

        marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                        marker.getIntrinsicHeight());

        map.getOverlays().add(new SitesOverlay(marker));

        me=new MyLocationOverlay(this, map);
        map.getOverlays().add(me);
    }

    @Override
    public void onResume() {
        super.onResume();

        me.enableCompass();
    }       

    @Override
    public void onPause() {
        super.onPause();

        me.disableCompass();
    }       

    @Override
    protected boolean isRouteDisplayed() {
        return(false);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_S) {
            map.setSatellite(!map.isSatellite());
            return(true);
        }
        else if (keyCode == KeyEvent.KEYCODE_Z) {
            map.displayZoomControls(true);
            return(true);
        }

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

    private GeoPoint getPoint(double lat, double lon) {
        return(new GeoPoint((int)(lat*1000000.0),
                            (int)(lon*1000000.0)));
    }

    private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items=new ArrayList<OverlayItem>();
        private Drawable marker=null;

        public SitesOverlay(Drawable marker) {
            super(marker);
            this.marker=marker;

            items.add(new OverlayItem(getPoint
                    (40.748963847316034,-173.96807193756104),
                                "UN", "United Nations"));
            items.add(new OverlayItem(getPoint
                    (40.76866299974387,-173.98268461227417),
                                "Lincoln Center",
                                "Home of Jazz at Lincoln Center"));
            items.add(new OverlayItem(getPoint
                    (40.765136435316755,-173.97989511489868),
                                "Carnegie Hall",
                        "Where you go with practice, practice, practice"));
            items.add(new OverlayItem(getPoint
                    (40.70686417491799,-174.01572942733765),
                                "The Downtown Club",
                        "Original home of the Heisman Trophy"));

            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
            return(items.get(i));
        }

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            super.draw(canvas, mapView, shadow);            
            boundCenterBottom(marker);
        }

        @Override
        protected boolean onTap(int i) {
            Toast.makeText(ShopsOnMap.this,
                                items.get(i).getSnippet(),
                                Toast.LENGTH_SHORT).show();

            return(true);
        }

        @Override
        public int size() {
            return(items.size());
        }
    }
}

在 Logcat 中我有:

05-14 13:10:24.755: ERROR/AndroidRuntime(368): java.lang.NoClassDefFoundError: com.ShoppingList.ShopsOnMap
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at com.ShoppingList.Lists.onCreate(Lists.java:122)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.os.Looper.loop(Looper.java:123)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at java.lang.reflect.Method.invoke(Method.java:521)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at dalvik.system.NativeStart.main(Native Method)
05-14 13:10:24.783: INFO/Process(52): Sending signal. PID: 368 SIG: 3
05-14 13:10:24.796: INFO/dalvikvm(368): threadid=7: reacting to signal 3
05-14 13:10:24.854: INFO/dalvikvm(368): Wrote stack trace to '/data/anr/traces.txt'
05-14 13:10:26.295: INFO/Process(368): Sending signal. PID: 368 SIG: 9
05-14 13:10:26.393: INFO/ActivityManager(52): Process com.ShoppingList (pid 368) has died.
05-14 13:10:26.444: INFO/WindowManager(52): WIN DEATH: Window{44e46860 com.ShoppingList/com.ShoppingList.Start paused=false}
05-14 13:10:26.444: INFO/WindowManager(52): WIN DEATH: Window{44e41618 AtchDlg:com.ShoppingList/com.ShoppingList.Start paused=false}
05-14 13:10:26.603: INFO/ActivityManager(52): Start proc com.ShoppingList for activity com.ShoppingList/.Start: pid=485 uid=10043 gids={3003}

AndroidManifest:

<uses-library android:name="com.google.android.maps" />     

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Start"
              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=".Lists"></activity>
<activity android:name=".NewList"></activity>
<activity android:name=".AddProduct"></activity>
<activity android:name=".Categoris"></activity>
<activity android:name=".EditProduct"></activity>

<activity android:name=".SimpleCalendar"></activity>
<activity android:name="com.ShoppingList.ProductsPredefine.NewProduct"></activity>
<activity android:name="com.ShoppingList.ProductsPredefine.Details"></activity>
<activity android:name="com.ShoppingList.Shops.Shops"></activity>
<activity android:name="com.ShoppingList.MapShow">
<activity android:name=".ShopsOnMap"></activity>
<intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

</activity>
<activity android:name="com.ShoppingList.Shops.SelectShop"></activity>

</application>

Lists.java:

package com.ShoppingList;

import com.ShoppingList.databases.ListDbAdapter;
import com.ShoppingList.databases.ShopDbAdapter;
import com.google.android.maps.GeoPoint;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;

public class Lists extends Activity {

private ListView lists;

private SimpleCursorAdapter adapter;
private Cursor cursor, c;
private ListDbAdapter db;
private ShopDbAdapter shop;
float[] results;
double latitudine;
double longitudine;
LocationManager lm;

private static final int NOTIFICATION_ID = 1;
private NotificationManager notificationManager;


private static final int NEW_LIST = Menu.FIRST;
private static final int DELETE_LIST = Menu.FIRST + 1;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lists);

    lists = (ListView) findViewById(R.id.list);

    db = new ListDbAdapter(this);
    db.open();

    shop = new ShopDbAdapter(this);
    shop.open();
    fillData();

    registerForContextMenu(lists);

    lists.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            Intent j = new Intent(Lists.this, AddProduct.class);
            Cursor c = (Cursor) parent.getAdapter().getItem(position);

            j.putExtra("titlelist", c.getString(c
                    .getColumnIndex(db.KEY_TITLE)));
            j.putExtra("idlist", c
                    .getString(c.getColumnIndex(db.KEY_ROWID)));
            startActivityForResult(j, 0);
        }
    });

    cursor = db.fetchAll();
    startManagingCursor(cursor);

    c = shop.fetchAll();
    startManagingCursor(c);
    cursor.moveToFirst();
    do {
        System.out.println("#####" + db.getShop(cursor) + "$$$$$$");
        c.moveToFirst();
        do {
            if (db.getShop(cursor) == shop.getName(c)) {
                latitudine = shop.getLatitudine(c);
                longitudine = shop.getLongitudine(c);
                System.out.println("%%%" + latitudine + "!!!!!");
                System.out.println("%%%" + longitudine + "!!!!!");
            } else
                c.moveToNext();
        } while (c.isLast());
        cursor.moveToNext();
    } while (cursor.isLast());

    latitudine = 46.7511187;
    longitudine = 23.5906539;
    results = new float[1];
    Location.distanceBetween(46.7547825, 23.5861364, latitudine,
            longitudine, results);
    System.out.println("%%%" + latitudine + "!!!!!");
    System.out.println("Distanta este" + results[0] + "!!!!!!!");
    if (results[0] < 800) {

        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        CharSequence NotificationTicket = "Notification";
        CharSequence NotificationTitle = "Notification";
        CharSequence NotificationContent = "Test";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(R.drawable.icon,
                NotificationTicket, when);

        Context context = getApplicationContext();

        Intent notificationIntent = new Intent(this,ShopsOnMap.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, 0);

        notification.setLatestEventInfo(context, NotificationTitle,
                NotificationContent, contentIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);

    }

}

public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, NEW_LIST, 0, "New List");// .setIcon(R.drawable.quit);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case NEW_LIST:
        createlist();
        return true;
    }
    return false;

}

public void createlist() {
    startActivityForResult(new Intent(Lists.this, NewList.class), 0);

}

public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    menu.add(0, DELETE_LIST, 0, "Delete List");
}

public boolean onContextItemSelected(MenuItem mitem) {

    switch (mitem.getItemId()) {

    case DELETE_LIST:
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) mitem
                .getMenuInfo();
        db.delete(info.id);
        fillData();
        return true;
    default:
        return super.onContextItemSelected(mitem);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    fillData();
}

private void fillData() {
    cursor = db.fetchAll();
    startManagingCursor(cursor);

    adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor,
            new String[] { ListDbAdapter.KEY_TITLE },
            new int[] { R.id.txt1 });
    lists.setAdapter(adapter);
}

}

更新:这是我的问题:

<uses-library android:name="com.google.android.maps" />

必须在

I have a strange problem. I have a single class in a project and when I run it,it starts ok. I put this class in my project( where I have some packages and some classes) ,I put it in AndroidManifest, but when I run I get NoClassDefFound. I realised that any new class I do in my project,I get this error. Can anyone help me? I don't know any solution for this error..Help,pls..

This is my class :

package com.ShoppingList;

import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;
import java.util.ArrayList;
import java.util.List;

public class ShopsOnMap extends MapActivity {
    private MapView map=null;
    private MyLocationOverlay me=null;

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

        map=(MapView)findViewById(R.id.map);

        map.getController().setCenter(getPoint
                (40.76793169992044,-173.98180484771729));
        map.getController().setZoom(17);
        map.setBuiltInZoomControls(true);

        Drawable marker=getResources().getDrawable(R.drawable.pushpin);

        marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                        marker.getIntrinsicHeight());

        map.getOverlays().add(new SitesOverlay(marker));

        me=new MyLocationOverlay(this, map);
        map.getOverlays().add(me);
    }

    @Override
    public void onResume() {
        super.onResume();

        me.enableCompass();
    }       

    @Override
    public void onPause() {
        super.onPause();

        me.disableCompass();
    }       

    @Override
    protected boolean isRouteDisplayed() {
        return(false);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_S) {
            map.setSatellite(!map.isSatellite());
            return(true);
        }
        else if (keyCode == KeyEvent.KEYCODE_Z) {
            map.displayZoomControls(true);
            return(true);
        }

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

    private GeoPoint getPoint(double lat, double lon) {
        return(new GeoPoint((int)(lat*1000000.0),
                            (int)(lon*1000000.0)));
    }

    private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
        private List<OverlayItem> items=new ArrayList<OverlayItem>();
        private Drawable marker=null;

        public SitesOverlay(Drawable marker) {
            super(marker);
            this.marker=marker;

            items.add(new OverlayItem(getPoint
                    (40.748963847316034,-173.96807193756104),
                                "UN", "United Nations"));
            items.add(new OverlayItem(getPoint
                    (40.76866299974387,-173.98268461227417),
                                "Lincoln Center",
                                "Home of Jazz at Lincoln Center"));
            items.add(new OverlayItem(getPoint
                    (40.765136435316755,-173.97989511489868),
                                "Carnegie Hall",
                        "Where you go with practice, practice, practice"));
            items.add(new OverlayItem(getPoint
                    (40.70686417491799,-174.01572942733765),
                                "The Downtown Club",
                        "Original home of the Heisman Trophy"));

            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
            return(items.get(i));
        }

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            super.draw(canvas, mapView, shadow);            
            boundCenterBottom(marker);
        }

        @Override
        protected boolean onTap(int i) {
            Toast.makeText(ShopsOnMap.this,
                                items.get(i).getSnippet(),
                                Toast.LENGTH_SHORT).show();

            return(true);
        }

        @Override
        public int size() {
            return(items.size());
        }
    }
}

And in Logcat I have :

05-14 13:10:24.755: ERROR/AndroidRuntime(368): java.lang.NoClassDefFoundError: com.ShoppingList.ShopsOnMap
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at com.ShoppingList.Lists.onCreate(Lists.java:122)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.os.Looper.loop(Looper.java:123)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at java.lang.reflect.Method.invoke(Method.java:521)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-14 13:10:24.755: ERROR/AndroidRuntime(368):     at dalvik.system.NativeStart.main(Native Method)
05-14 13:10:24.783: INFO/Process(52): Sending signal. PID: 368 SIG: 3
05-14 13:10:24.796: INFO/dalvikvm(368): threadid=7: reacting to signal 3
05-14 13:10:24.854: INFO/dalvikvm(368): Wrote stack trace to '/data/anr/traces.txt'
05-14 13:10:26.295: INFO/Process(368): Sending signal. PID: 368 SIG: 9
05-14 13:10:26.393: INFO/ActivityManager(52): Process com.ShoppingList (pid 368) has died.
05-14 13:10:26.444: INFO/WindowManager(52): WIN DEATH: Window{44e46860 com.ShoppingList/com.ShoppingList.Start paused=false}
05-14 13:10:26.444: INFO/WindowManager(52): WIN DEATH: Window{44e41618 AtchDlg:com.ShoppingList/com.ShoppingList.Start paused=false}
05-14 13:10:26.603: INFO/ActivityManager(52): Start proc com.ShoppingList for activity com.ShoppingList/.Start: pid=485 uid=10043 gids={3003}

AndroidManifest :

<uses-library android:name="com.google.android.maps" />     

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Start"
              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=".Lists"></activity>
<activity android:name=".NewList"></activity>
<activity android:name=".AddProduct"></activity>
<activity android:name=".Categoris"></activity>
<activity android:name=".EditProduct"></activity>

<activity android:name=".SimpleCalendar"></activity>
<activity android:name="com.ShoppingList.ProductsPredefine.NewProduct"></activity>
<activity android:name="com.ShoppingList.ProductsPredefine.Details"></activity>
<activity android:name="com.ShoppingList.Shops.Shops"></activity>
<activity android:name="com.ShoppingList.MapShow">
<activity android:name=".ShopsOnMap"></activity>
<intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

</activity>
<activity android:name="com.ShoppingList.Shops.SelectShop"></activity>

</application>

Lists.java :

package com.ShoppingList;

import com.ShoppingList.databases.ListDbAdapter;
import com.ShoppingList.databases.ShopDbAdapter;
import com.google.android.maps.GeoPoint;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;

public class Lists extends Activity {

private ListView lists;

private SimpleCursorAdapter adapter;
private Cursor cursor, c;
private ListDbAdapter db;
private ShopDbAdapter shop;
float[] results;
double latitudine;
double longitudine;
LocationManager lm;

private static final int NOTIFICATION_ID = 1;
private NotificationManager notificationManager;


private static final int NEW_LIST = Menu.FIRST;
private static final int DELETE_LIST = Menu.FIRST + 1;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lists);

    lists = (ListView) findViewById(R.id.list);

    db = new ListDbAdapter(this);
    db.open();

    shop = new ShopDbAdapter(this);
    shop.open();
    fillData();

    registerForContextMenu(lists);

    lists.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            Intent j = new Intent(Lists.this, AddProduct.class);
            Cursor c = (Cursor) parent.getAdapter().getItem(position);

            j.putExtra("titlelist", c.getString(c
                    .getColumnIndex(db.KEY_TITLE)));
            j.putExtra("idlist", c
                    .getString(c.getColumnIndex(db.KEY_ROWID)));
            startActivityForResult(j, 0);
        }
    });

    cursor = db.fetchAll();
    startManagingCursor(cursor);

    c = shop.fetchAll();
    startManagingCursor(c);
    cursor.moveToFirst();
    do {
        System.out.println("#####" + db.getShop(cursor) + "$$$");
        c.moveToFirst();
        do {
            if (db.getShop(cursor) == shop.getName(c)) {
                latitudine = shop.getLatitudine(c);
                longitudine = shop.getLongitudine(c);
                System.out.println("%%%" + latitudine + "!!!!!");
                System.out.println("%%%" + longitudine + "!!!!!");
            } else
                c.moveToNext();
        } while (c.isLast());
        cursor.moveToNext();
    } while (cursor.isLast());

    latitudine = 46.7511187;
    longitudine = 23.5906539;
    results = new float[1];
    Location.distanceBetween(46.7547825, 23.5861364, latitudine,
            longitudine, results);
    System.out.println("%%%" + latitudine + "!!!!!");
    System.out.println("Distanta este" + results[0] + "!!!!!!!");
    if (results[0] < 800) {

        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        CharSequence NotificationTicket = "Notification";
        CharSequence NotificationTitle = "Notification";
        CharSequence NotificationContent = "Test";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(R.drawable.icon,
                NotificationTicket, when);

        Context context = getApplicationContext();

        Intent notificationIntent = new Intent(this,ShopsOnMap.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, 0);

        notification.setLatestEventInfo(context, NotificationTitle,
                NotificationContent, contentIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);

    }

}

public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, NEW_LIST, 0, "New List");// .setIcon(R.drawable.quit);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case NEW_LIST:
        createlist();
        return true;
    }
    return false;

}

public void createlist() {
    startActivityForResult(new Intent(Lists.this, NewList.class), 0);

}

public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    menu.add(0, DELETE_LIST, 0, "Delete List");
}

public boolean onContextItemSelected(MenuItem mitem) {

    switch (mitem.getItemId()) {

    case DELETE_LIST:
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) mitem
                .getMenuInfo();
        db.delete(info.id);
        fillData();
        return true;
    default:
        return super.onContextItemSelected(mitem);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    fillData();
}

private void fillData() {
    cursor = db.fetchAll();
    startManagingCursor(cursor);

    adapter = new SimpleCursorAdapter(this, R.layout.listview, cursor,
            new String[] { ListDbAdapter.KEY_TITLE },
            new int[] { R.id.txt1 });
    lists.setAdapter(adapter);
}

}

UPDATE: Here was my problem :

<uses-library android:name="com.google.android.maps" />

must be within <application> </application>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱冒险 2024-11-14 05:31:52

首先检查堆栈跟踪。听起来它好像在抱怨新班级以外的事情。

Start out by checking your stack trace. It sounds like it's complaining about something other than your new class.

幽蝶幻影 2024-11-14 05:31:52

确保您的清单已在 标记中声明了该包

<manifest package="com.ShoppingList" . . . >

Make sure that your Manifest has declared the package in the <manifest> tag

<manifest package="com.ShoppingList" . . . >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文