Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法存储android设备的位置并将其存储在sqlite中_Android_Sqlite_Geolocation - Fatal编程技术网

无法存储android设备的位置并将其存储在sqlite中

无法存储android设备的位置并将其存储在sqlite中,android,sqlite,geolocation,Android,Sqlite,Geolocation,我想存储位置并将其放入一个数据库中我从这里得到了这段代码。 但是应用程序停止找不到任何原因为什么? 我还插入了API密钥 MainActivity.java文件 package in.wptrafficanalyzer.locationmarkersqlite; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import andr

我想存储位置并将其放入一个数据库中我从这里得到了这段代码。 但是应用程序停止找不到任何原因为什么? 我还插入了API密钥

MainActivity.java文件

    package in.wptrafficanalyzer.locationmarkersqlite;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class LocationsDB extends SQLiteOpenHelper{

    /** Database name */
    private static String DBNAME = "locationmarkersqlite";

    /** Version number of the database */
    private static int VERSION = 1;

    /** Field 1 of the table locations, which is the primary key */
    public static final String FIELD_ROW_ID = "_id";

    /** Field 2 of the table locations, stores the latitude */
    public static final String FIELD_LAT = "lat";

    /** Field 3 of the table locations, stores the longitude*/
    public static final String FIELD_LNG = "lng";

    /** Field 4 of the table locations, stores the zoom level of map*/
    public static final String FIELD_ZOOM = "zom";

    /** A constant, stores the the table name */
    private static final String DATABASE_TABLE = "locations";

    /** An instance variable for SQLiteDatabase */
    private SQLiteDatabase mDB;  


    /** Constructor */
    public LocationsDB(Context context) {
        super(context, DBNAME, null, VERSION);  
        this.mDB = getWritableDatabase();
    }


    /** This is a callback method, invoked when the method getReadableDatabase() / getWritableDatabase() is called 
      * provided the database does not exists 
    * */
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql =    "create table " + DATABASE_TABLE + " ( " +
                            FIELD_ROW_ID + " integer primary key autoincrement , " +
                            FIELD_LNG + " double , " +
                            FIELD_LAT + " double , " +
                            FIELD_ZOOM + " text " +
                        " ) ";

        db.execSQL(sql);
    }

    /** Inserts a new location to the table locations */
    public long insert(ContentValues contentValues){
        long rowID = mDB.insert(DATABASE_TABLE, null, contentValues);
        return rowID;

    }   


    /** Deletes all locations from the table */
    public int del(){
        int cnt = mDB.delete(DATABASE_TABLE, null , null);      
        return cnt;
    }

    /** Returns all the locations from the table */
    public Cursor getAllLocations(){
        return mDB.query(DATABASE_TABLE, new String[] { FIELD_ROW_ID,  FIELD_LAT , FIELD_LNG, FIELD_ZOOM } , null, null, null, null, null);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
位置ContentProvider.java

    package in.wptrafficanalyzer.locationmarkersqlite;

import java.sql.SQLException;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

/** A custom Content Provider to do the database operations */
public class LocationsContentProvider extends ContentProvider{

    public static final String PROVIDER_NAME = "in.wptrafficanalyzer.locationmarkersqlite.locations";

    /** A uri to do operations on locations table. A content provider is identified by its uri */
    public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/locations" );

    /** Constant to identify the requested operation */
    private static final int LOCATIONS = 1; 

    private static final UriMatcher uriMatcher ;

    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(PROVIDER_NAME, "locations", LOCATIONS);       
    }

    /** This content provider does the database operations by this object */
    LocationsDB mLocationsDB;

    /** A callback method which is invoked when the content provider is starting up */
    @Override
    public boolean onCreate() {
        mLocationsDB = new LocationsDB(getContext());
        return true;
    }

    /** A callback method which is invoked when insert operation is requested on this content provider */
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        long rowID = mLocationsDB.insert(values);
        Uri _uri=null;
        if(rowID>0){
            _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
        }else {     
            try {
                throw new SQLException("Failed to insert : " + uri);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return _uri;    
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
            String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }



    /** A callback method which is invoked when delete operation is requested on this content provider */
    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        int cnt = 0;        
        cnt = mLocationsDB.del();   
        return cnt;
    }

    /** A callback method which is invoked by default content uri */
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 

        if(uriMatcher.match(uri)==LOCATIONS){
            return mLocationsDB.getAllLocations();
        }
        return null;
    }


    @Override
    public String getType(Uri uri) {        
        return null;
    }   
}
logcat输出

    08-15 01:29:34.509: I/ActivityThread(543): Pub in.wptrafficanalyzer.locationmarkersqlite.locations: in.wptrafficanalyzer.locationmarkersqlite.LocationsContentProvider
08-15 01:29:34.818: D/AndroidRuntime(543): Shutting down VM
08-15 01:29:34.818: W/dalvikvm(543): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-15 01:29:34.828: E/AndroidRuntime(543): FATAL EXCEPTION: main
08-15 01:29:34.828: E/AndroidRuntime(543): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationmarkersqlite/in.wptrafficanalyzer.locationmarkersqlite.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.os.Looper.loop(Looper.java:137)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 01:29:34.828: E/AndroidRuntime(543):  at java.lang.reflect.Method.invokeNative(Native Method)
08-15 01:29:34.828: E/AndroidRuntime(543):  at java.lang.reflect.Method.invoke(Method.java:511)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 01:29:34.828: E/AndroidRuntime(543):  at dalvik.system.NativeStart.main(Native Method)
08-15 01:29:34.828: E/AndroidRuntime(543): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.Activity.setContentView(Activity.java:1835)
08-15 01:29:34.828: E/AndroidRuntime(543):  at in.wptrafficanalyzer.locationmarkersqlite.MainActivity.onCreate(MainActivity.java:33)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.Activity.performCreate(Activity.java:4465)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
08-15 01:29:34.828: E/AndroidRuntime(543):  ... 11 more
08-15 01:29:34.828: E/AndroidRuntime(543): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4132500 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.maps.internal.q.v(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.maps.internal.q.u(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.maps.SupportMapFragment$b.eb(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.dynamic.a.a(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
08-15 01:29:34.828: E/AndroidRuntime(543):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
08-15 01:29:34.828: E/AndroidRuntime(543):  ... 21 more
08-15 01:29:36.898: I/Process(543): Sending signal. PID: 543 SIG: 9
08-15 01:29:34.509:I/ActivityThread(543):发布in.wptrafficanalyzer.locationmarkersqlite.locations:in.wptrafficanalyzer.locationmarkersqlite.LocationsContentProvider
08-15 01:29:34.818:D/AndroidRuntime(543):关闭虚拟机
08-15 01:29:34.818:W/dalvikvm(543):threadid=1:线程退出时出现未捕获异常(组=0x409961f8)
08-15 01:29:34.828:E/AndroidRuntime(543):致命异常:主
08-15 01:29:34.828:E/AndroidRuntime(543):java.lang.RuntimeException:无法启动活动组件信息{in.wptrafficanalyzer.locationmarkersqlite/in.wptrafficanalyzer.locationmarkersqlite.MainActivity}:android.view.InflateException:二进制XML文件行#7:膨胀类片段时出错
08-15 01:29:34.828:E/AndroidRuntime(543):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.app.ActivityThread.access$600(ActivityThread.java:122)
08-15 01:29:34.828:E/AndroidRuntime(543):位于android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-15 01:29:34.828:E/AndroidRuntime(543):位于android.os.Handler.dispatchMessage(Handler.java:99)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.os.Looper.loop(Looper.java:137)
08-15 01:29:34.828:E/AndroidRuntime(543):位于android.app.ActivityThread.main(ActivityThread.java:4340)
08-15 01:29:34.828:E/AndroidRuntime(543):位于java.lang.reflect.Method.Invokenactive(本机方法)
08-15 01:29:34.828:E/AndroidRuntime(543):在java.lang.reflect.Method.invoke(Method.java:511)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 01:29:34.828:E/AndroidRuntime(543):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 01:29:34.828:E/AndroidRuntime(543):在dalvik.system.NativeStart.main(本机方法)
08-15 01:29:34.828:E/AndroidRuntime(543):由以下原因引起:android.view.InflateException:二进制XML文件行#7:膨胀类片段时出错
08-15 01:29:34.828:E/AndroidRuntime(543):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-15 01:29:34.828:E/AndroidRuntime(543):位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
08-15 01:29:34.828:E/AndroidRuntime(543):位于android.app.Activity.setContentView(Activity.java:1835)
08-15 01:29:34.828:E/AndroidRuntime(543):位于in.wptrafficanalyzer.locationmarkersqlite.MainActivity.onCreate(MainActivity.java:33)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.app.Activity.performCreate(Activity.java:4465)上
08-15 01:29:34.828:E/AndroidRuntime(543):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)上
08-15 01:29:34.828:E/AndroidRuntime(543):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
2008-15 01:29:34.828:E/AndroidRuntime(543):。。。还有11个
08-15 01:29:34.828:E/AndroidRuntime(543):由以下原因引起:java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。应为4132500,但找到0。元素中必须有以下声明:
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.common.GooglePlayServicesUtil.n(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.common.GooglePlayServicesUtil.isgoogleplayservicesavaailable(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):位于com.google.android.gms.maps.internal.q.v(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):位于com.google.android.gms.maps.internal.q.u(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.maps.mapsintializer.initialize(未知源)
08-15 01:29:34.828:E/AndroidRuntime(543):位于com.google.android.gms.maps.SupportMapFragment$b.eb(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.maps.SupportMapFragment$b.a(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.dynamic.a.a(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.dynamic.a.onInflate(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):在com.google.android.gms.maps.SupportMapFragment.onInflate(未知来源)
08-15 01:29:34.828:E/AndroidRuntime(543):位于android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
08-15 01:29:34.828:E/AndroidRuntime(543):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
2008-15 01:29:34.828:E/AndroidRuntime(543):。。。还有21个
08-15 01:29:36.898:I/进程(543):发送信号。PID:543信号:9
阅读最底层的“由”异常,以获得有关问题及其修复的有用信息:

The meta-data tag in your app's AndroidManifest.xml does not have the right value.
Expected 4132500 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
应用程序的AndroidManifest.xml中的元数据标记没有正确的值。
应为4132500,但找到0。
元素中必须有以下声明:

(我刚刚添加了一些换行符以使其更具可读性。)

错误消息会告诉您做错了什么。