ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java – 应用程序显示新设备(棒棒糖)上的错误,但在我的旧设备上工作正常(kitkat)

2019-07-06 02:26:52  阅读:150  来源: 互联网

标签:json java android android-layout google-maps-markers


我面临一个非常不寻常的错误(在我的列表中因为我是编程的新手)我开发了一个应用程序,其中mainActivity有facebook登录然后它转到MapsActivity.App崩溃任何新的棒棒糖设备但在我的旧kitkat工作正常device.here是我的活动代码和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)                                                                                        

这是我的MapsActivity –

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);

}

这是我的MapsActivity.xml

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTintMode="src_over"
    android:visibility="visible"
    android:background="#3f51b5">

    <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"
        tools:background="@drawable/common_google_signin_btn_text_dark_normal" />


    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="46dp"
        android:text=""
        android:id="@+id/search_button"
        android:layout_gravity="right"
        android:onClick="onMapSearch"
        android:nestedScrollingEnabled="false"
        android:textColor="@color/abc_input_method_navigation_guard"
        android:background="@drawable/search_button" />
</LinearLayout>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="522dp"
tools:context="com.thekhagpsnavigation.newthekhaapp.MapsActivity" />
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>

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" />

解决方法:

 <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"/>

风格可能是问题.

标签:json,java,android,android-layout,google-maps-markers
来源: https://codeday.me/bug/20190706/1393178.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有