Java 应用程序在新设备(棒棒糖)上显示错误,但在我的旧设备(kitkat)上运行良好

Java 应用程序在新设备(棒棒糖)上显示错误,但在我的旧设备(kitkat)上运行良好,java,android,json,android-layout,google-maps-markers,Java,Android,Json,Android Layout,Google Maps Markers,我面临一个非常不寻常的错误(在列表中,因为我是编程新手),我开发了一个应用程序,mainActivity在其中登录了facebook,然后转到MapsActivity。应用程序在任何新的棒棒糖设备中崩溃,但在我的旧kitkat设备中运行良好。这是我的活动代码和MapsActivity FATAL EXCEPTION: main Process: com.thekhagpsnavigation.newthekhaapp, PID: 31999 java.lang.RuntimeExce

我面临一个非常不寻常的错误(在列表中,因为我是编程新手),我开发了一个应用程序,mainActivity在其中登录了facebook,然后转到MapsActivity。应用程序在任何新的棒棒糖设备中崩溃,但在我的旧kitkat设备中运行良好。这是我的活动代码和MapsActivity

  FATAL EXCEPTION: main
  Process: com.thekhagpsnavigation.newthekhaapp, PID: 31999
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thekhagpsnavigation.newthekhaapp/com.thekhagpsnavigation.newthekhaapp.MapsActivity}: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class android.widget.Button
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
  at android.app.ActivityThread.-wrap11(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5443)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class android.widget.Button
  at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
  at android.app.Activity.setContentView(Activity.java:2176)
  at com.thekhagpsnavigation.newthekhaapp.MapsActivity.onCreate(MapsActivity.java:99)
  at android.app.Activity.performCreate(Activity.java:6259)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5443) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
  Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class android.widget.Button
  at android.view.LayoutInflater.createView(LayoutInflater.java:645)
  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
  at android.app.Activity.setContentView(Activity.java:2176) 
  at com.thekhagpsnavigation.newthekhaapp.MapsActivity.onCreate(MapsActivity.java:99) 
  at android.app.Activity.performCreate(Activity.java:6259) 
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
  at android.os.Handler.dispatchMessage(Handler.java:102) 
  at android.os.Looper.loop(Looper.java:148) 
  at android.app.ActivityThread.main(ActivityThread.java:5443) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
  Caused by: java.lang.reflect.InvocationTargetException
  at java.lang.reflect.Constructor.newInstance(Native Method)
  at android.view.LayoutInflater.createView(LayoutInflater.java:619)
  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
  at android.app.Activity.setContentView(Activity.java:2176) 
  at com.thekhagpsnavigation.newthekhaapp.MapsActivity.onCreate(MapsActivity.java:99) 
  at android.app.Activity.performCreate(Activity.java:6259) 
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)                                                                                        
这是我的地图活动-

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback  {

public GoogleMap mMap;
private HttpURLConnection urlConnection = null;
private BufferedReader reader = null;
private String forecastJsonStr = null;
private  String url = "My_url";




// menu bar option enable

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_map,menu);
    return true;
}

// on menu click

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id=item.getItemId();

    if (id == R.id.Exit){
        finish();
        System.exit(0);


        return true;
    }
    else if (id == R.id.Logout){
        FacebookSdk.sdkInitialize(getApplicationContext());
        LoginManager.getInstance().logOut();
        Intent i = new Intent(MapsActivity.this,MainActivity.class);
        this.startActivity(i);
    }



    return super.onOptionsItemSelected(item);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);


}


public void onMapSearch (View view) throws IOException {

    //hide button when button is pressed
    InputMethodManager inputManager = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

    //preview the entered address as an Tost in bar
    EditText locationSearch = (EditText) findViewById(R.id.editText);
    String location = locationSearch.getText().toString();

    //this will animate camera and zoom 12.0f
    mMap.animateCamera(CameraUpdateFactory.zoomTo(12.0f));



    //further address search codes
    List<Address> addressList = null;

    //if nothing will be entered in the edit-text will not show a toast rather than crashing of thekha app
    if (locationSearch.getText().toString().equals("")){
        Toast.makeText(this,"Please enter an Address",Toast.LENGTH_LONG).show();
    }
    else {

        //process of exception handling and finding location
        if (location != null || !location.equals("")) {
            Geocoder geocoder = new Geocoder(this);
            try {
                addressList = geocoder.getFromLocationName(location, 1);
            } catch (IOException e) {
                e.printStackTrace();
              }
            //if address is greater than one then these processes will happen

            if(addressList.size()>0) {
                Address address = addressList.get(0);
                LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
                mMap.addMarker(new MarkerOptions()
                        .position(latLng)
                        .title(location + " is Here ")
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
                mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));

                Toast.makeText(this, location+" is here, Zoom In or Zoom Out to make your Thekha Visible ", Toast.LENGTH_LONG)
                        .show(); //popup type to show entered data
            }
            else {
                //process where entered entry will not gonna find , this will gonna a toast to show popup

                Toast.makeText(this,"Entered Address Not Found", Toast.LENGTH_LONG).show();

            }
        }

    }
}
ProgressDialog pd = null;

private class RetriveMarkerTask extends AsyncTask<String,Void,String> {
    private Context context;


    public RetriveMarkerTask(Context context) {
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        pd = new ProgressDialog(MapsActivity.this);
        pd.setTitle("Please wait ...");
        pd.setMessage("Connecting to Loofre Network");
        pd.setCancelable(false);
        pd.show();

    }

    protected String doInBackground(String... markerGetUrl) {
        try {
            // Construct the URL for the OpenWeatherMap query
            // Possible parameters are avaiable at OWM's forecast API page, at
            // http://openweathermap.org/API#forecast
            URL url1 = new URL(url);

            // Create the request to OpenWeatherMap, and open the connection
            urlConnection = (HttpURLConnection) url1.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();

            // Read the input stream into a String
            InputStream inputStream = urlConnection.getInputStream();
            StringBuffer buffer = new StringBuffer();
            if (inputStream == null) {
                // Nothing to do.
                return null;
            }
            reader = new BufferedReader(new InputStreamReader(inputStream));

            String line;
            while ((line = reader.readLine()) != null) {
                // Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
                // But it does make debugging a *lot* easier if you print out the completed
                // buffer for debugging.
                buffer.append(line + "\n");
            }

            if (buffer.length() == 0) {
                // Stream was empty.  No point in parsing.
                return null;
            }
            forecastJsonStr = buffer.toString();
        } catch (IOException e) {
            Log.e("PlaceholderFragment", "Error ", e);
            // If the code didn't successfully get the weather data, there's no point in attemping
            // to parse it.
            forecastJsonStr = "Error, an exception was raised.";
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
            if (reader != null) {
                try {
                    reader.close();
                } catch (final IOException e) {
                    Log.e("PlaceholderFragment", "Error closing stream", e);
                }
            }
        }
        return forecastJsonStr;

    }



    protected void onPostExecute(String markers) {


        Log.d("string response",markers);

        Toast.makeText(MapsActivity.this, "Plotting Thekha", Toast.LENGTH_LONG).show();

        try {
            JSONArray jsonArray = new JSONArray(markers);
            for (int i =0; i<jsonArray.length(); i++){
                //create marker of each place in the json data
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String placeName = jsonObject.getString("name");
                String placeAddress = jsonObject.getString("address");
                double latitude = jsonObject.getJSONArray("latlang").getDouble(0);
                double longitude = jsonObject.getJSONArray("latlang").getDouble(1);
                LatLng loc = new LatLng(latitude, longitude);
                //marker size change code
                int height = 150;
                int width =150;
                BitmapDrawable bitmapDrawable =(BitmapDrawable)getResources().getDrawable(R.drawable.thekhaicon);
                Bitmap b=bitmapDrawable.getBitmap();
                Bitmap smallMarker =Bitmap.createScaledBitmap(b,width,height,false);
                //marker size change code ends here
                //mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 13));

                mMap.addMarker(new MarkerOptions()
                        .icon(BitmapDescriptorFactory.fromBitmap(smallMarker))
                        .title(placeName)
                        .snippet(placeAddress)
                        .position(loc)

                );

                LatLng dwarka = new LatLng(28.570317,77.32182);
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(dwarka, 13));
                mMap.addMarker(
                        new MarkerOptions()
                                .title("Wine Beer Liquor Shop, Sector 18, Noida")
                                .snippet("Sector 18, Near Centre Stage Mall, Noida")
                                .position(dwarka));
            }
            pd.dismiss();
        }catch (JSONException e){
            e.printStackTrace();
        }

    }



}


//OnReady map starts here when we can enter or add Marker to the map
@Override
public void onMapReady(GoogleMap googleMap) {





    Toast.makeText(this, "Connecting Server", Toast.LENGTH_LONG).show();
    mMap = googleMap;

    try {
        RetriveMarkerTask markerTask = new RetriveMarkerTask(MapsActivity.this);
        markerTask.execute(url);
    }catch (Exception e){
        Toast.makeText(this,"Can not fetch data",Toast.LENGTH_LONG).show();
    }
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission
            (this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //  int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
    }
    //tool bar and other tool related on map uiSettings
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setMapToolbarEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);

}


Syles.xml-

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的


//将其添加到Manifest.xml中

风格可能是个问题。

MapsActivity.xml中有两个顶级元素?我不明白你的意思。。。这是我所有的代码sir@MikeM. 先生,你能帮我一下吗?按钮样式有问题,这行style=“?android:attr/buttonStyleSmall”。@NitinKarande先生,我如何解决这个问题?我无法从我的位置访问这些类型的URL。你能粘贴它吗?致命的例外:主进程:com.thekhagpsnavigation.newthekhaapp,PID:11520 java.lang.SecurityException:my location要求在com.google.android.gms.maps.internal.igogleMapDelegate$zza$zza.setMyLocationEnabled.com.com.google.android.gms.DynamicModulesB:274)的xj.onTransact(:com.google.android.gms.DynamiteModulesB:274)的maps.ad.t.ad.t.c(未知源代码)上访问maps.ad.t.t.c(粗略位置)的权限(未知来源)在gms.maps.GoogleMap.setMyLocationEnabled(未知来源)在KhagpsNavigation.newthekhaapp.MapsActivity.onMapReady(MapsActivity.java:335)请现在尝试我的答案你得到任何结果了吗?是的……我不得不注释掉mMap.setMyLocationEnabled(true);但它禁用了位置按钮
MAnifest file : -
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSWEVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:name="android.support.multidex.MultiDexApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="MY THEKHA"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />

    <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="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="MYTHEKHA"
        />
    <activity
        android:name=".instructionSlide"
        android:label="MY THEKHA"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat"/>
    <activity
        android:name=".AboutUs"
        android:label="My Thekha" />
</application>
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
 <EditText
    android:layout_width="304dp"
    android:layout_height="46dp"
    android:id="@+id/editText"
    android:textColor="@color/abc_input_method_navigation_guard"
    android:hint="@string/enter_address"
    android:background="@drawable/common_google_signin_btn_text_dark_focused"
   />
  //add this to your Manifest.xml
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>