我剛剛在學校開始了一個android開發類,想知道爲什麼我的代碼不工作?任何幫助將不勝感激。我正在創建一個提示跟蹤器應用程序,以幫助我在提供比薩餅時跟蹤我的提示。我知道創建了一個類似的應用程序,但我想創建自己的應用程序,這也是我本學期的最終項目。現在,我只是試圖在窗口之間導航,以確保我可以將所有內容鏈接在一起,然後才能在UI上發瘋。我沒有看到實際存在問題的位置,但當我點擊主屏幕上的「傳送」按鈕時,出現錯誤「不幸的是,[app]已停止工作」。所以我的第二個窗口從未真正出現。另外,我的應用程序有時非常緩慢且無響應。感謝任何能夠幫助的人。我的代碼如下:Android應用程序。應用程序工作非常緩慢,並導致錯誤
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:layout_width="155dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal|center"
android:layout_marginBottom="10dp"
android:background="@drawable/button_bg"
android:text="Delivery"
android:id="@+id/deliveryButton" />
<Button
android:layout_width="155dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal|center"
android:layout_marginBottom="10dp"
android:background="@drawable/button_bg"
android:text="LOG"
android:id="@+id/logButton" />
<Button
android:layout_width="155dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal|center"
android:layout_marginBottom="10dp"
android:background="@drawable/button_bg"
android:text="MAPS"
android:id="@+id/mapsButton" />
我主要的Java文件的代碼是:
public class MainActivity extends AppCompatActivity {
private Button launchDeliveryActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
launchDeliveryActivity = (Button) findViewById(R.id.deliveryButton);
launchDeliveryActivity.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
launchActivity();
}
});
}
private void launchActivity()
{
Intent intent = new Intent(this, orderDetailsActivity.class);
startActivity(intent);
}
我的第二個窗口是我趕緊扔在一起,以確保我將能夠從導航主屏幕,第二個窗口和背部:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/order_details"
android:orientation="vertical">
<Button
android:layout_width="120dp"
android:layout_height="60dp"
android:text="Home"
android:id="@+id/homeScreenButton" />
</LinearLayout>
最後,我的第二個Java文件:
public class orderDetailsActivity extends AppCompatActivity {
private Button homeScreen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order_details);
homeScreen = (Button) findViewById(R.id.homeScreenButton);
homeScreen.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
finish();
}
});
}
個
日誌是:
上午01時29分執行的任務:[:應用:assembleDebug]
上午01時29分搖籃建設完成了1秒781ms
上午01點31執行任務: :應用:assembleDebug]
上午01時31分在搖籃7S 15ms的
上午01時31分建立成品即時運行進行全方位構建和安裝,因爲在設備上的安裝不符合ŧ他本地建立在磁盤上。 (不要再顯示)
上午01點40執行任務:[:應用:assembleDebug]
上午01時40搖籃籌建完成了1秒203ms
上午01點43執行任務: :應用程序:assembleDebug]
上午01點43分搖籃籌建完成了在983ms
編輯: 的logcat的是:
03-27 03:37:59.550 31525-31525/com.example.boley.personaldeliveryassistant E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.boley.personaldeliveryassistant, PID: 31525
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.boley.personaldeliveryassistant/com.example.boley.personaldeliveryassistant.orderDetailsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.boley.personaldeliveryassistant.orderDetailsActivity.onCreate(orderDetailsActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.boley.personaldeliveryassistant.orderDetailsActivity.onCreate(orderDetailsActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.boley.personaldeliveryassistant.orderDetailsActivity.onCreate(orderDetailsActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 207355916 byte allocation with 16773008 free bytes and 53MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:2228)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4215)
at android.content.res.Resources.loadDrawable(Resources.java:4089)
at android.content.res.Resources.loadDrawable(Resources.java:3939)
at android.content.res.TypedArray.getDrawable(TypedArray.java:886)
at android.view.View.<init>(View.java:4230)
at android.view.ViewGroup.<init>(ViewGroup.java:589)
at android.widget.LinearLayout.<init>(LinearLayout.java:202)
at android.widget.LinearLayout.<init>(LinearLayout.java:198)
at android.widget.LinearLayout.<init>(LinearLayout.java:194)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.boley.personaldeliveryassistant.orderDetailsActivity.onCreate(orderDetailsActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
請加日誌 –
請加錯! – BinaryMan
只有當我在手機或模擬器上運行應用程序時,我纔會在Android Studio中收到任何錯誤。該應用加載非常緩慢,當我點擊「傳遞」按鈕,這是按鈕,帶我到第二個窗口,它說:「不幸的是,個人傳遞助理已停止。」第二個窗口從不顯示。 –