我正在Android Studio IDE 1.1.0版上開發應用程序。 這是個應用程序...爲什麼我的應用程序在啓動時崩潰(Android Studio)
我的問題是,當我開始它一直在啓動時崩潰的設備上的應用程序。
這裏是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
package com.ziad_homework.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView totalTextView;
EditText percentageTxt;
EditText numberTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
totalTextView = (TextView) findViewById(R.id.totalTextView);
percentageTxt = (EditText) findViewById(R.id.percentageTxt);
numberTxt = (EditText) findViewById(R.id.numTxt);
Button calcBtn = (Button) findViewById(R.id.calcBtn);
calcBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
float percentage = Float.parseFloat(percentageTxt.getText().toString());
float dec = percentage/100;
float total = dec * Float.parseFloat(numberTxt.getText().toString());
totalTextView.setText(Float.toString(total));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/totalTextView"
android:layout_marginTop="29dp"
android:textStyle="normal"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="false"
android:layout_alignParentLeft="false"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false"
android:autoText="false"
android:elegantTextHeight="false"
android:gravity="center"
android:textAlignment="center"
android:textSize="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="What is"
android:id="@+id/textView"
android:layout_below="@+id/totalTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/percentageTxt"
android:layout_marginTop="28dp"
android:hint="Enter Percentage"
android:textAlignment="center"
android:gravity="center"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/numTxt"
android:hint="Enter Number"
android:textAlignment="center"
android:gravity="center"
android:layout_marginTop="18dp"
android:layout_below="@+id/textView3"
android:layout_toStartOf="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="%"
android:id="@+id/textView2"
android:layout_alignBottom="@+id/percentageTxt"
android:layout_alignEnd="@+id/totalTextView"
android:layout_marginEnd="25dp"
android:layout_marginRight="55dp"
android:layout_marginBottom="5dp"
android:textSize="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="of"
android:id="@+id/textView3"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CALCULATE"
android:id="@+id/calcBtn"
android:layout_marginTop="39dp"
android:background="#e8443e6f"
android:textColor="#ffffff"
android:gravity="center"
android:layout_below="@+id/numTxt"
android:layout_alignStart="@+id/numTxt"
android:layout_alignEnd="@+id/numTxt" />
</RelativeLayout>
的strings.xml
<resources>
<string name="app_name">Percent Calculator</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primaryColor">#e8443e6f</color>
</resources>
styles.xml(V21)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">@color/primaryColor</item>
</style>
</resources>
的logcat的:
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication E/Zygote﹕ MountEmulatedStorage()
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication E/Zygote﹕ v2
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication I/SELinux﹕ Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-J105F_5.1.1_0046
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication I/art﹕ Late-enabling -Xcheck:jni
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication E/art﹕ setrlimit(RLIMIT_CORE) failed for pid 20522: Operation not permitted
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication I/libpersona﹕ KNOX_SDCARD checking this for 10111
04-30 14:53:23.541 20522-20522/com.ziad_homework.myapplication I/libpersona﹕ KNOX_SDCARD not a persona
04-30 14:53:23.581 20522-20530/com.ziad_homework.myapplication E/art﹕ Failed sending reply to debugger: Broken pipe
04-30 14:53:23.581 20522-20530/com.ziad_homework.myapplication I/art﹕ Debugger is no longer active
04-30 14:53:23.611 20522-20522/com.ziad_homework.myapplication W/ResourcesManager﹕ getTopLevelResources: /data/app/com.ziad_homework.myapplication-2/base.apk/1.0 running in com.ziad_homework.myapplication rsrc of package null
04-30 14:53:23.641 20522-20522/com.ziad_homework.myapplication W/ResourcesManager﹕ getTopLevelResources: /data/app/com.ziad_homework.myapplication-2/base.apk/1.0 running in com.ziad_homework.myapplication rsrc of package null
04-30 14:53:23.651 20522-20522/com.ziad_homework.myapplication W/ResourcesManager﹕ getTopLevelResources: /data/app/com.ziad_homework.myapplication-2/base.apk/1.0 running in com.ziad_homework.myapplication rsrc of package null
04-30 14:53:23.661 20522-20522/com.ziad_homework.myapplication D/AndroidRuntime﹕ Shutting down VM
04-30 14:53:23.661 20522-20522/com.ziad_homework.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ziad_homework.myapplication, PID: 20522
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ziad_homework.myapplication/com.ziad_homework.myapplication.MainActivity}: java.lang.RuntimeException: A TaskDescription's primary color should be opaque
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3150)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.RuntimeException: A TaskDescription's primary color should be opaque
at android.app.ActivityManager$TaskDescription.<init>(ActivityManager.java:592)
at android.app.Activity.onApplyThemeResource(Activity.java:4050)
at
android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:140)
at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:85)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3096)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
04-30 14:58:23.744 20522-20522/com.ziad_homework.myapplication I/Process﹕ Sending signal. PID: 20522 SIG: 9
您的AppTheme資源存在問題。你在那裏使用哪些自定義顏色? – CommonsWare
我忘了提及,我添加了一個colors.xml文件 – Ziad
這 <?XML版本= 「1.0」 編碼= 「UTF-8」?> <顏色名= 「primaryColor」>#e8443e6f –
Ziad