2017-10-25 5 views
0

Entschuldigung für den unspezifischen Titel. Also habe ich an einer App gearbeitet, die JustJava heißt und ich habe gerade die Schlagsahne-Checkbox und den entsprechenden Code installiert. Ich hatte es geloggt und aus irgendeinem Grund tauchte es nicht auf. Stattdessen gab es mir Fehler wie:Viele Fehler in meiner App

konnte nicht geladen werden memetrack Modul

Fehler beim Speicherverbrauch Informationen zu erhalten: -1

Keine Aktivität Standard

Auch die Die App stürzte vor jedem Mal, wenn ich sie ausführte, gleich am Anfang, und ich musste die App erneut ausführen. Offensichtlich hat das Kontrollkästchen Schlagsahne nichts aktualisiert. Ich habe den Code mehrere Male durchgesehen und eine Weile im Internet gesucht, aber ich konnte nichts finden. Könnte jemand bitte meinen Code ansehen und sehen, ob er das Problem sehen kann?

Vielen Dank!

XML-Layoutcode

<EditText 
    android:id="@+id/name_input" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:hint="Enter Your Name Here" 
    android:layout_marginBottom="16dp" 
    android:inputType="text"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Toppings" 
    android:layout_marginBottom="16dp" 
    android:textAllCaps="true" 
    android:textSize="20sp"/> 

<CheckBox 
    android:id="@+id/whipped_cream_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Whipped cream" 
    android:paddingLeft="24dp" 
    android:textSize="16sp" 
    android:textAppearance="?android:textAppearanceMedium" /> 

<CheckBox 
    android:id="@+id/chocolate_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Chocolate" 
    android:paddingLeft="24dp" 
    android:textSize="16sp" 
    android:textAppearance="?android:textAppearanceMedium" 
    android:layout_marginBottom="16dp"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="16dp" 
    android:text="Quantity" 
    android:textAllCaps="true" 
    android:textSize="20sp"/> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

<Button 
    android:layout_width="48dp" 
    android:layout_height="48dp" 
    android:onClick="decrement" 
    android:text="-" /> 

<TextView 
    android:id="@+id/quantity_text_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:text="0" 
    android:textColor="@android:color/black" 
    android:textSize="16sp" /> 

<Button 
    android:layout_width="48dp" 
    android:layout_height="48dp" 
    android:onClick="increment" 
    android:text="+" /> 

</LinearLayout> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="16dp" 
    android:text="Order summary" 
    android:textSize="20sp" 
    android:textAllCaps="true" /> 

<TextView 
    android:id="@+id/order_summary_text_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="16dp" 
    android:text="Free" 
    android:textColor="@android:color/black" 
    android:textSize="16sp" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="16dp" 
    android:onClick="submitOrder" 
    android:text="Order" /> 

MainActivity-Code

package com.example.android.justjava3; 

import android.icu.text.NumberFormat; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import android.widget.CheckBox; 
import android.widget.TextView; 
import com.example.android.justjava.R; 

/** 

This app displays an order form to order coffee. 
*/ 
public class MainActivity extends AppCompatActivity { 

int quantity = 0; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
} 

/** 

This method is called when the order button is clicked. 
*/ 
public void submitOrder(View view) { 
CheckBox whippedCreamCheckBox = (CheckBox) 
findViewById(R.id.whipped_cream_checkbox); 
boolean hasWhippedCream = whippedCreamCheckBox.isChecked(); 
Log.v(“MainActivity”, “Has whipped cream?”+hasWhippedCream); 
int price=calculatePrice(); 
String priceMessage=createOrderSummary(price, hasWhippedCream); 
displayMessage(priceMessage); 
} 
/** 
Calculates the price of the order. 
@total price 
*/ 
private int calculatePrice() { 
int price = quantity * 5; 
return price; 
} 
private String createOrderSummary(int price, boolean addWhippedCream){ 
String priceMessage=“The total price for " + quantity + " cups of coffee is 
$” + price; 
priceMessage +="\n Customer name: Kaptain Kunal"; 
priceMessage +="\n Whipped cream topping: " + addWhippedCream; 
String freeMessage=“Free”; 
displayMessage(freeMessage); 
priceMessage+="\n Number of coffees ordered: "+quantity; 
return priceMessage; 

}

/** 

This method displays the given quantity value on the screen. 
/
private void displayQuantity(int number) { 
TextView quantityTextView = (TextView) 
findViewById(R.id.quantity_text_view); 
quantityTextView.setText("" + number); 
} 
/* 
This method displays the given price on the screen. 
*/ 
private void displayMessage(String message) { 
TextView orderSummaryTextView = (TextView) 
findViewById(R.id.order_summary_text_view); 
orderSummaryTextView.setText 
(NumberFormat.getCurrencyInstance().format(message)); 

}

public void increment (View view){ 

quantity=(quantity+1); 
displayQuantity(quantity); 
} 

public void decrement (View view){ 
quantity=(quantity-1); 
displayQuantity(quantity); 
} 

} 

Antwort

0

Es scheint, als hätten Sie vergessen, die Aktivität in Manifest.xml zu definieren. Versuchen Sie es einmal so

<application> 
    <activity 
     android:name="ActivityName" 
     android:screenOrientation="portrait" 
     android:theme="@style/SplashTheme"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 
</application> 

Fällig Begrenzte Details über das Problem in Frage, wenn Lösung nicht funktioniert, dann addieren Sie Fehler stackTrace zusammen mit Frage.

+0

Leider habe ich das schon vor einigen Tagen gemacht und es hilft immer noch nicht. Ich bekomme keine Fehler mehr vom Code selbst, aber die App ist immer noch durcheinander, wenn sie ausgeführt wird. Vielleicht wird das Problem behoben, wenn Sie mit diesem Setup herumspielen. –

+0

versuchen Sie das obige Update einmal, wenn es immer noch nicht funktioniert, fügen Sie Fehler-Stack-Trace hinzu, so dass wir das Problem verstehen können. –

+0

Ist der "Fehler Stack Trace" die Fehlermeldungen im Android-Monitor? (Logcat) –

Verwandte Themen