I'm just here to confirm what the other two coders told you ~ I found
it on first read place a catch( Throwable ) around the call
to .print_result(MyService.
java:62) and look at line 62 in MyService but before you even try that
do Object someObject= ((val=null)?("error"):(val)) all over code as
what you are looking for is a result of many design types telling
people that code handles nulls

it doesn't = you have to go look for it and find it

when you do, fix it some way.....

On Nov 23, 7:46 am, Graham Bright <gbwienmobil...@gmail.com> wrote:
> Hi I am getting FATAL EXCEPTION when the ArrayList items is
> populated;
>
> can you help ?
>
> Thanks
> Graham
>
> W/dalvikvm(11235): threadid=9: thread exiting with uncaught exception
> (group=0x4
> 001e578)
> E/AndroidRuntime(11235): FATAL EXCEPTION: Thread-10
> E/AndroidRuntime(11235): java.lang.NullPointerException
> E/AndroidRuntime(11235):        at
> com.example.MyService.print_result(MyService.
> java:62)
> E/AndroidRuntime(11235):        at com.example.MyService
> $1.run(MyService.java:54
> )
> E/AndroidRuntime(11235):        at java.lang.Thread.run(Thread.java:
> 1019)
> W/ActivityManager( 2696):   Force finishing activity
> com.example/.ServicesDemo
> I/OrientationDebug( 2696): [pwm] in updateOrientationListenerLp()
> V/OrientationDebug( 2696): in updateOrientationListenerLp(), Screen
> status=true,
>  current orientation=1, SensorEnabled=true
> I/OrientationDebug( 2696): [pwm] needSensorRunningLp(), return true #4
> I/Launcher( 2852): onResume(). mIsNewIntent : false screenOff: false
> E/        ( 2696): Dumpstate > /data/log/dumpstate_app_error
> I/dumpstate(11275): begin
> D/KeyguardViewMediator( 2696): handleTimeout
> W/PowerManagerService( 2696): Timer 0x3->0x3|0x3
>
> package com.example;
>
> import java.util.ArrayList;
>
> import android.app.Service;
> import android.content.Intent;
> import android.os.Bundle;
> import android.os.IBinder;
> import android.util.Log;
> import android.widget.Toast;
>
> public class MyService extends Service {
>
> ArrayList<String> items = null;
>
> public String ORIG = "";
> private static final String TAG = "MyService";
> public Bundle data = new Bundle();
>
> @Override
> public IBinder onBind(Intent intent) {
> return null;
>
> }
>
> public static String getTag() {
> return TAG;
>
> }
>
> @Override
> public void onCreate() {
> Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
>
> }
>
> @Override
> public void onDestroy() {
> Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
> Log.d(TAG, "onDestroy");
>
> }
>
> @Override
> public void onStart(Intent intent, int startid) {
> Log.d(TAG, "onStart");
> data = intent.getExtras();
> ORIG = data.getString("originator");
> Log.d(TAG, "onCreate");
> Thread initBkgdThread = new Thread(new Runnable() {
> public void run() {
> print_result(ORIG);}
> });
>
> initBkgdThread.start();
>
> }
>
> public void print_result(String orig){
> Log.d(TAG, "HELLO WORLD:" + orig);
> items.add(orig);
> if (items != null) {
> items.add(orig);
> String toadd = orig.toString();
>
> if(items.contains(toadd)){
> Log.d(TAG, "Element already exists exiting ");} else {
>
> Log.d(TAG, "Adding Element");
>     items.add(toadd);
>
> }
> }
>
> else {
> Log.d(TAG, "IS NULL");
>
> }
> }
> }
>
> On 23 Nov., 12:53, Kostya Vasilyev <kmans...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Look below "caused by" in the logcat to identify where the
> > NullPointerException occurrs. Then fix it.
>
> > 23 ÎÏÑÂÒÑ 2011 Ç. 15:36 ÐÏÌØÚÏ×ÁÔÅÌØ Graham Bright <gbwienmobil...@gmail.com
>
> > > ÎÁÐÉÓÁÌ:
> > > Can anyone help?
>
> > > Thanks
> > > Graham
> > > On Nov 23, 2011 11:51 a.m., "Graham Bright" <gbwienmobil...@gmail.com>
> > > wrote:
>
> > >> Hi,
>
> > >> I am creating service which will run in the background and contain a
> > >> blocking list š(implemented using ArrayList) which may be used later
> > >> by other activites.
>
> > >> My Problem:-
>
> > >> From my activity Services Demo I pass data to my service using
>
> > >> dataIntent.putExtra("originator", x);
>
> > >> this is fine but when I try to store this data in my Service in an
> > >> ArrayList called Items I get an exception and I cannot figure out
> > >> why.
>
> > >> The problem is in my Service code MyService :
>
> > >> š š š š š š š šif(items.contains(ORIG)){
> > >> š š š š š š š š š š š šLog.d(TAG, "Element already exists exiting ");
> > >> š š š š š š š š} else {
> > >> š š š š š š š š š š š šLog.d(TAG, "Adding Element");
> > >> š š š š š š š š š šitems.add(ORIG);
>
> > >> š š š š š š š š}
> > >> Please help.
>
> > >> EXCEPTION
> > >> java.lang.RuntimeException: Unable to start service ...... with
> > >> intent
>
> > >> caused by: java.lang.NullPointerException
>
> > >> Best Regards,
>
> > >> Graham
>
> > >> CODE Eclipse
>
> > >> Activity -> ServicesDemo
> > >> Service -> MyService
>
> > >> ACTIVITY ServicesDemo
>
> > >> package com.example;
>
> > >> import android.app.Activity;
> > >> import android.content.Intent;
> > >> import android.os.Bundle;
> > >> import android.util.Log;
> > >> import android.view.View;
> > >> import android.view.View.OnClickListener;
> > >> import android.widget.Button;
> > >> import android.widget.EditText;
>
> > >> public class ServicesDemo extends Activity implements OnClickListener
> > >> {
> > >> šprivate static final String TAG = "ServicesDemo";
> > >> šButton buttonStart, buttonStop;
> > >> šEditText Input;
> > >> šString x = ""; š//test pass to my service
>
> > >> š@Override
> > >> špublic void onCreate(Bundle savedInstanceState) {
> > >> š šsuper.onCreate(savedInstanceState);
> > >> š šsetContentView(R.layout.main);
>
> > >> š šbuttonStart = (Button) findViewById(R.id.buttonStart);
> > >> š šbuttonStop = (Button) findViewById(R.id.buttonStop);
> > >> š šInput = (EditText) findViewById(R.id.INPUT);
> > >> š šbuttonStart.setOnClickListener(this);
> > >> š šbuttonStop.setOnClickListener(this);
>
> > >> š}
>
> > >> špublic void onClick(View src) {
> > >> š šswitch (src.getId()) {
> > >> š šcase R.id.buttonStart:
> > >> š š šLog.d(TAG, "onClick: starting srvice");
> > >> š š šIntent dataIntent = new Intent(ServicesDemo.this,
> > >> MyService.class);
> > >> š š šx = Input.getText().toString();
> > >> š š šdataIntent.putExtra("originator", x);
> > >> š š šstartService(dataIntent);
>
> > >> š š šbreak;
>
> > >> š šcase R.id.buttonStop:
>
> > >> š š šLog.d(TAG, "onClick: stopping srvice");
> > >> š š š//implicit starting
> > >> š š šstopService(new Intent(this, MyService.class));
> > >> š š šbreak;
> > >> š š}
> > >> š}
>
> > >> public static String getTag() {
> > >> š š š šreturn TAG;
> > >> }
> > >> }
> > >> -----------------------------------<end ACTIVITY>
>
> > >> --Service MyService ---------
> > >> package com.example;
>
> > >> import java.util.ArrayList;
>
> > >> import android.app.Service;
> > >> import android.content.Intent;
> > >> import android.os.Bundle;
> > >> import android.os.IBinder;
> > >> import android.util.Log;
> > >> import android.widget.Toast;
>
> > >> public class MyService extends Service {
>
> > >> š š š šArrayList<String> items;
>
> > >> š š š špublic String ORIG = "";
> > >> š š š šprivate static final String TAG = "MyService";
> > >> š š š špublic Bundle data = new Bundle();
>
> > >> š š š š@Override
> > >> š š š špublic IBinder onBind(Intent intent) {
> > >> š š š š š š š šreturn null;
> > >> š š š š}
>
> > >> š š š špublic static String getTag() {
> > >> š š š š š š š šreturn TAG;
> > >> š š š š}
>
> > >> š š š š@Override
> > >> š š š špublic void onCreate() {
> > >> š š š š š š š šToast.makeText(this, "My Service Created",
> > >> Toast.LENGTH_LONG).show();
> > >> š š š š š š š šLog.d(TAG, "onCreate");
>
> > >> š š š š}
>
> > >> š š š š@Override
> > >> š š š špublic void onDestroy() {
> > >> š š š š š š š šToast.makeText(this, "My Service Stopped",
> > >> Toast.LENGTH_LONG).show();
> > >> š š š š š š š šLog.d(TAG, "onDestroy");
>
> > >> š š š š}
>
> > >> š š š š@Override
> > >> š š š špublic void onStart(Intent intent, int startid) {
> > >> š š š š š š š šLog.d(TAG, "onStart");
> > >> š š š š š š š šdata = intent.getExtras();
> > >> š š š š š š š šORIG = data.getString("originator");
> > >> š š š š š š š šToast.makeText(this, "My Service Started with passed in
> > >> value " +
> > >> ORIG, Toast.LENGTH_LONG).show();
> > >> š š š š š š š šif(items.contains(ORIG)){
> > >> š š š š š š š š š š š šLog.d(TAG, "Element already exists exiting ");
> > >> š š š š š š š š} else {
> > >> š š š š š š š š š š š šLog.d(TAG, "Adding Element");
> > >> š š š š š š š š š šitems.add(ORIG);
>
> > >> š š š š š š š š}
>
> > >> š š š š š š š šThread initBkgdThread = new Thread(new Runnable() {
> > >> š š š š š š š š š š š špublic void run() {
> > >> š š š š š š š š š š š š š š š š//print_result();
> > >> š š š š š š š š š š š š}
> > >> š š š š š š š š š š š š});
> > >> š š š š š š š š š š š šinitBkgdThread.start();
>
> > >> š š š š}
>
> > >> š š š špublic void print_result(String orig){
> > >> š š š š š š š šLog.d(TAG, "HELLO WORLD:" + orig);
>
> > >> š š š š}
>
> > >> }
>
> > >> --------------end of service-----------
>
> > > š--
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en-Zitierten Text 
> > >ausblenden -
>
> > - Zitierten Text anzeigen -

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to