2014-11-24 2 views
0

В моем приложении я открываю активность из службы каждые 1 минуту, если в веб-службе у меня есть некоторые данные. теперь в этом моем коде я иногда получаю эту ошибку ниже. после поиска в любом документе об этой ошибке и приложении трассировки я могу найти причину этой ошибки.Активность Android ComponentInfo

полный журнал кошка:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.ServiceDialog}: java.lang.NullPointerException: println needs a message 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 
    at android.app.ActivityThread.access$600(ActivityThread.java:156) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:153) 
    at android.app.ActivityThread.main(ActivityThread.java:5297) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException: println needs a message 
    at android.util.Log.println_native(Native Method) 
    at android.util.Log.e(Log.java:231) 
    at com.example.ServiceDialog.onCreate(ServiceDialog.java:195) 
    at android.app.Activity.performCreate(Activity.java:5122) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
    ... 11 more 
java.lang.NullPointerException: println needs a message 
    at android.util.Log.println_native(Native Method) 
    at android.util.Log.e(Log.java:231) 
    at com.example.ServiceDialog.onCreate(ServiceDialog.java:195) 
    at android.app.Activity.performCreate(Activity.java:5122) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 
    at android.app.ActivityThread.access$600(ActivityThread.java:156) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:153) 
    at android.app.ActivityThread.main(ActivityThread.java:5297) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
    at dalvik.system.NativeStart.main(Native Method) 

моя активность:

public class ServiceDialog extends Activity { 

    private Context ctx; 
    private String count; 
    private Boolean ps; 
    private Boolean sn; 
    private String mLastID; 
    private String mSmsNumber; 
    private String mMobileNumber; 
    private String mContactName; 
    private String mSmsBody; 
    private String mSenderName; 
    private String mDate; 
    private MediaPlayer sms_music; 
    private PowerManager.WakeLock wakeLock; 
    private TextView count_sms; 
    private Intent intent; 
    MyResultReceiver resultReceiver; 
    private ContentResolver contentResolver; 
    private boolean getCurrentActivity; 
    private LinearLayout open_app; 
    private TextView content; 
    private TextView title; 
    private TextView tv_date_time; 
    private TextView tv_name_family; 
    private TextView te_sms_text; 
    private TextView tv_phone_number; 
    private TextView title; 
    private LinearLayout main_window; 
    private Integer notify = 0; 
    private Integer unread_messages = 0; 
    @Override 
    public void onCreate (Bundle savedInstanceState) { 
     super.onCreate (savedInstanceState); 
     requestWindowFeature (Window.FEATURE_NO_TITLE); 
     getWindow().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView (R.layout.service_view_dialog); 

     ctx = getBaseContext(); 
     G.redirect = false; 
     /* Set current Activity runnable with this activity class */ 
     G.activity = this; 

     title     = (TextView) findViewById (R.id.tv_title); 
     content    = (TextView) findViewById (R.id.content); 
     count_sms    = (TextView) findViewById (R.id.tv_count_new_sms); 
     tv_date_time   = (TextView) findViewById (R.id.tv_date_time); 
     tv_name_family  = (TextView) findViewById (R.id.tv_name_family); 
     tv_phone_number  = (TextView) findViewById (R.id.tv_phone_number); 
     te_sms_text   = (EditText) findViewById (R.id.te_sms_text); 

     title.setText   (ctx.getResources().getString (R.string.count_new_sms_received)); 

     main_window   = (LinearLayout) findViewById (R.id.main_window); 

     int count = 0; 
     int unread= 0; 
     if (savedInstanceState == null) { 
      Bundle extras = getIntent().getExtras(); 
      if (extras == null) { 
       count = 0; 
      } else { 
       G.config_username = extras.getString ("username"); 
       G.config_password = extras.getString ("password"); 
       unread_messages = extras.getInt ("unread" ); 
       notify   = extras.getInt ("notify" ); 
       G.db    = new DatabaseHandler (getBaseContext()); 
      } 
     } 
     contentResolver = ctx.getContentResolver(); 
     Button send_sms    = (Button) findViewById (R.id.send_sms); 

     open_app      = (LinearLayout) findViewById (R.id.open_app); 
     LinearLayout delete   = (LinearLayout) findViewById (R.id.delete); 
     LinearLayout forward   = (LinearLayout) findViewById (R.id.forward); 


     ps = Configuration.getInstance().getBoolean (getApplication(), Configuration.SharedPrefsTypes.PLAY_SOUND); 

     sn = Configuration.getInstance().getBoolean (getApplication(), Configuration.SharedPrefsTypes.SHOW_NOTOFICATION); 
     //Log.e("Notification State is : ", sn+""); 

     count_sms.setText(unread_messages +""); 
     new LongOperation().execute (unread_messages); 
     notification(); 


     WindowManager.LayoutParams params = getWindow().getAttributes(); 
     params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; 
     params.screenBrightness = 1.0f; 
     getWindow().setAttributes(params); 

     PowerManager powermanager = ((PowerManager)ctx.getSystemService(Context.POWER_SERVICE)); 
     wakeLock=powermanager.newWakeLock(
       PowerManager.SCREEN_BRIGHT_WAKE_LOCK | 
         PowerManager.ACQUIRE_CAUSES_WAKEUP, "TsmsScreenOn"); 
     wakeLock.acquire(); 

     resultReceiver = new MyResultReceiver(null); 
     intent = new Intent(this, ToobaPayamakService.class); 
     intent.putExtra("receiver", resultReceiver); 
     startService(intent); 
    } 

    public void updateAndIntertDialog(Integer received_count){ 
     Cursor cursor  = G.db.getSingleRowReceivedFromDatabase(G.config_username); 
     if (cursor != null && cursor.getCount() != 0) { 
      if (cursor.moveToFirst()) { 
       mLastID  = cursor.getString(2); 
       mSmsBody  = cursor.getString(7); 
       mSenderName = cursor.getString(5); 
       mDate   = cursor.getString (9); 
       mSmsNumber = cursor.getString(3); 
       mContactName = G.getContentNameFromContactList(mSenderName,contentResolver); 
       if(TextUtils.isEmpty(mContactName)) 
        /* if contact name not exist in contact show resolve by service */ 
        mContactName = mSenderName; 
      } 
     } 
     cursor.close(); 
     //Log.e("LAST ID FOE CHECK -------------",mLastID); 
     tv_name_family.setText (mContactName); 
     tv_phone_number.setText (mSmsNumber); 
     tv_date_time.setText (mDate.substring(11, 16)); 
     mMobileNumber = G.getContactMobile (mContactName); 
     content.setText  (mSmsBody); 

     getCurrentActivity = Configuration.getInstance() 
       .getBoolean (getApplication(), 
         Configuration.SharedPrefsTypes.ACTIVITY_IS_RUNNING); 
     Log.e("Activity is : ", getCurrentActivity+""); 
     if(getCurrentActivity){ 
      try{ 
       G.fillItems (contentResolver); 
      }catch (Exception e){ 
       Log.e ("Fill Items in ServiceDialog", e.getMessage()); 
      } 
     } 

     main_window.setVisibility (View.VISIBLE); 
    } 

    private class LongOperation extends AsyncTask<Integer, Void, Integer> { 
     @Override 
     protected Integer doInBackground(Integer... params) { // params[0] is unread; 
      int result = 0; 
      try { 
       if(G.checkInternetConnection()) { 
        G.getRequestFromServer (0, params[ 0 ], contentResolver); 
        result = params[0]; 
       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
      return result; 
     } 

     @Override 
     protected void onPostExecute(Integer result) { 
      if(result != 0) { 
       updateAndIntertDialog(result); 
      } 
     } 
     @Override 
     protected void onPreExecute() {} 

     @Override 
     protected void onProgressUpdate(Void... values) {} 
    } 

    class UpdateUI implements Runnable{ 
     String received_count; 

     public UpdateUI(String received_count) { 
      this.received_count = received_count; 
     } 
     public void run() { 
      new LongOperation().execute (Integer.valueOf (received_count)); 
     } 
    } 

    class MyResultReceiver extends ResultReceiver{ 
     public MyResultReceiver(Handler handler) { 
      super(handler); 
     } 

     @Override 
     protected void onReceiveResult(int resultCode, Bundle resultData) { 
      runOnUiThread(new UpdateUI(""+resultCode)); 
     } 
    } 

} 

линия 195 является:

protected void onPreExecute() {} 

ответ

0

инициализации

private boolean getCurrentActivity = false; 

Изменить код,

Log.e("Activity is : ", getCurrentActivity+""); 

по

Log.e("Activity is : ", Boolean.toString(getCurrentActivity)); 

&

Log.e ("Fill Items in ServiceDialog", e.getMessage()); 

по

Log.e("Fill Items in ServiceDialog", "I got an error", e); 

надеюсь, t поможет вам

1

Проблема заключается в синтаксисе AsyncTask.

изменение порядка AsyncTask

  1. onPreExecute()
  2. doInBackground()
  3. onProgressUpdate()
  4. onPostExecute()
Смежные вопросы