2011-01-15 6 views
3

에뮬레이터에서 다시 만들 수없는 몇 가지 문제점이 있습니다.하지만 해결 방법이없는 안드로이드 마켓에서 오류 보고서가 계속 나오고 있습니다. 다른 사용자가 이드를 볼 수도 있습니다. 때때로이NullPointerException 위치를 얻는 경우

java.lang.NullPointerException 
at android.webkit.WebViewDatabase.getCacheTotalSize(WebViewDatabase.java:734) 
at android.webkit.CacheManager.trimCacheIfNeeded(CacheManager.java:548) 
at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:190) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:123) 
at android.os.HandlerThread.run(HandlerThread.java:60) 

때로는이 보고서를 reposrts

들거 greatful 수

java.lang.RuntimeException: Unable to start activity ComponentInfo{polis.koll/polis.koll.WebPageLoader}: java.lang.IllegalArgumentException: provider==null 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753) 
at android.app.ActivityThread.access$2500(ActivityThread.java:129) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:143) 
at android.app.ActivityThread.main(ActivityThread.java:4701) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:521) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.IllegalArgumentException: provider==null 
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:625) 
at polis.koll.WebPageLoader.getLocation(WebPageLoader.java:54) 
at polis.koll.WebPageLoader.onCreate(WebPageLoader.java:70) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701) 
,

여기에 내 코드

public class WebPageLoader extends Activity implements LocationListener{ 
    public static String Android_ID = null; 
    final Activity activity = this; 
    private Location mostRecentLocation; 

    private void CheckEnableGPS(){ 
     String provider = Settings.Secure.getString(getContentResolver(), 
      Settings.Secure.LOCATION_PROVIDERS_ALLOWED); 
      if(!provider.equals("")){ 
       //GPS Enabled 
       getLocation(); 
      }else{ 
      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
       startActivity(intent); 
      } 

     } 


private void getLocation() { 
    String provider = Settings.Secure.getString(getContentResolver(), 
      Settings.Secure.LOCATION_PROVIDERS_ALLOWED); 
      if(!provider.equals("")){ 
    LocationManager locationManager = 
     (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    Criteria criteria = new Criteria(); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE); 
    String bestprovider = locationManager.getBestProvider(criteria,true); 
    locationManager.requestLocationUpdates(bestprovider, 1, 500, this);  
    mostRecentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     }else{ 
      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
       startActivity(intent); 
      } 
    } 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    //AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR }); 
    super.onCreate(savedInstanceState); 
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS); 
    setContentView(R.layout.main); 

    getLocation(); 
    Android_ID = Secure.getString(getContentResolver(), Secure.ANDROID_ID); 


    WebView webView = (WebView) findViewById(R.id.webView); 
    webView.getSettings().setJavaScriptEnabled(true); 
    /** Allows JavaScript calls to access application resources **/ 
    webView.addJavascriptInterface(new JavaScriptInterface(), "android16"); 
    webView.setWebChromeClient(new WebChromeClient() { 
     public void onProgressChanged(WebView view, int progress) 
     { 
      activity.setTitle("Letar poliskontroller"); 
      activity.setProgress(progress * 100); 


      if(progress == 100) 
       activity.setTitle(R.string.app_name); 
     } 
    }); 


    webView.setWebViewClient(new WebViewClient() { 

     @Override 
     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) 
     { 
      // Handle the error 
     } 


    // Testade att ta bort denna override för att få market länkar att fungera 
    // @Override 
    // public boolean shouldOverrideUrlLoading(WebView view, String url) 
    // { 
    //  view.loadUrl(url); 
    //  return true; 
    // } 
    }); 

    if (Locale.getDefault().getLanguage().equals("sv")){ 
    //webView.loadUrl("file:///android_asset/android.html"); 
     webView.loadUrl("file:///android_asset/findgps_sv.html"); 
    }else{ 
    //webView.loadUrl("http://m.bryggplatsen.se/android/polis/index.php"); 
    //webView.loadUrl("file:///android_asset/android_en.html"); 
     webView.loadUrl("file:///android_asset/findgps_en.html"); 
    } 



} 
    /** Sets up the interface for getting access to Latitude and Longitude data from device 
    **/ 




private class JavaScriptInterface { 
    public double getLatitude(){ 
     return mostRecentLocation != null ? mostRecentLocation.getLatitude() : Double.NaN; 
    } 

    public double getLongitude(){ 
     return mostRecentLocation != null ? mostRecentLocation.getLongitude() : Double.NaN; 
    } 


    public String getAndroid_ID(){ 
     return Android_ID; 
    } 

    public void sharethisapp(){ 
    startActivity(Intent.createChooser(sharespotIntent(), "Share this warning")); 
    } 
    } 


@Override 
public void onLocationChanged(Location location) { 
    // TODO Auto-generated method stub 

    getLocation(); 
    //CheckEnableGPS(); 
} 

@Override 
public void onProviderDisabled(String provider) { 
    // TODO Auto-generated method stub 
    getLocation(); 
} 

@Override 
public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 
    getLocation(); 
} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
    // TODO Auto-generated method stub 
    getLocation(); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    super.onCreateOptionsMenu(menu); 
    MenuItem item = menu.add("Shut down"); 
    item.setIcon(R.drawable.exit); 

    item = menu.add("Share"); 
    item.setIcon(R.drawable.m_share); 

    item = menu.add("Fix GPS"); 
    item.setIcon(R.drawable.globe); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    if (item.getTitle() == "Shut down") { 
     System.exit(0); 
     finish(); 
    } 
    if (item.getTitle() == "Fix GPS") { 
     getLocation(); 
    } 
    if (item.getTitle() == "Share") { 
     if (Locale.getDefault().getLanguage().equals("sv")){ 
     startActivity(Intent.createChooser(shareIntent(), "Dela denna app")); 
     }else{ 
     startActivity(Intent.createChooser(shareIntent(), "Share this app")); 
     } 
    } 
    return true; 
} 

private Intent shareIntent() { 
     Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
     shareIntent.setType("text/plain");  
    if (Locale.getDefault().getLanguage().equals("sv")){ 
     shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Testa denna android app..."); 
     return shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "index.php"); 
    }else{ 
     shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try this cool android app..."); 
     return shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "index_en.php");   
    } 

} 


private Intent sharespotIntent() { 
    Intent sharespotIntent = new Intent(android.content.Intent.ACTION_SEND); 
    sharespotIntent.setType("text/plain");  
if (Locale.getDefault().getLanguage().equals("sv")){ 
    sharespotIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " la just upp en ny varning i appen Polisradar"); 
    return sharespotIntent.putExtra(android.content.Intent.EXTRA_TEXT, "warn.php?lat=" + mostRecentLocation.getLatitude() + "&lng=" + mostRecentLocation.getLongitude() + ""); 
}else{ 
    sharespotIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " just added a new warning in the app Policeradar"); 
    return sharespotIntent.putExtra(android.content.Intent.EXTRA_TEXT, "warn_en.php?lat=" + mostRecentLocation.getLatitude() + "&lng=" + mostRecentLocation.getLongitude() + "");  
    } 
} 

}

+0

귀하의 잘못이 아닌 것으로 느껴집니다. 특정 기기, 제조업체, 특정 Android 버전 등 예외가 발생하는 위치와 관련된 패턴이 있습니까? – CommonsWare

+0

아니요 보고서에 어떤 휴대 전화 또는 Android가 있는지 알 수 없습니다. 안드로이드 2.2와 함께 내 자신의 전화 (HTC의 욕망)에서 나는 때때로 애플 리케이션은 가끔 있지만 너무 자주 중지하지 않거나 얼어 붙지 않고, 다음 단계로 이동한다는 것을 알아 차렸다. – Jerry

답변

1

메소드 Settings.Secure.getString() 요청 된 이름이 데이터베이스에없는 경우 null을 반환 할 수 있습니다. 내가 왜 Settings.Secure.LOCATION_PROVIDERS_ALLOWED를 찾을 수 없는지 모르겠다. 그러나 코드에서 빈 문자열이 아닌지 확인하기 전에 provider가 null이 아닌지 getLocation()에서 확인하지 않습니다. 제 생각에는 그것이 두 번째 예외의 근원이라고 생각합니다.

코드에서 무언가를 지원하지 않는 OS 릴리스에서 앱을 실행하려고하면 프레임 워크의 심오한 임의 오류가 발생할 수 있습니다. targetSdkVersion뿐만 아니라 매니페스트에서 설정 한 minSdkVersion에 맞게 코드를 컴파일해야합니다.

+0

좋아, 아프다. 그래서 제공자 dosnt가 null로 시작하고, 아픈 보고서를 돌려 준다. – Jerry

+0

@Ted Hopp - 이것이 트릭을 할 수 있다고 생각하니? if (provider == null) provider = ""; – Jerry

+0

"if (! (provider == null || provider.equals (" "))) {...}"을 사용해보십시오. 그 트릭을해야합니다. –

1

이 문제에 대한 참고 사항. 이것이 당신의 문제인지 아닌지는 모르겠지만 애플리케이션간에 파일을 공유하고 AndroidManifest.xml 파일의 android:sharedUserId 속성을 수정하려고 시도했습니다. 내가 한 후에는 귀하가보고 한 것과 정확히 동일한 오류가 발생했으며 내 앱이 제대로 시작되지 않았습니다 (AdRequest의 실패로 인해 발생). 매니 페스트에서 sharedUserId 속성을 제거한 후에도 환경 설정 데이터베이스에서 오류가 발생했지만 계속해서 오류가 발생했습니다.

최종 줄은 배포 된 응용 프로그램의 sharedUserId 특성을 변경하지 않거나 모든 작업을 다시 수행하기 위해 제거/다시 설치주기가 필요할 것입니다.

관련 문제