Null Pointer Exception - Java for Android App Development

Hello there,
I am trying to learn android application development through one of the online tutorials .I am stuck at a point and since,both java and android are new for me I can't figure out how to get out of it.Here's the code to my Startingpoint.java:
Code:
public class Startingpoint extends Activity {
int counter;
Button add,sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter=0;
add=(Button)findViewById(R.id.bAdd);
sub=(Button)findViewById(R.id.bSub);
display=(TextView)findViewById(R.id.display);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
counter--;
display.setText("Your total is" + counter);
}
});
}
}
The following are the contents within the LineaLlayout in my main.xml file:
Code:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="25sp"
android:layout_gravity="fill_horizontal"
android:gravity="center"
android:id="@+id/display"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/bAdd"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/bAdd"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/bSub"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/bSub"
/>
And this is what the logcat has to say :
Code:
02-13 11:44:12.076: D/AndroidRuntime(2026): Shutting down VM
02-13 11:44:12.076: W/dalvikvm(2026): threadid=1: thread exiting with uncaught exception (group=0xb2d5bb08)
02-13 11:44:12.156: E/AndroidRuntime(2026): FATAL EXCEPTION: main
02-13 11:44:12.156: E/AndroidRuntime(2026): Process: com.thenewboston.rohit, PID: 2026
02-13 11:44:12.156: E/AndroidRuntime(2026): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thenewboston.rohit/com.thenewboston.rohit.Startingpoint}: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.access$700(ActivityThread.java:135)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.os.Handler.dispatchMessage(Handler.java:102)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.os.Looper.loop(Looper.java:137)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.main(ActivityThread.java:4998)
02-13 11:44:12.156: E/AndroidRuntime(2026): at java.lang.reflect.Method.invokeNative(Native Method)
02-13 11:44:12.156: E/AndroidRuntime(2026): at java.lang.reflect.Method.invoke(Method.java:515)
02-13 11:44:12.156: E/AndroidRuntime(2026): atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
02-13 11:44:12.156: E/AndroidRuntime(2026): at dalvik.system.NativeStart.main(Native Method)
02-13 11:44:12.156: E/AndroidRuntime(2026): Caused by: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.thenewboston.rohit.Startingpoint.onCreate(Startingpoint.java:21)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.Activity.performCreate(Activity.java:5243)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-13 11:44:12.156: E/AndroidRuntime(2026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
02-13 11:44:12.156: E/AndroidRuntime(2026): ... 11 more
Being inexperienced in java , I could not figure out what's wrong with the code.May be the exception is due to my add,sub and display being null but I am not sure.Please help me figure out what's wrong with my code and how to deal with it.
Any help is greatly appreciated.

Well, you can find the line where it crashes in the logcat:
Code:
02-13 11:44:12.156: E/AndroidRuntime(2026): Caused by: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.thenewboston.rohit.Startingpoint.onCreate([B]Startingpoint.java:21[/B])
It's line 21. Which one is that?
Have a look at my debugging tutorial here as well, mainly the part on understanding the logcat. It will probably be very helpful and save much time: http://forum.xda-developers.com/showthread.php?t=2325164

nikwen said:
Well, you can find the line where it crashes in the logcat:
Code:
02-13 11:44:12.156: E/AndroidRuntime(2026): Caused by: java.lang.NullPointerException
02-13 11:44:12.156: E/AndroidRuntime(2026): at com.thenewboston.rohit.Startingpoint.onCreate([B]Startingpoint.java:21[/B])
It's line 21. Which one is that?
Have a look at my debugging tutorial here as well, mainly the part on understanding the logcat. It will probably be very helpful and save much time: http://forum.xda-developers.com/showthread.php?t=2325164
Click to expand...
Click to collapse
I bet they must be the findViewById(int id);
as much i trust my counting skills line 21 is calling for one the views
i still remeber the first NPE when i started android
Sent from my GT-S5302 using Tapatalk 2

I am sorry , I should have mentioned it.
Line 21 -> add.setOnClickListener(new View.OnClickListener()

DarkMethod said:
I am sorry , I should have mentioned it.
Line 21 -> add.setOnClickListener(new View.OnClickListener()
Click to expand...
Click to collapse
It means the.view with id bAdd was not found make sure have declared it in your layout
Sent from my GT-S5302 using Tapatalk 2

I have declared the ids for each view as you can see in the layout.xml attached.This NPE is turning out to be quite frustrating now.

DarkMethod said:
I have declared the ids for each view as you can see in the layout.xml attached.This NPE is turning out to be quite frustrating now.
Click to expand...
Click to collapse
do one thing
add a breakpoint to each line
then debug your app if on Eclipse or Android Studio !
and watch the control flow through each line this should narrow you down to the root cause.
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
do one thing
add a breakpoint to each line
then debug your app if on Eclipse or Android Studio !
and watch the control flow through each line this should narrow you down to the root cause.
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
More on that here as well: http://forum.xda-developers.com/showthread.php?t=2325164

nikwen said:
More on that here as well: http://forum.xda-developers.com/showthread.php?t=2325164
Click to expand...
Click to collapse
indeed a great one :thumbup:
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
indeed a great one :thumbup:
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Thanks.

Related

[Q] Error - Google Maps Android API v2

Helllo
I have a problem with Google Maps Android API v2
every time I try to open the app on device or even on emulator this message always display
Unfortunately Google Maps API Demos has stopped
I have made a video that Explain every steps that I did
http://www.youtube.com/watch?v=WUmlu3CNOSo
and this is the error that display on Eclipse
ahmadssb.com/ttv2541/com.example.mapdemo.txt
Actually I have tried many tutorials on internet
also I tried to do the coding by myself according to Google instructions
https://developers.google.com/maps/documentation/android/start
and this is the error that display on Eclipse
www.ahmadssb.com/ttv2541/com.example.mapdemo.txt
I don't know what's wrong with this problem
please help me
ahmadssb said:
Helllo
I have a problem with Google Maps Android API v2
every time I try to open the app on device or even on emulator this message always display
Unfortunately Google Maps API Demos has stopped
I have made a video that Explain every steps that I did
http://www.youtube.com/watch?v=WUmlu3CNOSo
and this is the error that display on Eclipse
ahmadssb.com/ttv2541/com.example.mapdemo.txt
Actually I have tried many tutorials on internet
also I tried to do the coding by myself according to Google instructions
https://developers.google.com/maps/documentation/android/start
and this is the error that display on Eclipse
www.ahmadssb.com/ttv2541/com.example.mapdemo.txt
I don't know what's wrong with this problem
please help me
Click to expand...
Click to collapse
Your package name is com.*.
I think that in your AndroidManifest.xml there is a "L" before the com in the definition of your class. It is something like Lcom.*
Remove the L.
My suggestion is to walk through the following tutorial and see if you can get it working and put the demo to the side for now.
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
nikwen said:
Your package name is com.*.
I think that in your AndroidManifest.xml there is a "L" before the com in the definition of your class. It is something like Lcom.*
Remove the L.
Click to expand...
Click to collapse
there is no L on package name ...
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="2"
android:versionName="2.1.0">
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE"/>
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- End of copy. -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/demo_title"
android:hardwareAccelerated="true">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".BasicMapActivity"
android:label="@string/basic_map"/>
<activity
android:name=".CameraDemoActivity"
android:label="@string/camera_demo"/>
<activity
android:name=".CircleDemoActivity"
android:label="@string/circle_demo"/>
<activity
android:name=".EventsDemoActivity"
android:label="@string/events_demo"/>
<activity
android:name=".GroundOverlayDemoActivity"
android:label="@string/groundoverlay_demo"/>
<activity
android:name=".LayersDemoActivity"
android:label="@string/layers_demo"/>
<activity
android:name=".LocationSourceDemoActivity"
android:label="@string/locationsource_demo"/>
<activity
android:name=".MarkerDemoActivity"
android:label="@string/marker_demo"/>
<activity
android:name=".OptionsDemoActivity"
android:label="@string/options_demo"/>
<activity
android:name=".PolygonDemoActivity"
android:label="@string/polygon_demo"/>
<activity
android:name=".PolylineDemoActivity"
android:label="@string/polyline_demo"/>
<activity
android:name=".ProgrammaticDemoActivity"
android:label="@string/programmatic_demo"/>
<activity
android:name=".TileOverlayDemoActivity"
android:label="@string/tile_overlay_demo"/>
<activity
android:name=".UiSettingsDemoActivity"
android:label="@string/uisettings_demo"/>
<activity
android:name=".RawMapViewDemoActivity"
android:label="@string/raw_mapview_demo"/>
<activity
android:name=".RetainMapActivity"
android:label="@string/retain_map"/>
<activity
android:name=".MultiMapDemoActivity"
android:label="@string/multi_map_demo"/>
</application>
</manifest>
MainActivity.java
Code:
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.mapdemo;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.example.mapdemo.view.FeatureView;
/**
* The main activity of the API library demo gallery.
* <p>
* The main layout lists the demonstrated features, with buttons to launch them.
*/
public final class MainActivity extends ListActivity {
/**
* A simple POJO that holds the details about the demo that are used by the List Adapter.
*/
private static class DemoDetails {
/**
* The resource id of the title of the demo.
*/
private final int titleId;
/**
* The resources id of the description of the demo.
*/
private final int descriptionId;
/**
* The demo activity's class.
*/
private final Class<? extends FragmentActivity> activityClass;
public DemoDetails(
int titleId, int descriptionId, Class<? extends FragmentActivity> activityClass) {
super();
this.titleId = titleId;
this.descriptionId = descriptionId;
this.activityClass = activityClass;
}
}
/**
* A custom array adapter that shows a {@link FeatureView} containing details about the demo.
*/
private static class CustomArrayAdapter extends ArrayAdapter<DemoDetails> {
/**
* [user=955119]@param[/user] demos An array containing the details of the demos to be displayed.
*/
public CustomArrayAdapter(Context context, DemoDetails[] demos) {
super(context, R.layout.feature, R.id.title, demos);
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
FeatureView featureView;
if (convertView instanceof FeatureView) {
featureView = (FeatureView) convertView;
} else {
featureView = new FeatureView(getContext());
}
DemoDetails demo = getItem(position);
featureView.setTitleId(demo.titleId);
featureView.setDescriptionId(demo.descriptionId);
return featureView;
}
}
private static final DemoDetails[] demos = {new DemoDetails(
R.string.basic_map, R.string.basic_description, BasicMapActivity.class),
new DemoDetails(R.string.camera_demo, R.string.camera_description,
CameraDemoActivity.class),
new DemoDetails(R.string.events_demo, R.string.events_description,
EventsDemoActivity.class),
new DemoDetails(R.string.layers_demo, R.string.layers_description,
LayersDemoActivity.class),
new DemoDetails(
R.string.locationsource_demo, R.string.locationsource_description,
LocationSourceDemoActivity.class),
new DemoDetails(R.string.uisettings_demo, R.string.uisettings_description,
UiSettingsDemoActivity.class),
new DemoDetails(R.string.groundoverlay_demo, R.string.groundoverlay_description,
GroundOverlayDemoActivity.class),
new DemoDetails(R.string.marker_demo, R.string.marker_description,
MarkerDemoActivity.class),
new DemoDetails(R.string.polygon_demo, R.string.polygon_description,
PolygonDemoActivity.class),
new DemoDetails(R.string.polyline_demo, R.string.polyline_description,
PolylineDemoActivity.class),
new DemoDetails(R.string.circle_demo, R.string.circle_description,
CircleDemoActivity.class),
new DemoDetails(R.string.tile_overlay_demo, R.string.tile_overlay_description,
TileOverlayDemoActivity.class),
new DemoDetails(R.string.options_demo, R.string.options_description,
OptionsDemoActivity.class),
new DemoDetails(R.string.multi_map_demo, R.string.multi_map_description,
MultiMapDemoActivity.class),
new DemoDetails(R.string.retain_map, R.string.retain_map_description,
RetainMapActivity.class),
new DemoDetails(R.string.raw_mapview_demo, R.string.raw_mapview_description,
RawMapViewDemoActivity.class),
new DemoDetails(R.string.programmatic_demo, R.string.programmatic_description,
ProgrammaticDemoActivity.class)};
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListAdapter adapter = new CustomArrayAdapter(this, demos);
setListAdapter(adapter);
}
[user=439709]@override[/user]
protected void onListItemClick(ListView l, View v, int position, long id) {
DemoDetails demo = (DemoDetails) getListAdapter().getItem(position);
startActivity(new Intent(this, demo.activityClass));
}
}
zalez said:
My suggestion is to walk through the following tutorial and see if you can get it working and put the demo to the side for now.
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Click to expand...
Click to collapse
It does not find the class definition because the path is spelled wrong!
nikwen said:
It does not find the class definition because the path is spelled wrong!
Click to expand...
Click to collapse
Incorrect. The "L" means Link.
http://stackoverflow.com/questions/13733911/google-maps-android-api-v2-sample-code-crashes
zalez said:
My suggestion is to walk through the following tutorial and see if you can get it working and put the demo to the side for now.
http://www.vogella.com/articles/AndroidGoogleMaps/article.html
Click to expand...
Click to collapse
I tried his tutorial and I still same error displayed
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vogella.android.locationapi.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<permission
android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.vogella.android.locationapi.maps.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value=".................................................." />
</application>
</manifest>
ShowMapActivity.java
Code:
package com.vogella.android.locationapi.maps;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class ShowMapActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_map);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.show_map, menu);
return true;
}
}
Error Log
Code:
04-24 05:09:39.576: E/Trace(10600): error opening trace file: No such file or directory (2)
04-24 05:09:39.741: D/dalvikvm(10600): Trying to load lib /data/app-lib/com.google.android.gms-2/libAppDataSearch.so 0x4215ea30
04-24 05:09:39.806: D/dalvikvm(10600): Added shared lib /data/app-lib/com.google.android.gms-2/libAppDataSearch.so 0x4215ea30
04-24 05:09:39.806: D/dalvikvm(10600): No JNI_OnLoad found in /data/app-lib/com.google.android.gms-2/libAppDataSearch.so 0x4215ea30, skipping init
04-24 05:09:39.811: D/Icing(10600): Init last flush num docs 170 last docstore size 431104
04-24 05:09:39.811: D/Icing(10600): Docid map file has data, scanning...
04-24 05:09:39.811: D/Icing(10600): Scanning /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.docids found 170 documents, last docstore location 429312
04-24 05:09:39.811: D/Icing(10600): File /data/data/com.google.android.gms/files/AppDataSearch/main/cur/ds.perdocdata contains 170 records of size 6
04-24 05:09:39.816: D/Icing(10600): Init docstore ok num docs 170 bytes 431104
04-24 05:09:39.831: V/Icing(10600): Lite index crc computed in 0.079ms
04-24 05:09:39.831: V/Icing(10600): Lite index init ok in 1.932ms
04-24 05:09:39.831: V/Icing(10600): Warming lite-index took 0.011ms
04-24 05:09:39.831: V/Icing(10600): Warming lexicon took 0.020ms
04-24 05:09:39.831: V/Icing(10600): Warming display mappings took 0.012ms
04-24 05:09:39.831: D/Icing(10600): Init index ok num docs 170
04-24 05:09:39.831: D/Icing(10600): Init done
04-24 05:09:39.866: E/Icing(10600): Not enough disk space. Will not index.
04-24 05:09:57.391: I/Recovery(10600): Received: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.recovery.AccountRecoveryService$Receiver }
04-24 05:09:57.806: I/Recovery(10600): Received: Intent { act=com.google.android.gms.INITIALIZE flg=0x10 pkg=com.google.android.gms cmp=com.google.android.gms/.recovery.AccountRecoveryService$Receiver }
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
04-24 05:09:39.866: E/Icing(10600): Not enough disk space. Will not index.
are you out of space?
out of ideas said:
04-24 05:09:39.866: E/Icing(10600): Not enough disk space. Will not index.
are you out of space?
Click to expand...
Click to collapse
i didn't understand what this error means or want !!! because I have more than enough space for simple program like this
if it means my PC then I have more than enough space on my SSD hard drive and RAM is 8 GB
also when I check the task manege
RAM : 61%
CPU almost 18%
and for my phone (GS2 using CyanogenMod 10.1):
System ROM: 528 MB (159 MB free)
Internal : 2.11 GB (886 MB free)
media : 12.3 GB (4.8 GB free)
Ext. SD card : 15.7 GB (14.5 GB free)
weird. are you still getting the same fatal exception error?
So, your activity where the map is should extend a fragment activity cuz the maps are now fragments. You should also go with SupportMapFragment so gingerbread can use it too.
im using something like this for my MainActivity
Code:
import android.support.v4.app.FragmentActivity;
import android.view.View;
//There are other imports, these are map things
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
//Notice the FragmentActivity difference?
public class MainActivity extends FragmentActivity {
private GoogleMap mMap;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
and then my layout that gets setup from there is like this
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
this site has some good tutorials on the maps. I couldnt get vogella to work for me either.
http://wptrafficanalyzer.in/blog/go...maps-android-api-v2-using-supportmapfragment/
out of ideas said:
weird. are you still getting the same fatal exception error?
So, your activity where the map is should extend a fragment activity cuz the maps are now fragments. You should also go with SupportMapFragment so gingerbread can use it too.
im using something like this for my MainActivity
Code:
import android.support.v4.app.FragmentActivity;
import android.view.View;
//There are other imports, these are map things
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
//Notice the FragmentActivity difference?
public class MainActivity extends FragmentActivity {
private GoogleMap mMap;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
and then my layout that gets setup from there is like this
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
this site has some good tutorials on the maps. I couldnt get vogella to work for me either.
http://wptrafficanalyzer.in/blog/go...maps-android-api-v2-using-supportmapfragment/
Click to expand...
Click to collapse
thank you for the link, but I still getting the same error in my phone (Galaxy S 2, ROM CyanogenMod 10.1 )
also using the emulator with 2 AVD for (4.2.2) and (4.2.2 with Google API)
still not working
I start to think (and maybe it is ) that the problem is not from the code the problem is from my phone or the setting in my PC or Eclipse
while any other application is working fine with me except that using google apis key (actually I didn't try any thing that needs api key and this is my first time using it)
BTW this is the result from the tutorial from the link that you gave to me
====================================================
Log:
——-
Code:
04-26 01:28:57.494: D/dalvikvm(5121): Late-enabling CheckJNI
04-26 01:28:57.629: E/Trace(5121): error opening trace file: No such file or directory (2)
04-26 01:28:57.659: D/AndroidRuntime(5121): Shutting down VM
04-26 01:28:57.659: W/dalvikvm(5121): threadid=1: thread exiting with uncaught exception (group=0x41ff7930)
04-26 01:28:57.679: E/AndroidRuntime(5121): FATAL EXCEPTION: main
04-26 01:28:57.679: E/AndroidRuntime(5121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmadssb.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Looper.loop(Looper.java:137)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.main(ActivityThread.java:5226)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.NativeStart.main(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
04-26 01:28:57.679: E/AndroidRuntime(5121): … 11 more
——
AndroidManifest.xml
——-
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ahmadssb.locationgooglemapv2demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.ahmadssb.locationgooglemapv2demo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.ahmadssb.locationgooglemapv2demo.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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/AppTheme" >
<activity
android:name="in.wptrafficanalyzer.locationgooglemapv2demo.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="************MY API KEY***********"/>
</application>
</manifest>
——-
MainActivity.java
———-
Code:
package com.ahmadssb.locationgooglemapv2demo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
[user=439709]@override[/user]
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;
}
}
——
activity_main.xml
———-
<
Code:
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
———–
If I get some time, I will try the demo out to help more. I created my google maps app back before you had to import the library.
To me, your manifest looks off.
Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
[B] package="com.ahmadssb.locationgooglemapv2demo"[/B]
android:versionCode="1"
android:versionName="1.0" >
The bold is your package. When you define your activity name, it should either resemble your package plus your activity name. Your activity name doesn't look right (Look at below code).
Code:
<activity
android:name="[B]in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity[/B]"
android:label="@string/app_name" >
You should fix your activity name in your manifest first. Get rid of "in.wptrafficanalyzer.locationgooglemapv2demo" and just leave ".MainActivity" (be sure to leave the period in front of it)
ahmadssb said:
thank you for the link, but I still getting the same error in my phone (Galaxy S 2, ROM CyanogenMod 10.1 )
also using the emulator with 2 AVD for (4.2.2) and (4.2.2 with Google API)
still not working
I start to think (and maybe it is ) that the problem is not from the code the problem is from my phone or the setting in my PC or Eclipse
while any other application is working fine with me except that using google apis key (actually I didn't try any thing that needs api key and this is my first time using it)
BTW this is the result from the tutorial from the link that you gave to me
====================================================
Log:
——-
Code:
04-26 01:28:57.494: D/dalvikvm(5121): Late-enabling CheckJNI
04-26 01:28:57.629: E/Trace(5121): error opening trace file: No such file or directory (2)
04-26 01:28:57.659: D/AndroidRuntime(5121): Shutting down VM
04-26 01:28:57.659: W/dalvikvm(5121): threadid=1: thread exiting with uncaught exception (group=0x41ff7930)
04-26 01:28:57.679: E/AndroidRuntime(5121): FATAL EXCEPTION: main
04-26 01:28:57.679: E/AndroidRuntime(5121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmadssb.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Looper.loop(Looper.java:137)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.main(ActivityThread.java:5226)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.NativeStart.main(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
04-26 01:28:57.679: E/AndroidRuntime(5121): … 11 more
——
You're getting closer
you got enough space, now you're error is this
Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679:
You changed the name of your package, but left the references from the tutorial the same.
switch EVERYTHING that says "in.wptrafficanalyzer....." etc. and change them to "com.ahmadssb......"
the api key stuff doesn't really matter till you get it up and running. If you typed in the wrong api key, your program would still load normally, but you just get a gray background where the map should be.
Click to expand...
Click to collapse
Click to expand...
Click to collapse
Click to expand...
Click to collapse
out of ideas said:
ahmadssb said:
thank you for the link, but I still getting the same error in my phone (Galaxy S 2, ROM CyanogenMod 10.1 )
also using the emulator with 2 AVD for (4.2.2) and (4.2.2 with Google API)
still not working
I start to think (and maybe it is ) that the problem is not from the code the problem is from my phone or the setting in my PC or Eclipse
while any other application is working fine with me except that using google apis key (actually I didn't try any thing that needs api key and this is my first time using it)
BTW this is the result from the tutorial from the link that you gave to me
====================================================
Log:
——-
Code:
04-26 01:28:57.494: D/dalvikvm(5121): Late-enabling CheckJNI
04-26 01:28:57.629: E/Trace(5121): error opening trace file: No such file or directory (2)
04-26 01:28:57.659: D/AndroidRuntime(5121): Shutting down VM
04-26 01:28:57.659: W/dalvikvm(5121): threadid=1: thread exiting with uncaught exception (group=0x41ff7930)
04-26 01:28:57.679: E/AndroidRuntime(5121): FATAL EXCEPTION: main
04-26 01:28:57.679: E/AndroidRuntime(5121): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ahmadssb.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.os.Looper.loop(Looper.java:137)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.main(ActivityThread.java:5226)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-26 01:28:57.679: E/AndroidRuntime(5121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.NativeStart.main(Native Method)
04-26 01:28:57.679: E/AndroidRuntime(5121): Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679: E/AndroidRuntime(5121): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-26 01:28:57.679: E/AndroidRuntime(5121): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
04-26 01:28:57.679: E/AndroidRuntime(5121): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
04-26 01:28:57.679: E/AndroidRuntime(5121): … 11 more
——
You're getting closer
you got enough space, now you're error is this
Caused by: java.lang.ClassNotFoundException: Didn’t find class “in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity” on path: /data/app/com.ahmadssb.locationgooglemapv2demo-1.apk
04-26 01:28:57.679:
You changed the name of your package, but left the references from the tutorial the same.
switch EVERYTHING that says "in.wptrafficanalyzer....." etc. and change them to "com.ahmadssb......"
the api key stuff doesn't really matter till you get it up and running. If you typed in the wrong api key, your program would still load normally, but you just get a gray background where the map should be.
Click to expand...
Click to collapse
thanks for the help
It works now but not after fix the package name only
but I did some modification and organization for libraries something at top and rest bottom also copy the libraries to workplace not use it from the android directory
Actually I don't know exactly how did this works but finally it works :victory:
thank you all for your help
Click to expand...
Click to collapse
Click to expand...
Click to collapse
Click to expand...
Click to collapse

NullPointerException at findPreference

I'm creating a new FragmentPreference and then I want add a OnClickListener to an Preference:
My PreferenceFragment-Class:
Code:
public class PreferencesFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
And my FragmentActivity:
Code:
public class SettingsActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferencesFragment frag = new PreferencesFragment();
getFragmentManager().beginTransaction().replace(android.R.id.content, frag).commit();
Preference deleteLocalDataPref = frag.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
}
OnPreferenceClickListener Pref_OnClickhandler = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
new DeleteSettings().execute();
return false;
}
};
}
And the error:
02-10 08:06:10.598: E/AndroidRuntime(1836): FATAL EXCEPTION: main
02-10 08:06:10.598: E/AndroidRuntime(1836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.SettingsActivity}: java.lang.NullPointerException
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.os.Looper.loop(Looper.java:137)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-10 08:06:10.598: E/AndroidRuntime(1836): at java.lang.reflect.Method.invokeNative(Native Method)
02-10 08:06:10.598: E/AndroidRuntime(1836): at java.lang.reflect.Method.invoke(Method.java:511)
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-10 08:06:10.598: E/AndroidRuntime(1836): at dalvik.system.NativeStart.main(Native Method)
02-10 08:06:10.598: E/AndroidRuntime(1836): Caused by: java.lang.NullPointerException
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.test.SettingsActivity.onCreate(SettingsActivity.java:44)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.Activity.performCreate(Activity.java:5104)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-10 08:06:10.598: E/AndroidRuntime(1836): ... 11 more
Click to expand...
Click to collapse
Why I get a NullPointerException? The Preference does exist...
Code:
<Preference
android:key="deleteLocalData"
android:summary="@string/pref_delete_local_data_summary"
android:title="@string/pref_delete_local_data" />
What happens when you comment the line you think is offending? And which line are you commenting?
Please give a thanks if you think this post helped you!
Sent from my Nexus 4 using XDA Premium 4 Mobile App .
When I comment the lines
Code:
Preference deleteLocalDataPref = frag.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
my preferences are shown correctly.
OK, I changed some parts. This is what works for me:
Code:
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
public class SettingsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
PreferenceFragment preferenceFragment = (PreferenceFragment) getFragmentManager().findFragmentById(R.id.pref_frag_id);
Preference deleteLocalDataPref = preferenceFragment.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
}
Preference.OnPreferenceClickListener Pref_OnClickhandler = new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
new DeleteSettings().execute();
return false;
}
};
}
/res/layout/settings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.example.app.PreferencesFragment"
android:id="@+id/pref_frag_id"/>
</FrameLayout>
(Replace the package name.)
/res/xml/settings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:key="deleteLocalData"
android:summary="@string/pref_delete_local_data_summary"
android:title="@string/pref_delete_local_data" />
</PreferenceScreen>
I changed the way the Fragment is added. If you need to do it dynamically, have a look at a tutorial again and follow it closely.
You don't need to use a PreferenceActivity. The PreferenceFragment kind of replaced it. It is more flexible (it can be added to any kind of Activity) and the PreferenceActivity should only be used for apps which are supposed to work on Android versions below 3.0.

[Q] what the correct way to use ShowcaseView?

when I try to use ShowcaseView I get error
Code:
@override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final ImageButton saveButton = (ImageButton) view.findViewById(R.id.button_Save);
ViewTarget viewTarget = new ViewTarget(saveButton);
showcaseView = new ShowcaseView.Builder(getActivity())
.setTarget(viewTarget)
.setContentTitle("Reset Button")
.setContentText("This will erase all the data in the table except the line that in progress")
.build();
}
when I tried to do the same thing in my fragmentactivity and didn't work, but when I did the same thing but took a view that declared in the fragmentactivity and not in the fragment it worked.
Logcat:
Code:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:724)
at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
at android.graphics.Bitmap.createBitmap(Bitmap.java:670)
at com.github.amlcurran.showcaseview.ShowcaseView.updateBitmap(ShowcaseView.java:169)
at com.github.amlcurran.showcaseview.ShowcaseView.onGlobalLayout(ShowcaseView.java:343)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:839)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2050)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
I understand what the error said but how can I fix it?

[Q] New Dev trying to figure out what is probably a simple problem

I am getting a NullPointerException after the build but once my phone tries to launch the app. I do not understand where the problem is. Im just learning to code and this app is simply supposed to make a toast pop up Long if the checkbox is clicked and short if it isnt.
Code:
package universaltruth.toastee;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
public CheckBox longToast = (CheckBox) findViewById(R.id.checkbox);
public EditText editText = (EditText) findViewById(R.id.toastText);
public int toastLength = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnlongToast();
}
public void addListenerOnlongToast(){
longToast.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if(((CheckBox) view).isChecked()){
toastLength = '1';
}
}
});
}
public void toastMessage(View view){
String message = editText.getText().toString();
Toast.makeText(getApplicationContext(),message, (toastLength == 0) ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
LogCat:
02-08 12:48:34.718 6684-6684/universaltruth.toastee D/AndroidRuntime﹕ Shutting down VM
02-08 12:48:34.718 6684-6684/universaltruth.toastee W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4191bda0)
02-08 12:48:34.718 6684-6684/universaltruth.toastee E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: universaltruth.toastee, PID: 6684
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{universaltruth.toastee/universaltruth.toastee.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5748)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:2014)
at universaltruth.toastee.MainActivity.<init>(MainActivity.java:19)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
************at android.app.ActivityThread.access$900(ActivityThread.java:174)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:146)
************at android.app.ActivityThread.main(ActivityThread.java:5748)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:515)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
************at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
************at dalvik.system.NativeStart.main(Native Method)
02-08 13:00:50.672 9121-9121/universaltruth.toastee I/SELinux﹕ Function: selinux_android_load_priority , priority [3] , priority version is VE=SEPF_SM-N910F_4.4.4_A024
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/SELinux﹕ [DEBUG] get_category: variable seinfocat: default sensitivity: NULL, cateogry: NULL
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/dalvikvm﹕ >>>>> Normal User
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/dalvikvm﹕ >>>>> universaltruth.toastee [ userId:0 | appId:10384 ]
02-08 13:00:50.682 9121-9121/universaltruth.toastee E/SELinux﹕ [DEBUG] get_category: variable seinfocat: default sensitivity: NULL, cateogry: NULL
02-08 13:00:50.682 9121-9121/universaltruth.toastee D/dalvikvm﹕ Late-enabling CheckJNI
02-08 13:00:50.682 9121-9121/universaltruth.toastee I/libpersona﹕ KNOX_SDCARD checking this for 10384
02-08 13:00:50.682 9121-9121/universaltruth.toastee I/libpersona﹕ KNOX_SDCARD not a persona
02-08 13:00:50.752 9121-9121/universaltruth.toastee D/TimaKeyStoreProvider﹕ in addTimaSignatureService
02-08 13:00:50.762 9121-9121/universaltruth.toastee D/TimaKeyStoreProvider﹕ Cannot add TimaSignature Service, License check Failed
02-08 13:00:50.762 9121-9121/universaltruth.toastee D/ActivityThread﹕ Added TimaKesytore provider
02-08 13:00:50.922 9121-9121/universaltruth.toastee D/AndroidRuntime﹕ Shutting down VM
02-08 13:00:50.922 9121-9121/universaltruth.toastee W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4191bda0)
02-08 13:00:50.922 9121-9121/universaltruth.toastee E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: universaltruth.toastee, PID: 9121
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{universaltruth.toastee/universaltruth.toastee.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5748)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:2014)
at universaltruth.toastee.MainActivity.<init>(MainActivity.java:16)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
************at android.app.ActivityThread.access$900(ActivityThread.java:174)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:146)
************at android.app.ActivityThread.main(ActivityThread.java:5748)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:515)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
************at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
************at dalvik.system.NativeStart.main(Native Method)
02-08 13:00:55.232 9121-9121/universaltruth.toastee I/Process﹕ Sending signal. PID: 9121 SIG: 9
Forgive me if I am not posting this correctly. This is my first time. I am open to any and all feedback. Thank you.
Your problem is that you initialize the longToast checkbox outside of a method. But findViewById only returns a result if called after a call to setContentView(...), which is done in onCreate. So: put your initialization code into onCreate, after setContentView and it will work fine
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Masrepus said:
Your problem is that you initialize the longToast checkbox outside of a method. But findViewById only returns a result if called after a call to setContentView(...), which is done in onCreate. So: put your initialization code into onCreate, after setContentView and it will work fine
Click to expand...
Click to collapse
Hey Masrepus,
Thanks a bunch for answering me.
I have moved the initializations to the on create after the setContentView. I am still getting the null pointer exception. Do you have any further advice?
UniversalTruth said:
Hey Masrepus,
Thanks a bunch for answering me.
I have moved the initializations to the on create after the setContentView. I am still getting the null pointer exception. Do you have any further advice?
Click to expand...
Click to collapse
Can you edit the first post with the new code (and new logcat)?
Yes, grab a new log and post it on pastebin
Then link the log from here

[Q] App keeps crashing when starting activity

My app keeps crashing when I try to start this activity. It is the Kit Kat easter egg. here is the code:
Code:
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Bon Appetit!",
Toast.LENGTH_LONG).show();
Intent dessert = new Intent("com.android.systemui.DessertCase");
startActivity(dessert);
}
here is the logcat:
04-06 22:57:26.607 31168-31168/com.jonanomisk.dessert E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.jonanomisk.dessert, PID: 31168
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19748)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
************at android.view.View.performClick(View.java:4756)
************at android.view.View$PerformClick.run(View.java:19748)
************at android.os.Handler.handleCallback(Handler.java:739)
************at android.os.Handler.dispatchMessage(Handler.java:95)
************at android.os.Looper.loop(Looper.java:135)
************at android.app.ActivityThread.main(ActivityThread.java:5254)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.systemui.DessertCase }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)
at android.app.Activity.startActivityForResult(Activity.java:3736)
at android.app.Activity.startActivityForResult(Activity.java:3697)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:4007)
at android.app.Activity.startActivity(Activity.java:3975)
at com.jonanomisk.dessert.MainActivity.onClick(MainActivity.java:50)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at android.view.View$1.onClick(View.java:4002)
************at android.view.View.performClick(View.java:4756)
************at android.view.View$PerformClick.run(View.java:19748)
************at android.os.Handler.handleCallback(Handler.java:739)
************at android.os.Handler.dispatchMessage(Handler.java:95)
************at android.os.Looper.loop(Looper.java:135)
************at android.app.ActivityThread.main(ActivityThread.java:5254)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Click to expand...
Click to collapse
Thanks!
JonanomisK said:
My app keeps crashing when I try to start this activity. It is the Kit Kat easter egg. here is the code:
Code:
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Bon Appetit!",
Toast.LENGTH_LONG).show();
Intent dessert = new Intent("com.android.systemui.DessertCase");
startActivity(dessert);
}
here is the logcat:
Thanks!
Click to expand...
Click to collapse
Code:
at com.jonanomisk.dessert.MainActivity.onClick(MainActivity.java:50)
Line 50 is causing the issues - not sure which line it is but I can see a problem in your intent line. Try the below code:
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.systemui", "com.android.systemui.DessertCase");
startActivity(intent);
Jonny said:
Code:
at com.jonanomisk.dessert.MainActivity.onClick(MainActivity.java:50)
Line 50 is causing the issues - not sure which line it is but I can see a problem in your intent line. Try the below code:
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.systemui", "com.android.systemui.DessertCase");
startActivity(intent);
Click to expand...
Click to collapse
Thanks man that worked great!
JonanomisK said:
Thanks man that worked great!
Click to expand...
Click to collapse
Hoped it would - your problem was that you need to pass a context to the intent - usually for starting activities within your own app you can use "this" as the context - so it would be:
Code:
new Intent(this, "SomeActivity.class");
But the package that the easter egg is under is com.android.systemui so that's what you have to set the class name using that as the context:
Code:
intent.setClassName("com.android.systemui", "com.android.systemui.DessertCase");

Categories

Resources