我开发了一个Android应用程序。当我加载另一个这样的布局时,我的应用程序崩溃我不知道怎么解释!!!!请给我一个关键字或一切来搜索和调试它! 我的应用可以启动并加载主要活动
logcat
[ 03-27 06:37:57.264 1419: 1419 D/ ]
HostConnection::get() New Host Connection established 0xb8073fa8, tid 1419
03-27 06:37:57.272 1419-1419/com.xuanlocfashion.xuanlocfashion D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so
03-27 06:37:57.272 1419-1419/com.xuanlocfashion.xuanlocfashion D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
03-27 06:37:57.336 1419-1419/com.xuanlocfashion.xuanlocfashion W/EGL_genymotion: eglSurfaceAttrib not implemented
03-27 06:37:57.336 1419-1419/com.xuanlocfashion.xuanlocfashion E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from GradienCache
03-27 06:37:57.336 1419-1419/com.xuanlocfashion.xuanlocfashion E/OpenGLRenderer: MAX_TEXTURE_SIZE: 16384
03-27 06:37:57.348 1419-1419/com.xuanlocfashion.xuanlocfashion E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
03-27 06:37:57.352 1419-1419/com.xuanlocfashion.xuanlocfashion E/OpenGLRenderer: MAX_TEXTURE_SIZE: 16384
03-27 06:37:57.352 1419-1419/com.xuanlocfashion.xuanlocfashion D/OpenGLRenderer: Enabling debug mode 0
03-27 06:38:00.036 1419-1419/com.xuanlocfashion.xuanlocfashion I/Choreographer: Skipped 69 frames! The application may be doing too much work on its main thread.
03-27 06:38:05.540 1419-1419/com.xuanlocfashion.xuanlocfashion D/AndroidRuntime: Shutting down VM
03-27 06:38:05.540 1419-1419/com.xuanlocfashion.xuanlocfashion W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d5eb20)
03-27 06:38:05.540 1419-1419/com.xuanlocfashion.xuanlocfashion E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xuanlocfashion.xuanlocfashion, PID: 1419
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xuanlocfashion.xuanlocfashion/com.xuanlocfashion.xuanlocfashion.DatLichHenActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xuanlocfashion.xuanlocfashion.DatLichHenActivity.intentButton(DatLichHenActivity.java:189)
at com.xuanlocfashion.xuanlocfashion.DatLichHenActivity.onCreate(DatLichHenActivity.java:50)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
package com.xuanlocfashion.xuanlocfashion;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button buttonDatDichVu;
Button buttonGioiThieu;
ImageView imvSuaQuanAo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonDatDichVu = (Button)findViewById(R.id.buttonDatDichVu);
buttonGioiThieu = (Button)findViewById(R.id.buttonGioiThieu);
imvSuaQuanAo = (ImageView)findViewById(R.id.imvSuaQuanAo);
intentButton();
}
protected void openDatDichVu(){
Intent myIntent = new Intent(this, DatLichHenActivity.class);
startActivity(myIntent);
}
protected void openGioiThieu(){
Intent myIntent = new Intent(this, GioiThieuActivity.class);
startActivity(myIntent);
}
protected void openSuaQuanAo(){
Intent myIntent = new Intent(this, SuaQuanAoActivity.class);
startActivity(myIntent);
}
protected void intentButton(){
buttonDatDichVu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openDatDichVu();
}
});
buttonGioiThieu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openGioiThieu();
}
});
imvSuaQuanAo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openSuaQuanAo();
}
});
}
}
y布局。 非常感谢!
// PS logcat中没什么,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_datlichhen"
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.xuanlocfashion.xuanlocfashion.DatLichHenActivity">
<CheckBox
android:text="Giặt sấy tận nơi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="21dp"
android:id="@+id/checkBoxGiatUi"
android:layout_below="@+id/textView6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:text="Sửa quần áo tận nơi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBoxSuaQuanAo"
android:layout_alignBaseline="@+id/checkBoxGiatUi"
android:layout_alignBottom="@+id/checkBoxGiatUi"
android:layout_toRightOf="@+id/textView6"
android:layout_toEndOf="@+id/textView6" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Tên của bạn"
android:ems="10"
android:layout_below="@+id/checkBoxGiatUi"
android:layout_marginTop="22dp"
android:id="@+id/editTextHoTen"
android:singleLine="false"
android:selectAllOnFocus="false"
android:maxLength="15"
android:textColor="@color/colorAccent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="70dp"
app:srcCompat="@drawable/hotline"
android:id="@+id/imageViewGoiNgay"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="false"
android:layout_centerVertical="false"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="true"
android:layout_centerInParent="false" />
<TextView
android:text="Đặt lịch hẹn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:textColor="@color/colorPrimary"
android:id="@+id/textView5"
android:layout_marginTop="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="Bạn muốn sử dụng dịch vụ gì?"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:id="@+id/textView6"
android:layout_below="@+id/textView5"
android:layout_alignParentStart="true" />
<Button
android:text="Đặt ngay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonDatNgay"
android:textSize="30dp"
android:layout_weight="0.16"
android:textColor="@color/colorAccent"
android:gravity="center"
android:layout_above="@+id/imageViewGoiNgay"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Địa chỉ"
android:inputType="textPersonName"
android:ems="10"
android:textSize="8pt"
android:id="@+id/edtDiaChi"
android:layout_below="@+id/editTextSoDienThoai"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/editTextSoDienThoai"
android:hint="Số điện thoại"
tools:maxLength="13"
android:textColor="@color/colorAccent"
android:layout_below="@+id/editTextHoTen"
android:layout_alignParentStart="true" />
<TextView
android:text="Bạn muốn sửa sản phẩm gì?"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="@+id/textView4"
android:layout_alignBaseline="@+id/btnChonLoaiDo"
android:layout_alignBottom="@+id/btnChonLoaiDo"
android:layout_alignParentStart="true" />
<Button
android:text="Chọn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnChonLoaiDo"
android:layout_marginBottom="19dp"
android:layout_above="@+id/buttonDatNgay"
android:layout_toEndOf="@+id/textView4" />
</RelativeLayout>
package com.xuanlocfashion.xuanlocfashion;
import android.Manifest;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
public class DatLichHenActivity extends AppCompatActivity {
CheckBox checkBoxGiatUi;
CheckBox checkBoxSuaQuanAo;
EditText editTextHoTen;
EditText editTextSoDienThoai;
Button buttonDatNgay;
ImageView imageViewGoiNgay;
SmsManager sms;
String hotlineXuanLocFashion1 = "0908418036";
String hotlineXuanLocFashion2 = "0936208806";
String smsMessage;
Button btnChonLoaiDo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dat_lich_hen);
AnhXa();
GuiMessage();
imageViewGoiNgay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
call();
}
});
intentButton();
}
private void GuiMessage() {
sms = SmsManager.getDefault();
smsMessage = editTextHoTen.getText().toString() + " " + editTextSoDienThoai.getText().toString() + " " + " ";
buttonDatNgay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkBoxGiatUi.isChecked()) {
smsMessage += "(GU)";
}
if (checkBoxSuaQuanAo.isChecked())
smsMessage += "(SQA)";
dialogDatLichHen();
}
});
}
private void AnhXa() {
checkBoxGiatUi = (CheckBox) findViewById(R.id.checkBoxGiatUi);
checkBoxSuaQuanAo = (CheckBox) findViewById(R.id.checkBoxSuaQuanAo);
editTextHoTen = (EditText) findViewById(R.id.editTextHoTen);
editTextSoDienThoai = (EditText) findViewById(R.id.editTextSoDienThoai);
buttonDatNgay = (Button) findViewById(R.id.buttonDatNgay);
imageViewGoiNgay = (ImageView) findViewById(R.id.imageViewGoiNgay);
}
protected void call() {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + hotlineXuanLocFashion1));//change the number
if (ActivityCompat.checkSelfPermission(DatLichHenActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
if (ActivityCompat.checkSelfPermission(DatLichHenActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
startActivity(callIntent);
}
protected void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
// SMS sent
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
// SMS fail without reason
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
// No service
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
// Null PDU
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
// Radio off
break;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
// SMS delivered"
break;
case Activity.RESULT_CANCELED:
// SMS not delivered
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
protected void dialogDatLichHen() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// khởi tạo dialog
alertDialogBuilder.setMessage("Đặt lịch hẹn ngay.");
// thiết lập nội dung cho dialog
alertDialogBuilder.setPositiveButton("Đồng ý", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
sendSMS(hotlineXuanLocFashion1, smsMessage);
sendSMS(hotlineXuanLocFashion2, smsMessage);
}
});
alertDialogBuilder.setNegativeButton("Không", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
// button "no" ẩn dialog đi
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
// tạo dialog
alertDialog.show();
// hiển thị dialog
}
protected void openChonLoaiDo(){
Intent myIntent = new Intent(this, ChonLoaiDoActivity.class);
startActivity(myIntent);
}
protected void intentButton(){
btnChonLoaiDo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openChonLoaiDo();
}
});
}
}
答案 0 :(得分:0)
我尝试在您的DatLichHenActivity.java
中运行您的代码。可能您忘记了Button btnChonLoaiDo;
的视图,因此它会在那里生成空对象引用。