有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我面临着一个非常不寻常的错误(在列表中,因为我是编程新手),我开发了一个应用程序,其中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}: 安卓.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class 安卓.widget.Button
  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
  at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
  at 安卓.app.ActivityThread.-wrap11(ActivityThread.java)
  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
  at 安卓.os.Handler.dispatchMessage(Handler.java:102)
  at 安卓.os.Looper.loop(Looper.java:148)
  at 安卓.app.ActivityThread.main(ActivityThread.java:5443)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
  at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  Caused by: 安卓.view.InflateException: Binary XML file line #24: Binary XML file line #24: Error inflating class 安卓.widget.Button
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:539)
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:423)
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:374)
  at com.安卓.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
  at 安卓.app.Activity.setContentView(Activity.java:2176)
  at com.thekhagpsnavigation.newthekhaapp.MapsActivity.onCreate(MapsActivity.java:99)
  at 安卓.app.Activity.performCreate(Activity.java:6259)
  at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
  at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
  at 安卓.app.ActivityThread.-wrap11(ActivityThread.java) 
  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
  at 安卓.os.Handler.dispatchMessage(Handler.java:102) 
  at 安卓.os.Looper.loop(Looper.java:148) 
  at 安卓.app.ActivityThread.main(ActivityThread.java:5443) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
  at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
  Caused by: 安卓.view.InflateException: Binary XML file line #24: Error inflating class 安卓.widget.Button
  at 安卓.view.LayoutInflater.createView(LayoutInflater.java:645)
  at com.安卓.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
  at 安卓.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
  at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
  at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
  at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:835)
  at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
  at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:838)
  at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:515)
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:423) 
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:374) 
  at com.安卓.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
  at 安卓.app.Activity.setContentView(Activity.java:2176) 
  at com.thekhagpsnavigation.newthekhaapp.MapsActivity.onCreate(MapsActivity.java:99) 
  at 安卓.app.Activity.performCreate(Activity.java:6259) 
  at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
  at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
  at 安卓.app.ActivityThread.-wrap11(ActivityThread.java) 
  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
  at 安卓.os.Handler.dispatchMessage(Handler.java:102) 
  at 安卓.os.Looper.loop(Looper.java:148) 
  at 安卓.app.ActivityThread.main(ActivityThread.java:5443) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
  at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
  Caused by: java.lang.reflect.InvocationTargetException
  at java.lang.reflect.Constructor.newInstance(Native Method)
  at 安卓.view.LayoutInflater.createView(LayoutInflater.java:619)
  at com.安卓.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
  at 安卓.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
  at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
  at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
  at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
  at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
  at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
  at 安卓.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:515) 
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:423) 
  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:374) 
  at com.安卓.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
  at 安卓.app.Activity.setContentView(Activity.java:2176) 
  at com.thekhagpsnavigation.newthekhaapp.MapsActivity.onCreate(MapsActivity.java:99) 
  at 安卓.app.Activity.performCreate(Activity.java:6259) 
  at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
  at 安卓.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, 安卓.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission
            (this, 安卓.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);

}

这是我的地图活动。xml

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

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

    <EditText
        安卓:layout_width="304dp"
        安卓:layout_height="46dp"
        安卓:id="@+id/editText"
        安卓:textColor="@color/abc_input_method_navigation_guard"
        安卓:hint="@string/enter_address"
        安卓:background="@drawable/common_google_signin_btn_text_dark_focused"
        tools:background="@drawable/common_google_signin_btn_text_dark_normal" />


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

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


MAnifest file : -

<uses-permission 安卓:name="安卓.permission.INTERNET" />
<uses-permission 安卓:name="安卓.permission.ACCESS_NETWORK_STATE" />
<uses-permission 安卓:name="安卓.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission 安卓:name="com.google.安卓.providers.gsf.permission.READ_GSWEVICES" />
<uses-permission 安卓:name="安卓.permission.ACCESS_COARSE_LOCATION" />
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION" />

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

    <activity 安卓:name=".MainActivity">
        <intent-filter>
            <action 安卓:name="安卓.intent.action.MAIN" />

            <category 安卓:name="安卓.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        安卓:name="com.facebook.FacebookActivity"
        安卓:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        安卓: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
        安卓:name="com.google.安卓.geo.API_KEY"
        安卓:value="@string/google_maps_key" />

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

西尔斯。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" />


共 (1) 个答案

  1. # 1 楼答案

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

    风格可能是个问题