简体   繁体   English

Android 移动应用程序崩溃

[英]Android Mobile Application crashing

I am developing an app.我正在开发一个应用程序。 but some how i am getting an exception.但我如何得到一个例外。

Here is my logcat.这是我的 logcat。

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.project.mobileshoppingassistant/com.project.mobileshoppingassistant.indoor.MapViewActivity}; have you declared this activity in your AndroidManifest.xml?
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)
    at android.app.Activity.startActivityForResult(Activity.java:3446)
    at android.app.Activity.startActivityForResult(Activity.java:3407)
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
    at android.app.Activity.startActivity(Activity.java:3617)
    at android.app.Activity.startActivity(Activity.java:3585)
    at com.project.mobileshoppingassistant.activity.MainActivity.onClick(MainActivity.java:72)
    at android.view.View.performClick(View.java:4211)
    at android.view.View$PerformClick.run(View.java:17267)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4898)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
    at dalvik.system.NativeStart.main(Native Method)

1 1

Anyone can help me please ?任何人都可以帮助我吗?

My Manifest is found below it might be helpful to someone :我的清单在下面找到它可能对某人有帮助:

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

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name="com.project.mobileshoppingassistant.indoor.MapViewActivity"
            android:label="Indoor Location"
            android:screenOrientation="portrait">
        </activity>
        <activity
            android:name="com.project.mobileshoppingassistant.indoor.MapEditActivity"
            android:label="Indoor Location"
            android:screenOrientation="portrait">
        </activity>


    </application>

</manifest>

................................................................................ ............................................................................... ................................................................................. ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ...................................................................... ………………………………………………………………………………………………………………………………………………

This is my MapViewActivity code :这是我的 MapViewActivity 代码:

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.PointF;
import android.net.wifi.ScanResult;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.Fragment;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeSet;

public class MapViewActivity extends MapActivity {
    public final static String EXTRA_MESSAGE_FLOOR = "com.inte.indoorpositiontracker.FLOOR";

    private static final int MENU_ITEM_EDIT_MAP = 21;

    public static final int SCAN_DELAY = 1000; // delay for the first scan (milliseconds)
    public static final int SCAN_INTERVAL = 1000; // interval between scans (milliseconds)
    public static final int MAX_SCAN_THREADS = 2; // max amount of simultaneus scans

    private int mScanThreadCount = 0;

    //keys to save fingerPrint to sharedPereferences--start
    public static final String KEY_ID="fingerprint_id";
    public static final String KEY_MAP="fingerprint_map";
    public static final String KEY_POSITON_X="fingerprintX";
    public static final String KEY_POSITON_Y="fingerprintY";
    //end

    public static final String KEY_FINGERPRINT_MADE="hasFIngerPrintBeenMade";//used to check if
    // an average point has been calculated

    // UI pointer to visualize user where he is on the map
    private WifiPointView mLocationPointer;

    // handler for callbacks to the UI thread
    private static Handler sUpdateHandler = new Handler();

    // runnable to refresh map (called by the handler)
    private Runnable mRefreshMap = new Runnable() {
        public void run() {
            refreshMap();
        }
    };

    private boolean mPaused = false; // used to detect if the application is on map edit mode

    private HashMap<String, Integer> mMeasurements; // used to calculate weighted averages of signal strengths



    /** INSTANCE METHODS*/

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mMeasurements = new HashMap<String, Integer>();

        mLocationPointer = mMap.createNewWifiPointOnMap(new PointF(-1000, -1000));
        mLocationPointer.activate();

        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(KEY_FINGERPRINT_MADE,false))
        {
            mLocationPointer.setFingerprint(getSavedFingerprint());
        }

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                if(mPaused == false) { // start scan only when this activity is active
                    mWifi.startScan();
                }
            }

        }, SCAN_DELAY, SCAN_INTERVAL);
    }


    @Override
    public void onReceiveWifiScanResults(final List<ScanResult> results) {
        IndoorPositionTracker application = (IndoorPositionTracker) getApplication();
        final ArrayList<Fingerprint> fingerprints = application.getFingerprintData(mSelectedMap);

        // calculating the location might take some time in case there are a lot of fingerprints (>10000),
        // so it's reasonable to limit scan thread count to make sure there are not too many of these threads
        // going on at the same time
        if(results.size() > 0 && fingerprints.size() > 0 && mScanThreadCount <= MAX_SCAN_THREADS) {
            Thread t = new Thread() {
                public void run() {
                    mScanThreadCount++;

                    HashMap<String, Integer> measurements = new HashMap<String, Integer>();
                    for (ScanResult result : results) {
                        measurements.put(result.BSSID, result.level);
                    }

                    TreeSet<String> keys = new TreeSet<String>();
                    keys.addAll(mMeasurements.keySet());
                    keys.addAll(measurements.keySet());

                    // calculate access point signal strengths with weighted averages
                    // (adjust to suddent big changes in received signal strengths)
                    for (String key : keys) {
                        Integer value = measurements.get(key);
                        Integer oldValue = mMeasurements.get(key);
                        if(oldValue == null) {
                            mMeasurements.put(key, value);
                        } else if(value == null) {
                            mMeasurements.remove(key);
                        } else {
                            value = (int) (oldValue * 0.4f + value * 0.6f);
                            mMeasurements.put(key, value);
                        }
                    }


                    Fingerprint f = new Fingerprint(mMeasurements);

                    // find fingerprint closest to our location (one with the smallest euclidean distance to us)
                    Fingerprint closestMatch = f.getClosestMatch(fingerprints);

                    runOnUiThread(new Runnable() {
                        public void run() {
                            PreferenceManager.getDefaultSharedPreferences(MapViewActivity.this).edit()
                                    .putBoolean(KEY_FINGERPRINT_MADE,true).commit();
                        }
                    });
                    mLocationPointer.setFingerprint(closestMatch); // translate UI pointer to new location on screen
                    saveFingerPrint(closestMatch);
                    // need to refresh map through updateHandler since only UI thread is allowed to touch its views
                    sUpdateHandler.post(mRefreshMap);

                    mScanThreadCount--;
                }
            };
            t.start(); // start new scan thread
        }
    }

    public void startMapEditActivity() {
        Intent intent = new Intent(MapViewActivity.this, MapEditActivity.class);
        intent.putExtra(EXTRA_MESSAGE_FLOOR, mSelectedMap);
        startActivity(intent); // start map edit mode
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // add menu items
        super.onCreateOptionsMenu(menu); // items for changing map
        menu.add(Menu.NONE, MENU_ITEM_EDIT_MAP, Menu.NONE, "Edit map");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case MENU_ITEM_EDIT_MAP: // start map edit mode
                startMapEditActivity();
                return true;
            default: // change map
                return super.onOptionsItemSelected(item);
        }
    }

    private void saveMap(HashMap<String,Integer> inputMap){
        SharedPreferences pSharedPref = getApplicationContext().getSharedPreferences
                ("MyVariables", Context.MODE_PRIVATE);
        if (pSharedPref != null){
            JSONObject jsonObject = new JSONObject(inputMap);
            String jsonString = jsonObject.toString();
            SharedPreferences.Editor editor = pSharedPref.edit();
            editor.remove("My_map").commit();
            editor.putString("My_map", jsonString);
            editor.commit();
        }
    }

    private HashMap<String,Integer> loadMap(){
        HashMap<String,Integer> outputMap = new HashMap<String,Integer>();
        SharedPreferences pSharedPref = getApplicationContext().getSharedPreferences("MyVariables", Context.MODE_PRIVATE);
        try{
            if (pSharedPref != null){
                String jsonString = pSharedPref.getString("My_map", (new JSONObject()).toString());
                JSONObject jsonObject = new JSONObject(jsonString);
                Iterator<String> keysItr = jsonObject.keys();
                while(keysItr.hasNext()) {
                    String key = keysItr.next();
                    Integer value = (Integer) jsonObject.get(key);
                    outputMap.put(key, value);
                }
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return outputMap;
    }

    private void saveFingerPrint(Fingerprint fingerprint)
    {
        PreferenceManager.getDefaultSharedPreferences(this).edit()
                .putInt(KEY_ID,fingerprint.getId())
                .putString(KEY_MAP,fingerprint.getMap())
                .putFloat(KEY_POSITON_X,fingerprint.getLocation().x)
                .putFloat(KEY_POSITON_Y,fingerprint.getLocation().y)
                .commit();
        saveMap(fingerprint.getMeasurements());

    }

    private Fingerprint getSavedFingerprint()
    {
        SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(this);
        int id=preferences.getInt(KEY_ID, -1);
        String map=preferences.getString(KEY_MAP, null);
        Float positionX=preferences.getFloat(KEY_POSITON_X, -1);
        Float positionY=preferences.getFloat(KEY_POSITON_Y,-1);
        PointF pointF=new PointF(positionX,positionY);
        Fingerprint fingerprint=new Fingerprint(id,map,pointF,loadMap());

        return fingerprint;
    }


}

.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ……………………………………………………………………………………………………………………………………………………

You need to declare your Activity class in your AndroidManifest.xml您需要在 AndroidManifest.xml 中声明您的 Activity 类

<manifest ... >
  <application ... >
      <activity android:name=".MapViewActivity" />
      ...
  </application ... >
  ...
</manifest >

http://developer.android.com/guide/components/activities.html http://developer.android.com/guide/components/activities.html

Exception is saying that you haven't declared activity in Manifest File .例外是说您尚未在Manifest File 中声明活动。

Declare your activity in Manifest.在 Manifest 中声明您的活动。

<activity android:name="com.project.mobileshoppingassistant.indoor.MapViewActivity">

And it's done.它已经完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM