故障使用解析 [英] Trouble in using parse

查看:118
本文介绍了故障使用解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使这是使用解析库推notifications.I应用程序跟着教程从parse.com但它不工作。
我得到错误:

 了java.lang.RuntimeException:无法启动活动ComponentInfo {com.robotrackerclient / com.robotrackerclient.MainActivity}:java.lang.IllegalArgumentException异常:监听== NULL

我认为这个问题是在codeI是一种具有正推出app.I活性的主要活动将我在 parse.initialize() code在OnCreate主要activity.Is此创建问题的方法是什么?还有一个错误:你必须调用 parse.initialize(..)之前,使用解析库

主要活动仅仅是一个简单的类获取lattitude和当前位置的经度和推动它。

 公共类MainActivity延伸活动{
         私人字符串imei_ code_of_device;
         私人的LocationManager流明;
         私人LocationListener的LocationListener的;
         TelephonyManager mngr;        @覆盖
        保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        //指定一个活动默认来处理所有推。
        //PushService.setDefaultPushCallback(this,MainActivity.class);        Parse.initialize(这一点,APP_KEY,CLIENT_KEY);
        PushService.setDefaultPushCallback(这一点,MainActivity.class);        mngr =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        imei_ code_of_device = mngr.getDeviceId();
        LM =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,LocationListener的);        LocationListener的=新MyLocationListener();
        如果(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){
            buildAlertMessageNoGps();
        }
        其他{         lm.requestLocationUpdates(
         LocationManager.GPS_PROVIDER,
         10000,
         0,
         LocationListener的);
         lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,10000,0,LocationListener的);        }
        }
    私人无效buildAlertMessageNoGps(){         最后AlertDialog.Builder建设者=新AlertDialog.Builder(本);
            builder.setMessage(您的GPS似乎被禁用,你要启用它?)。setCancelable(假).setPositiveButton(是,新DialogInterface.OnClickListener(){
                       公共无效的onClick(@燮pressWarnings(未使用)最终DialogInterface对话框,@燮pressWarnings(未使用)最终诠释的id){
                           startActivity(新意图(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                       }
                   })
                   .setNegativeButton(否,新DialogInterface.OnClickListener(){
                       公共无效的onClick(最终DialogInterface对话框,@燮pressWarnings(未使用)最终诠释的id){
                            dialog.cancel();
                       }
                   });
            最后AlertDialog警报= builder.create();
            alert.show();    }
    私有类MyLocationListener实现LocationListener的{        @覆盖
        公共无效onLocationChanged(位置LOC){
            如果(LOC!= NULL){
                的parseObject PO =新的parseObject(LatLang);
                po.put(imei_ code,imei_ code_of_device);
                po.put(纬度,loc.getLatitude());
                po.put(经度,loc.getLongitude());
                po.saveInBackground();
                Toast.makeText(getBaseContext(),位置变了:纬度:+ loc.getLatitude()+LNG+ loc.getLongitude(),Toast.LENGTH_SHORT).show();            }        }        @覆盖
        公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){
            // TODO自动生成方法存根        }        @覆盖
        公共无效onProviderEnabled(字符串提供商){
            // TODO自动生成方法存根        }        @覆盖
        公共无效onProviderDisabled(字符串提供商){
            // TODO自动生成方法存根        }     }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT ID = item.getItemId();
        如果(ID == R.id.action_settings){
            返回true;
        }
        返回super.onOptionsItemSelected(项目);
    }
}

下面是我的androidmenifest文件:
我完成了parse.com.I提供这些步骤教程帮助都包含其中parse.com教程说我include.I我没有得到Application.Because点我在活动中的一个来解析和它是不是要launched.So我不想在我的应用程序启动时初始化解析的第一个活动。

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.robotrackerclient
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =16
        机器人:targetSdkVersion =16/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>
    <使用许可权的android:NAME =android.permission.VIBRATE/>
    <使用许可权的android:NAME =android.permission.WAKE_LOCK/>
    <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
    <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用许可权的android:NAME =android.permission.GET_ACCOUNTS/>
    <使用许可权的android:NAME =com.google.android.c2dm.permission.RECEIVE/>
    <使用许可权的android:NAME =android.permission.READ_PHONE_STATE/>    <允许机器人:名字=com.robotrackerclient.permission.C2D_MESSAGE
        安卓的ProtectionLevel =签名/>
    <使用许可权的android:NAME =com.robotrackerclient.permission.C2D_MESSAGE/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=。MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        <服务机器人:名字=com.parse.PushService/>
        <接收机器人:名字=com.parse.ParseBroadcastReceiver>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
                <作用机器人:名字=android.intent.action.USER_ preSENT/>
            &所述; /意图滤光器>
        < /接收器>
        <接收机器人:名字=com.parse.GcmBroadcastReceiver
            机器人:权限=com.google.android.c2dm.permission.SEND>
            &所述;意图滤光器>
                <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
                <作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>                <类机器人:名字=com.robotrackerclient/>
            &所述; /意图滤光器>
        < /接收器>
        <接收机器人:名字=com.parse.ParsePushBroadcastReceiver
        机器人:出口=假>
        &所述;意图滤光器>
        <作用机器人:名字=com.parse.push.intent.RECEIVE/>
        <作用机器人:名字=com.parse.push.intent.DELETE/>
        <作用机器人:名字=com.parse.push.intent.OPEN/>
         &所述; /意图滤光器>
       < /接收器>       < /用途>
        < /清单>


解决方案

好吧非常感谢你的帮助,我能够发送推parse.com.The的错误是在清单file.I更新menifestfile与提供的Andr​​oid :名称= tag.Then我在ParseActivity类中定义的初始化应用下的ParseActivity。
现在,有谁能够告诉如何使用同一组键来获取其它设备上了服务器推送的数据?

I am trying to make an app which is using parse library for push notifications.I followed the tutorials from parse.com but its not working. I am getting error:

java.lang.RuntimeException: Unable to start activity 

ComponentInfo{com.robotrackerclient/com.robotrackerclient.MainActivity}: 

java.lang.IllegalArgumentException: listener==null

I think the problem is in the code.I am having a main activity which is launching activity of the app.I am putting the parse.initialize() code in the onCreate method of main activity.Is this creating the problem? There is one more error: You must call parse.initialize(..) before using the parse library.

The Main Activity is just a simple class getting the lattitude and longitude of the current location and pushing it.

         public class MainActivity extends Activity {
         private String imei_code_of_device;
         private LocationManager lm;
         private LocationListener locationListener;
         TelephonyManager mngr;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Specify an Activity to handle all pushes by default.
        //PushService.setDefaultPushCallback(this, MainActivity.class);

        Parse.initialize(this, "APP_KEY", "CLIENT_KEY"); 
        PushService.setDefaultPushCallback(this, MainActivity.class);

        mngr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        imei_code_of_device=mngr.getDeviceId();
        lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListener);               

        locationListener = new MyLocationListener();
        if ( !lm.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            buildAlertMessageNoGps();
        }
        else{

         lm.requestLocationUpdates(
         LocationManager.GPS_PROVIDER,
         10000,
         0,
         locationListener);
         lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,10000,0,locationListener);              

        }
        }
    private void buildAlertMessageNoGps() {

         final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                       public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                           startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                       }
                   })
                   .setNegativeButton("No", new DialogInterface.OnClickListener() {
                       public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                            dialog.cancel();
                       }
                   });
            final AlertDialog alert = builder.create();
            alert.show();

    }
    private class MyLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {
                ParseObject po=new ParseObject("LatLang");
                po.put("imei_code",imei_code_of_device);
                po.put("latitude",loc.getLatitude());
                po.put("longitude",loc.getLongitude());
                po.saveInBackground();
                Toast.makeText(getBaseContext(),"Location changed : Lat: " + loc.getLatitude() +" Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();

            }

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

     }



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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Here is my androidmenifest file: I completed these steps with help of the tutorials available on parse.com.I included everything which parse.com tutorial said me to include.I am not getting the point of Application.Because I have to parse in the one of the activities only and it is not the first activity to be launched.So I dont want to initialize parse at my application startup.

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

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <permission android:name="com.robotrackerclient.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.robotrackerclient.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="com.robotrackerclient" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.ParsePushBroadcastReceiver"
        android:exported="false">
        <intent-filter>            
        <action android:name="com.parse.push.intent.RECEIVE" />
        <action android:name="com.parse.push.intent.DELETE" />
        <action android:name="com.parse.push.intent.OPEN" />
         </intent-filter>
       </receiver>

       </application>
        </manifest>

解决方案

OKay thank you very much for helping I am able to send push to parse.com.The mistake was in the manifest file.I updated the menifestfile with providing android:name=."ParseActivity" under the application tag.Then I defined the initialization in the ParseActivity class. Now can anybody tell how to get the pushed data over server back on another device using the same set of keys?

这篇关于故障使用解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆