2013-05-29 78 views
0

所以我开发了一个应用程序,想将其上传到Play商店,但是当它说我必须更改包名称不同来自com.example.app_name我改变了它。 但现在我得到一个错误:java.lang.IllegalStateException:更改包名后无法执行活动错误的方法

05-29 22:35:15.599: E/AndroidRuntime(2196): java.lang.IllegalStateException: Could not execute method of the activity 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.view.View$1.onClick(View.java:3039) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.view.View.performClick(View.java:3480) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.view.View$PerformClick.run(View.java:13983) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.os.Handler.handleCallback(Handler.java:605) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.os.Handler.dispatchMessage(Handler.java:92) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.os.Looper.loop(Looper.java:137) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.app.ActivityThread.main(ActivityThread.java:4340) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at java.lang.reflect.Method.invokeNative(Native Method) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at java.lang.reflect.Method.invoke(Method.java:511) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at dalvik.system.NativeStart.main(Native Method) 
05-29 22:35:15.599: E/AndroidRuntime(2196): Caused by: java.lang.reflect.InvocationTargetException 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at java.lang.reflect.Method.invokeNative(Native Method) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at java.lang.reflect.Method.invoke(Method.java:511) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at android.view.View$1.onClick(View.java:3034) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  ... 11 more 
05-29 22:35:15.599: E/AndroidRuntime(2196): Caused by: java.lang.NullPointerException 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at com.gip.icomplain.Home.getGPSLocation(Home.java:209) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  at com.gip.icomplain.Home.send(Home.java:130) 
05-29 22:35:15.599: E/AndroidRuntime(2196):  ... 14 more 

这里是我的代码:

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.setContentView(R.layout.activity_home); 

     LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     imv = (ImageView) findViewById(R.id.imvFoto); 
     onderwerp = (TextView) findViewById(R.id.txtSubject); 
     commentaar = (TextView) findViewById(R.id.txtComment); 
     if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ 
      showGPSDisabledAlertToUser(); 
     } 
    } 
    public void getGPSLocation() { 
     if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ 
      showGPSDisabledAlertToUser(); 
     } 
     LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener()); 
     currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 

     if (currentLocation != null) { 
      longitude = currentLocation.getLongitude(); 
      latitude = currentLocation.getLatitude(); 
     } 
     EXTRA_TEXT = "http://maps.google.com/maps?q=" + latitude + "," + longitude; 
    } 
} 

请帮帮忙,这是非常重要的!!!!

+0

您是否在ANdroidManifest.xml中更改了包名? – Blackbelt

+0

是的,我做过, 我认为它与我的locationManager有关 –

+0

如果你使用eclipse,你可以使用'refractor'来重命名。如果需要的话,它会照顾到每个飞行员的变化。 –

回答

0

你得到一个NullPointerException你getGPSLocation,在您的locationManager这里:

if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ 
    showGPSDisabledAlertToUser(); 
} 

您应该移动已经的locationManager(删除类型LocationManager)无论是在onCreategetGPSLocation重新声明:

@Override 
public void onCreate(Bundle savedInstanceState) { 
... 
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
// Instead of: 
// LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
... 
} 

public void getGPSLocation() { 
... 
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
// Instead of: 
// LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
... 
} 

顺便说一句,你还应该每

之前检查的LocationManager的空值

if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){

+0

很高兴为您提供帮助! –

1

您将locationManager作为类成员,但在onCreate中重新声明它。这样你隐藏了memeber类,它永远不会被初始化。

在getGpsLocation()你使用这种方式

然后:

public void getGPSLocation() { 
     if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ 
      showGPSDisabledAlertToUser(); 
     } 

从的onCreate

删除 LocationManager
@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.setContentView(R.layout.activity_home); 

     locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
+0

omfg,非常感谢! 不能拇指你,没有15代表... 如果我能我会给你一千,你救了我的屁股在这里! –

+0

正如我在我的回答中所说的,你也应该从'getGPSlocation'中移除它,因为它也隐藏了成员类。 –

+0

欢迎你,欢迎在stackoverflow – Blackbelt

相关问题