ich zwischen 2 Aktivitäten in Android-Studio wechseln bin versucht, das Problem ist, wenn ich die Taste, um den Programmabsturz drücken und aufhören zu arbeiten, hier ist der Fehler:Android Studio - Fatal Exception
> FATAL EXCEPTION: main
Process: com.example.talal.furnitureorder, PID: 19310
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.talal.furnitureorder/com.example.talal.furnitureorder.Invoice}: java.lang.NumberFormatException: Invalid int: "Number of Chairs:"
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NumberFormatException: Invalid int: "Number of Chairs:"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:410)
at java.lang.Integer.parseInt(Integer.java:367)
at java.lang.Integer.parseInt(Integer.java:334)
at com.example.talal.furnitureorder.Invoice.onCreate(Invoice.java:48)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
mein XML-Code für Aktivität 1:
<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="com.example.talal.furnitureorder.Order">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Customer Name"
android:id="@+id/textView"
android:textAlignment="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/e1"
android:textAlignment="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Customer Address"
android:id="@+id/textView2"
android:textAlignment="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/e2"
android:textAlignment="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Customer City"
android:id="@+id/textView3"
android:textAlignment="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/e3"
android:textAlignment="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Number of Chairs ordered"
android:id="@+id/textView4"
android:textAlignment="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/e4"
android:textAlignment="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Number of Sofas ordered"
android:id="@+id/textView5"
android:textAlignment="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/e5"
android:textAlignment="center" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Print the Invoice"
android:id="@+id/b1"
android:textAlignment="center"
android:onClick="print"
android:layout_marginTop="10pt" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reset"
android:id="@+id/b2"
android:onClick="reset"
android:textAlignment="center" />
</LinearLayout>
</RelativeLayout>
mein Java-Code für Aktivität 1:
package com.example.talal.furnitureorder;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class Order extends AppCompatActivity {
private EditText ed1,ed2,ed3,ed4,ed5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
}
public void print (View view){
Intent t=new Intent (this,Invoice.class);
ed1=(EditText) findViewById(R.id.e1);
ed2=(EditText) findViewById(R.id.e2);
ed3=(EditText) findViewById(R.id.e3);
ed4=(EditText) findViewById(R.id.e4);
ed5=(EditText) findViewById(R.id.e5);
Bundle b=new Bundle();
b.putString("name",ed1.getText().toString());
b.putString("address",ed2.getText().toString());
b.putString("city",ed3.getText().toString());
b.putString("C_NO",ed4.getText().toString());
b.putString("S_NO",ed5.getText().toString());
t.putExtras(b);
startActivity(t);
}
}
meine XML-Code für activ ity2:
<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="com.example.talal.furnitureorder.Invoice">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv1"
android:textAlignment="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv2"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv3"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv4"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv5"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv6"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv7"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/tv8"
android:textAlignment="center"
android:layout_marginTop="18dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New"
android:id="@+id/b3"
android:textAlignment="center"
android:layout_marginTop="19dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Exit"
android:id="@+id/b4"
android:textAlignment="center"
android:layout_marginTop="10dp" />
</LinearLayout>
</RelativeLayout>
mein Java-Code für activity2:
package com.example.talal.furnitureorder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class Invoice extends AppCompatActivity {
private TextView t1, t2, t3, t4, t5, t6, t7, t8;
int c, s;
int p, tp;
int tx;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_invoice);
t1 = (TextView) findViewById(R.id.tv1);
t2 = (TextView) findViewById(R.id.tv2);
t3 = (TextView) findViewById(R.id.tv3);
t4 = (TextView) findViewById(R.id.tv4);
t5 = (TextView) findViewById(R.id.tv5);
t6 = (TextView) findViewById(R.id.tv6);
t7 = (TextView) findViewById(R.id.tv7);
t8 = (TextView) findViewById(R.id.tv8);
Bundle bb = getIntent().getExtras();
String s1 = bb.getString("name");
String s2 = bb.getString("address");
String s3 = bb.getString("city");
String s4 = bb.getString("C_NO");
String s5 = bb.getString("S_NO");
t1.setText("Customer Name:" + s1);
t2.setText("Customer Address:" + s2);
t3.setText("Customer City:" + s3);
t4.setText("Number of Chairs:" + s4);
t5.setText("Number of Sofas:" + s5);
c = Integer.parseInt(t4.getText().toString());
s = Integer.parseInt(t5.getText().toString());
p = (350 * c) + (925 * s);
t6.setText("Price is: $" + p);
}
}
Vielen Dank, es funktionierte wie ein Charme ... Ich habe gesucht und gesucht ..Sie sind mein Geschmack: D – tiktak
Froh wir könnten helfen .. –
hmm es funktionierte zuerst und alles war in Ordnung, aber dann habe ich es versucht um die Anwendung zu schließen und die Simulation erneut zu öffnen, wird der Fehler erneut angezeigt. – tiktak