Ich habe eine App für eine Woche jetzt entwickelt und alles lief gut. Ich hatte keine Probleme mit irgendeinem der 3 Geräte, in denen ich die Apps, die ich entwickle, teste. Aber jetzt habe ich die App auf einem dieser drei Geräte gestartet und alles ist zur Hölle gegangen. Die seltsamste Sache ist, dass die App perfekt auf den anderen beiden Geräten funktioniert, aber auf der dritten stürzt sie beim ersten onCreate() - Aufruf ab. Ich weiß wirklich nicht, was ich falsch mache, dass es nicht auf einem meiner Geräte funktioniert. Hier ist mein Code.verursacht durch: android.view.InflateException Fehler beim Aufblasen der Klasse in Android App
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myapp.miquel.mqlapps.hombresmujeresapp">
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="here_goes_my_real_admob_id" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="ndroid.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".TestActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ResultActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".MenuActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:screenOrientation="portrait" />
<activity
android:name=".GenderChoiceActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".AboutAppActivity"
android:label="@string/title_activity_about_app"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".MQLAppsIniActivity"
android:label="@string/app_name">
</activity>
</application>
</manifest>
MenuActivity.java (hier ist, wo die Ausnahme auf der setContentView geworfen wird() aufrufen innerhalb des onCreate() -Methode). Zu Ihrer Information handle ich in dieser Klasse nur mit drei Schaltflächen und je nachdem, worauf der Benutzer klickt, startet er die eine oder andere Aktivität.
package myapp.miquel.mqlapps.hombresmujeresapp;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MenuActivity extends AppCompatActivity {
public static String gender = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Typeface tf_existence = Typeface.createFromAsset(MenuActivity.this.getApplicationContext().getAssets(), "Existence-Light.otf");
Button initTest = (Button) findViewById(R.id.initTest);
initTest.setTypeface(tf_existence);
Button ajustes = (Button) findViewById(R.id.ajustes);
ajustes.setTypeface(tf_existence);
Button sobreLaApp = (Button) findViewById(R.id.sobreApp);
sobreLaApp.setTypeface(tf_existence);
Bundle extras = getIntent().getExtras();
if (extras != null) {
gender = extras.getString("GENERO");
}
initTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
MenuActivity.this.finish();
Intent intent = new Intent(MenuActivity.this, TestActivity.class);
intent.putExtra("GENERO", gender);
startActivity(intent);
}
});
ajustes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
//MenuActivity.this.finish();
Intent intent = new Intent(MenuActivity.this, SettingsActivity.class);
intent.putExtra("GENERO", gender);
startActivity(intent);
}
});
sobreLaApp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
//MenuActivity.this.finish();
Intent intent = new Intent(MenuActivity.this, AboutAppActivity.class);
startActivity(intent);
}
});
}
@Override
public void onResume(){
super.onResume();
// put your code here...
}
}
activity_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="myapp.miquel.mqlapps.hombresmujeresapp.ResultActivity"
android:background="#bbdefb">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
style="@style/ButtonInitTest"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:text="Iniciar test"
android:id="@+id/initTest"
android:layout_marginTop="45dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
style="@style/ButtonSettings"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:text="Ajustes"
android:id="@+id/ajustes"
android:layout_below="@+id/initTest"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="62dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
style="@style/ButtonAbout"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:text="Sobre la App"
android:id="@+id/sobreApp"
android:layout_below="@+id/ajustes"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="62dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
Wie Sie feststellen können, verwende ich für diese Tasten einen benutzerdefinierten Stil. Der Stil ist:
<style name="ButtonNormalText" parent="@android:style/Widget.Button">
<item name="android:textColor" >@color/black</item>
<item name="android:textSize" >25dip</item>
<item name="android:height" >44dip</item>
<item name="android:background" >@drawable/default_button</item>
<item name="android:focusable" >true</item>
<item name="android:clickable" >true</item>
</style>
<style name="ButtonInitTest" parent="ButtonNormalText">
<item name="android:drawableLeft" >@drawable/test_icon</item>
</style>
<style name="ButtonSettings" parent="ButtonNormalText">
<item name="android:drawableLeft" >@drawable/ic_settings</item>
</style>
<style name="ButtonAbout" parent="ButtonNormalText">
<item name="android:drawableLeft" >@drawable/ic_about</item>
</style>
Und schließlich ist dies der LogCat-Fehler. Da es ziemlich lang ist werde ich durch das verursacht nur schreiben:
FATAL EXCEPTION: main
Process: myapp.miquel.mqlapps.hombresmujeresapp, PID: 13239
java.lang.RuntimeException: Unable to start activity ComponentInfo{myapp.miquel.mqlapps.hombresmujeresapp/myapp.miquel.mqlapps.hombresmujeresapp.MenuActivity}: android.view.InflateException: Binary XML file line #43: Error inflating class android.support.v7.internal.widget.ActionBarContextView
Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class android.support.v7.internal.widget.ActionBarContextView
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.RuntimeException: org.xmlpull.v1.XmlPullParserException: <internal>: <nine-patch> requires a valid 9-patch source image
Alles geschieht unter:
at myapp.miquel.mqlapps.hombresmujeresapp.MenuActivity.onCreate(MenuActivity.java:30)
Welche der setContentView() aufrufen vom onCreate ist() in MenuActivity
Ich wäre sehr erfreut, wenn Sie sich bitte die Zeit nehmen könnten, um meinen Code zu überprüfen und lassen Sie mich wissen, wenn ich etwas falsch mache. Das ist so weit das seltsamste Problem, mit dem ich seit langer Zeit konfrontiert bin. Danke im Voraus!
Nun, Leute, es scheint, dass ich Probleme mit einem 9-Patch-Quellbild habe, das ich nicht einmal habe. Alle meine Zeichen sind .xml oder .png Dateien, aber nicht .9.png überhaupt. Das ist so seltsam.
Anscheinend ist eines Ihrer Zeichen nicht ein korrektes 9-Patch-Bild: "erfordert ein gültiges 9-Patch-Quellbild" – Andros
Ich habe das bemerkt, aber was bedeutet das? Was ist ein 9-Patch-Quellbild? –
Ein 9-Patch-Bild ist ein erweiterbares Bild. Sie können einige Dokumentation hier finden: http://developer.android.com/intl/es/tools/help/draw9patch.html Schauen Sie in Ihrer Zeichnung ein Bild mit der Endung ".9.png" – Andros