
我想通过Google地方信息API在 *** 作栏中使用搜索视图小部件,偶然发现了指向Stack Overflow各个帖子中共享的教程的链接,因此我决定进行检查.我已经将其全部实现到现有代码中,但是我遇到了NullPointerException并希望有人可以帮助我,以便我可以调试问题.我一直在浏览Stack Overflow上的各种帖子以及Google上的文章…
Logcat指定它是由第119和123行引起的.
MainActivity.java:
@H_404_9@public class MainActivity extends FragmentActivity implementsGooglePlayServicesClIEnt.ConnectionCallbacks,GooglePlayServicesClIEnt.OnConnectionFailedListener,LocationListener,OnMapLongClickListener,LoaderCallbacks<Cursor> {//Global Constantsprivate final static int CONNECTION_FAILURE_RESolUTION_REQUEST = 9000;// Milliseconds per secondprivate static final int MILliSECONDS_PER_SECOND = 1000;// Update frequency in secondspublic static final int UPDATE_INTERVAL_IN_SECONDS = 5;// Update frequency in millisecondsprivate static final long UPDATE_INTERVAL = MILliSECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS;// The fastest update frequency, in secondsprivate static final int FASTEST_INTERVAL_IN_SECONDS = 1;// A fast frequency ceiling in millisecondsprivate static final long FASTEST_INTERVAL = MILliSECONDS_PER_SECOND * FASTEST_INTERVAL_IN_SECONDS;//Global VariablesGoogleMap map;Marker marker;LocationRequest requestLocation;LocationClIEnt locationClIEnt;LocationManager locationManager;boolean updatesRequested;Geofence geoFence;Vibrator vibStatus;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); // Create the LocationRequest object requestLocation = LocationRequest.create(); // Use high accuracy requestLocation.setPriority( LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the update interval to 5 seconds requestLocation.setInterval(UPDATE_INTERVAL); // Set the fastest update interval to 1 second requestLocation.setFastestInterval(FASTEST_INTERVAL); SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByID(R.ID.map); map = fragment.getMap(); //Enables "My Location" button on map fragment map.getUiSettings().setMyLocationbuttonEnabled(true); //Create a new location clIEnt, using the enclosing class to handle callbacks. locationClIEnt = new LocationClIEnt(this, this, this); // Start with updates turned off updatesRequested = false; // map.setonMapLongClickListener(this); // Look up the AdVIEw as a resource and load a request. AdVIEw adVIEw = (AdVIEw)this.findVIEwByID(R.ID.adVIEw); AdRequest adRequest = new AdRequest.Builder().build(); adVIEw.loadAd(adRequest); handleIntent(getIntent()); //This is line 119 in my code }private voID handleIntent(Intent intent){ if(intent.getAction().equals(Intent.ACTION_SEARCH)){ //This is line 123 in my code doSearch(intent.getStringExtra(SearchManager.query)); }else if(intent.getAction().equals(Intent.ACTION_VIEW)){ getPlace(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); }}@OverrIDeprotected voID onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); handleIntent(intent);}...}AndroIDManifest.xml:
@H_404_9@<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="com...." //Removed while posting on forumandroID:versionCode="1"androID:versionname="1.0" ><uses-sdk androID:minSdkVersion="10" androID:targetSdkVersion="19" /><!-- Protect the map component of the application using application signature --><permission androID:name="com.....permission.MAPS_RECEIVE" //Removed while posting on forum androID:protectionLevel="signature" /><!-- Allows to receive map --><uses-permission androID:name="com.....permission.MAPS_RECEIVE" /> //Removed while posting on forum<uses-permission androID:name="androID.permission.INTERNET" /><uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" /><uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission androID:name="com.Google.androID.provIDers.gsf.permission.READ_GSERVICES" /><uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" /><uses-permission androID:name="androID.permission.VIBRATE" /><uses-feature androID:glEsversion="0x00020000" androID:required="true" /><application androID:allowBackup="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" androID:theme="@style/theme.AppCompat.light.DarkActionbar" > <activity androID:name="com.....SplashActivity" //Removed while posting on forum androID:label="@string/app_name" androID:screenorIEntation="portrait" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name="com.....MainActivity" //Removed while posting on forum androID:label="@string/app_name" androID:launchMode="singletop" androID:screenorIEntation="portrait" > <intent-filter> <action androID:name="androID.intent.action.SEARCH" /> </intent-filter> <!-- Points to searchable activity --> <Meta-data androID:name="androID.app.default_searchable" androID:value="com.....MainActivity" /> //Removed while posting on forum <!-- Points to searchable Meta data --> <Meta-data androID:name="androID.app.searchable" androID:resource="@xml/searchable"/> </activity> <activity androID:name="com.....PreferencesActivity" //Removed while posting on forum androID:label="@string/Title_activity_settings" androID:parentActivityname="com.....MainActivity" //Removed while posting on forum androID:screenorIEntation="portrait" > <Meta-data androID:name="androID.support.PARENT_ACTIVITY" androID:value="com.....MainActivity" /> //Removed while posting on forum </activity> <activity androID:name="com.....AlarmActivity" //Removed while posting on forum androID:label="@string/Title_activity_alarm" > </activity> <activity androID:name="com.Google.androID.gms.ads.AdActivity" androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize" /> <activity androID:name="com.....PlaceJsONParser" //Removed while posting on forum androID:label="@string/Title_activity_place_Jsonparser" > </activity> <activity androID:name="com.....PlaceDetailsJsONParser" //Removed while posting on forum androID:label="@string/Title_activity_place_details_Jsonparser" > </activity> <activity androID:name="com.....PlaceProvIDer" //Removed while posting on forum androID:label="@string/Title_activity_place_provIDer" > </activity> <provIDer androID:name=".PlaceProvIDer" androID:authoritIEs="com.....PlaceProvIDer" //Removed while posting on forum androID:exported="false" /> <Meta-data androID:name="com.Google.androID.gms.version" androID:value="@integer/Google_play_services_version" /> <Meta-data androID:name="com.Google.androID.maps.v2.API_KEY" androID:value="MY-KEY-HERE" /> //Removed while posting on forum</application></manifest>
解决方法:
您是从SplashActivity启动MainActivity吗?搜索视图中什么时候发生?看起来像它.调用startActivity(intent)时,需要确保已为该意图添加了一个 *** 作:
@H_404_9@Intent mainActivityIntent = new Intent(context);mainActivityIntent.setAction(Intent.ACTION_SEARCH);startActivity(mainActivityIntent);
如果您(或使用意图调用您的MainActivity的任何对象)未对该意图设置 *** 作,则当您尝试对Activity中的调用意图进行getAction()时,您将获得一个空指针.
总结以上是内存溢出为你收集整理的java-getAction()或Intent上的NullPointerException全部内容,希望文章能够帮你解决java-getAction()或Intent上的NullPointerException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)