抱歉非特定的标题。所以,我正在开发一个名为JustJava的应用程序,我刚刚安装了生奶油复选框和相应的代码。我记录了它,由于某种原因它没有显示出来。相反,它给了我错误,如:
无法加载memetrack模块
无法获取内存消耗信息:-1
无默认活动
此外,每次运行时,应用程序都会崩溃一次,就在开始时,我必须再次运行应用程序。显然,鲜奶油复选框没有更新任何东西。我已多次查看代码并在互联网上搜索了一段时间,但我找不到任何东西。有人可以看看我的代码,看看他们是否可以看到这个问题?
非常感谢!
XML布局代码
<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);
}
}
答案 0 :(得分:0)
您似乎忘了在Manifest.xml中定义活动。像这样尝试一次
<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>
由于有关问题的有限详细信息,如果解决方案不起作用,则添加错误stackTrace以及问题。