Java 无法为android执行方法:onClick尝试使用一个botton从活动1获取到活动2
我很抱歉,如果我的问题是真的胡说八道,但我是新的安卓系统。问题是:当我试图用按钮打开第二个活动时,我的应用程序崩溃了Java 无法为android执行方法:onClick尝试使用一个botton从活动1获取到活动2,java,android,xml,Java,Android,Xml,我很抱歉,如果我的问题是真的胡说八道,但我是新的安卓系统。问题是:当我试图用按钮打开第二个活动时,我的应用程序崩溃了 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" an
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.paul_2.bus.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="4000dp"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="37dp"
android:hint="Numarul autobuzului"
android:id="@+id/spatiu"
android:inputType="number"/>
<Switch
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="WEEKEND"
android:id="@+id/weekend"
android:layout_marginLeft="240dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vezi ORAR"
android:onClick="mybtn" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/orar"
android:textColor="#1449c4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ruta"
android:textColor="#ff0011" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Vezi RUTA"
android:onClick="afisareruta"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Preferi un taxi?"
android:onClick="startTaxi"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/androidIV"/>
</LinearLayout>
</ScrollView>
`
不管怎么说,我想只有出租车级别的乘客。。。我不知道该怎么办。有人知道我的代码出了什么问题吗?您是否在清单中声明了
TaxiClass
,并张贴日志,以防万一,非常感谢!它工作!!!
package com.example.paul_2.bus;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public TextView orar;
public ImageView imagine;
public EditText spatiualb;
public Switch weekend;
int memonr;
int memoruta;
public TextView ruta;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void mybtn (View view){
/*Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:0740123456"));
startActivity(callIntent);
*/
spatiualb=(EditText)findViewById(R.id.spatiu);
orar=(TextView)findViewById(R.id.orar);
weekend=(Switch)findViewById(R.id.weekend);
memonr= Integer.parseInt(spatiualb.getText().toString());
if(weekend.isChecked()==false) {
if (memonr == 19) {
orar.setText("Plecări din Centrofarm – zile lucrătoare\n" +
"\n" +
"05:15 05:45 06:15 06:35 07:22 07:45 08:15 08:45 09:15 09:45 10:15 10:45 11:45 12:15 12:45 13:15 13:45 14:15 14:45 15:15 15:45 16:15 16:45 17:15 17:45 18:15 18:45 19:15 19:45 20:15 20:45 21:15 21:45 22:10\n" +
"\n" +
"Sosiri/Plecări SMURD – zile lucrătoare\n" +
"\n" +
"05:40 06:10 06:40 06:55 07:50 08:10 08:40 09:10 09:40 10:10 10:40 11:10 11:40 12:10 12:40 13:10 13:40 14:10 14:40 15:10 15:40 16:10 16:40 17:10 17:40 18:10 18:40 19:10 19:40 20:10 20:40 21:10 21:40 22:10\n");
}
if (memonr==20){
orar.setText("Plecări Centrofarm – zile lucrătoare\n" +
"\n" +
"05:00 05:30 06:00 06:30 07:05 07:30 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30 13:00 13:00 13:30 14:00 14:30 15:00 15:30 16:00 16:30 17:00 17:30 18:00 18:30 19:00 19:30 20:00 20:30 21:30 22:05\n"+
"\n"+
"Sosiri / Plecări Spitalul Județean – zile lucrătoare\n" +
"\n" +
"05:2 05:55 06:25 06:55 07:30 07:55 08:25 08:55 09:25 09:55 10:25 10:55 11:25 11:55 12:25 12:55 13:25 13:55 14:25 14:55 15:25 15:55 16:25 16:55 17:25 17:55 18:25 18:55 19:25 19:55 20:25 20:55 21:25 21:55 22:25");
}
if (memonr==17) {
orar.setText("Plecări din ERP (Combinat) – zile lucrătoare\n" +
"\n" +
"05:05 05:20 05:35 05:50 06:05 06:20 06:35 06:50 07:05 07:20 07:35 07:50 08:05 08:20 08:35 08:50 09:05 09:20 09:35 09:50 10:05 10:20 10:35 10:50 11:05 11:20 11:30 11:50 12:05 12:20 12:35 12:50 13:05 13:20 13:35 13:50 14:05 14:20 14:35 14:50 15:05 15:20 15:35 15:50 16:05 16:20 16:35 16:55 17:15 17:35 17:55 18:15 18:35 18:55 19:15 19:35 19:55 20:15 20:35 20:55 21:15 21:35 21:55 22:15\n"+
"\n"+
"Plecări din Centrofarm – zile lucrătoare\n" +
"\n" +
"05:05 05:20 05:35 05:50 06:05 06:20 06:35 06:50 07:05 07:20 07:35 07:50 08:05 08:20 08:35 08:50 09:05 09:20 09:35 09:50 10:05 10:20 10:35 10:50 11:05 11:20 11:3 11:50 12:05 12:20 12:35 12:50 13:05 13:20 13:35 13:50 14:05 14:20 14:35 14:50 15:05 15:20 15:35 15:50 16:05 16:25 16:45 17:05 17:25 17:45 18:05 18:25 18:45 19:05 19:25 19:45 20:05 20:25 20:45 21:05 21:25 21:45 22:05");
}
if(memonr==44){
orar.setText("Plecări ERP(Combinat) – zile lucrătoare\n" +
"\n" +
"05:10 05:30 05:50 06:10 06:30 06:50 07:10 07:30 07:50 08:10 08:30 08:50 09:10 09:30 09:50 10:10 10:30 10:50 11:10 11:30 11:50 12:10 12:30 12:50 13:10 13:30 13:50 14:10 14:30 14:50 15:10 15:30 15:50 16:10 16:30 16:50 17:10 17:30 17:50 18:10 18:30 18:50 19:10 19:30 19:50 20:10 20:30 20:50 21:10 21:30 22:10\n"+
"\n"+
"Plecări Sapientia -zile lucrătoare\n" +
"\n" +
"05:10 05:30 05:50 06:10 06:30 06:50 07:10 07:30 07:50 08:10 08:30 08:50 09:10 09:30 09:50 10:10 10:30 10:50 11:10 11:30 11:50 12:10 12:30 12:50 13:10 13:30 13:50 14:10 14:30 14:50 15:10 15:30 15:50 16:10 16:30 16:50 17:10 17:30 17:50 18:10 18:30 18:50 19:10 19:30 19:50 20:10 20:30 20:50 21:10 21:30 22:10");
}
if (memonr==30) {
orar.setText("30\n" +"Plecări Centrofarm – zile lucrătoare\n" +
"\n" +
"05:10 05:25 05:40 05:55 06:10 06:25 06:40 06:55 07:10 07:25 07:10 07:55 08:10 08:25 08:40 08:55 09:10 09:25 09:40 09:55 10:10 10:25 10:40 10:55 11:10 11:25 11:40 11:55 12:10 12:25 12:40 12:55 13:10 13:25 13:40 13:55 14:10 14:25 14:40 14:55 15:10 15:25 15:40 15:55 16:10 16:25 16:40 16:55 17:10 17:25 17:40 17:55 18:10 18:25 18:40 18:55 19:10 19:25 19:40 19:55 20:10 20:40 21:10 21:40\n"+
"\n"+
"Sosiri / Plecări Spitalul Județean – zile lucrătoare\n" +
"\n" +
"05:30 05:45 06:00 06:15 06:30 06:45 07:00 07:15 07:30 07:45 08:00 08:15 08:30 08:45 09:00 09:15 09:30 09:45 10:00 10:15 10:30 10:45 11:00 11:15 11:30 11:45 12:00 12:15 12:30 12:45 13:00 13:15 13:30 13:45 14:00 14:15 14:30 14:45 15:00 15:15 15:30 15:45 16:00 16:15 16:30 16:45 17:00 17:15 17:30 17:45 18:00 18:15 18:30 18:45 19:00 19:15 19:30 19:45 20:00 20:15 20:30 21:00 21:30 22:00\n"+
"\n"+ "30b\n"+
"Plecări Belvedere – zile lucrătoare\n" +
"\n" +
"05:20 05:50 06:20 06:50 07:20 07:50 08:20 08:50 09:20 09:50 10:20 10:50 11:20 11:50 12:20 12:50 13:20 13:50 14:20 14:50 15:20 15:50 16:20 16:50 17:20 17:50 18:20 18:50 19:20 19:50 20:20 20:50 21:20 21:50\n" +
"\n"+
"Sosiri / Plecări Spitalul Județean – zile lucrătoare\n" +
"\n" +
"05:45 06:15 06:45 07:15 07:45 08:15 08:45 09:15 09:45 10:15 10:45 11:45 12:15 12:45 13:15 13:45 14:15 14:45 15:15 15:45 16:15 16:45 17:15 17:45 18:15 18:45 19:15 19:45 20:15 20:45 21:15 21:45 22:15");
}
}
if (weekend.isChecked()==true) {
if (memonr == 19) {
orar.setText( "Plecări din Centrofarm – zile nelucrătoare\n" +
"\n" +
"05:35 06:35 07:35 08:35 09:35 10:35 11:35 12:35 13:35 14:35 15:35 16:35 17:35 18:35 19:35 20:35 21:35 \n" +
"\n"+ "Sosiri/Plecări SMURD – zile nelucrătoare\n" +
"\n" +
"06:00 07:00 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 22:00");
}
if (memonr == 20) {
orar.setText("Plecări Centrofarm – zile nelucrătoare\n" +
"\n" +
"05:05 06:05 07:05 08:05 09:05 10:05 11:05 12:05 13:05 14:05 15:05 16:05 17:05 18:05 19:05 20:05 21:05 22:10\n"+
"\n"+
"Sosiri / Plecări Spitalul Județean – zile nelucrătoare\n" +
"\n" +
"05:30 06:30 07:30 08:30 09:30 10:30 11:30 12:30 13:30 14:30 15:30 16:30 17:30 18:30 19:30 20:30 21:30");
}
if (memonr == 17) {
orar.setText("Plecări din ERP (Combinat) – zile nelucrătoare\n" +
"\n" +
"05:00 05:30 06:05 06:30 07:00 07:30 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30 13:00 13:30 14:05 15:05 16:00 17:00 18:00 19:00 20:00 21:00 22:10\n"+
"\n"+
"Plecări din Centrofarm – zile nelucrătoare\n" +
"\n" +
"05:00 05:30 06:00 06:30 07:00 07:30 08:00 08:30 09:00 09:30 10:00 10:30 11:00 11:30 12:00 12:30 13:00 13:30 14:00 14:30 15:30 16:30 17:30 18:30 19:30 20:30 21:30");
}
if (memonr == 44) {
orar.setText("Plecări ERP(Combinat) – zile nelucrătoare\n" +
"\n" +
"05:30 06:10 06:50 07:30 08:10 08:50 09:30 10:10 10:50 11:30 12:10 12:50 13:30 14:10 14:50 15:20 16:10 16:50 17:30 18:10 18:50 19:30 20:10 20:50 21:30 22:10\n"+
"\n"+"Plecări Sapientia -zile nelucrătoare\n" +
"\n" +
"05:20 06:15 06:50 07:30 08:10 08:50 09:30 10:10 10:50 11:30 12:10 12:50 13:30 14:10 14:50 15:20 16:10 16:50 17:30 18:10 18:50 19:30 20:10 20:50 21:30 22:10");
}
if (memonr==30){
orar.setText("30\n"+ "Plecări Centrofarm – zile nelucrătoare\n" +
"\n" +
"05:10 06:10 07:10 08:10 09:10 10:10 11:10 12:10 13:10 14:10 15:10 16:10 17:10 18:10 19:10 20:10 21:10\n" +
"\n"+
"Sosiri / Plecări Spitalul Județean – zile nelucrătoare\n" +
"\n" +
"05:30 06:30 07:30 08:30 09:30 10:30 11:30 12:30 13:30 14:30 15:30 16:30 17:30 18:30 19:30 20:30 21:30\n"+
"\n"+"30b\n"+ "Plecări Belvedere – zile nelucrătoare\n" +
"\n" +
"05:20 06:20 07:20 08:20 09:20 10:20 11:20 12:20 13:20 14:20 15:20 16:20 17:20 18:20 19:20 20:20 21:20\n" +
"\n" +
"Sosiri / Plecări Spitalul Județean – zile nelucrătoare\n" +
"\n" +
"05:45 06:45 07:45 08:45 09:45 10:45 11:45 12:45 13:45 14:45 15:45 16:45 17:45 18:45 19:45 20:45 21:45");
}
}
/* imagine=(ImageView)findViewById(R.id.androidIV) ;
imagine.setImageResource(R.drawable.android);*/
}
public void afisareruta(View view){
spatiualb=(EditText)findViewById(R.id.spatiu);
ruta=(TextView)findViewById(R.id.ruta);
memonr= Integer.parseInt(spatiualb.getText().toString());
if(memonr==19){
ruta.setText("Centrofarm – Piaţa Diamant – Înfrăţirii – Fortuna – Lalelelor – Izvor – P-ţa Trandafirilor – Papiu Ilarian – Mihai Eminescu – Clinica O.R.L – SMURD – Secuilor Martirii – Gara Mică – P-ţa Teatrului – Poli 2 – Europa – Buşteni – Pocloş – Tudor Vladimirescu – Piaţa Diamant –Centrofarm");
}
if(memonr==20){
ruta.setText("Centrofarm – Corina – Fortuna – Lalelelor – Izvor – P-ţa Trandafirilor – Revoluţiei – P-ţa Republicii – 22 Decembrie 1989 – Spitalul Judeţean – Parcul Eroilor – Clinica de Oncologie – Braseria Universităţii – Nicolae Iorga – P-ţa Teatrului – Poli 2 – Europa – Buşteni – B-Dul 1Dec.1918 – Regele Ferdinand – Solidaritatea – Centrofarm\n" +
"\n");
}
if(memonr==17){
ruta.setText("European Retail Park – Metro – Conserve – Record – Prodcomplex – Autogara Voiajor – Trecătorul – Mocca – Poli 2 – Europa – Buşteni – B-Dul 1Dec. 1918 – Regele Ferdinand – Solidaritatea – Centrofarm – Masini de calcul – Centrofarm – Corina – Fortuna – Lalelelor – Izvor – Mocca – Gara CFR – Autogara Voiajor – Traian Vuia – Record 2 – Gheorghe Doja – Chimie – Metro –Combinat – European Retail Park\n" +
"\n");
}
if(memonr==44){
ruta.setText("Sapientia – Regele Ferdinand – Solidaritatea – Piaţa Diamant – Înfrăţirii – Fortuna – Moldovei – Macul Roşu–PANDURU – IZVORU RECE – Predeal – Cireşului – Dâmbul Pietros – Ciucaş – Gara CFR – Autogara Voiajor – Traian Vuia – Record 2 –Gheorghe Doja – Chimie – Metro – Combinat –European Retail Park – Metro – Conserve – Record – Prodcomplex – Autogara Voiajor – Trecătorul – Olimp – Cosmos – Avram Iancu – Predeal – IZVORU RECE – PANDURU – Macul Roşu – Moldovei – Poclos – Tudor Vladimirescu – Piaţa Diamant – Corina 2 – Sapientia\n" +
"\n");
}
if(memonr==30){
ruta.setText("30\n"+"Centrofarm – Corina – Fortuna – Lalelelor – Stefan cel Mare – Targului – Revoluţiei – P-ţa Republicii – 22 Decembrie 1989 – Spitalul Judeţean – Parcul Eroilor – Clinica de Oncologie – Braseria Universităţii – Nicolae Iorga – Targului – Stefan cel Mare – Europa – Buşteni – B-dul 1Dec.1918 – Regele Ferdinand – Solidaritatea – Centrofarm\n"+
"30b\n"+"Belvedere – Transilvania– Mari Cristi – Fortuna – Lalelelor – Izvor – Piața Trandafirilor – Revoluţiei – P-ţa Republicii – 22 Decembrie 1989 – Spitalul Judeţean – Parcul Eroilor – Clinica de Oncologie – Braseria Universităţii – Nicolae Iorga – Piata Teatrului – Poli 2 – Europa – Buşteni – Pandurilor – Mari Cristi– MBO – Belvedere\n" +
"\n");
}
}
public void startTaxi(View view){
startActivity(new Intent(this, TaxiClass.class));
}
}
And java file 2 :
package com.example.paul_2.bus;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
/**
* Created by paul_2 on 3/16/17.
*/
public class TaxiClass extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.taxi);
}
}