我正在创建一个应用程序,它从用户那里获取一些数据并通过短信发送给一个号码。 但我得到一个运行时异常作为错误充气类。 请试着找出我做错了什么。 谢谢
public class MainActivity extends Activity implements OnClickListener {
Button submit;
EditText dst;
EditText name;
EditText roll;
EditText txt;
String phoneNumber="525252";
GPSTracker gps;
double lat,lon;
String message;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submit = (Button) findViewById(R.id.button1);
dst = (EditText) findViewById(R.id.editText1);
name = (EditText) findViewById(R.id.editText2);
roll = (EditText) findViewById(R.id.editText3);
txt = (EditText) findViewById(R.id.editText4);
gps = new GPSTracker(MainActivity.this);
// Check if GPS enabled
if(gps.canGetLocation()) {
lat = gps.getLatitude();
lon = gps.getLongitude();
Toast.makeText(getBaseContext(), "Your Location is - \nLat: " + lat + "\nLong: " + lon, Toast.LENGTH_LONG).show();
}
else {
// Can't get location.
// GPS or network is not enabled.
// Ask user to enable GPS/network in settings.
gps.showSettingsAlert();
}
submit.setOnClickListener(this);
}
public void onClick(View v)
{
String dmd = dst.getText().toString();
String nm = name.getText().toString();
String md = roll.getText().toString();
String msg = txt.getText().toString();
String latt = Double.toString(lat);
String lngg = Double.toString(lon);
if (dmd.length()>0 && msg.length()>0 && nm.length()>0 && md.length()>0)
{
message = "VISIT."+dmd+"."+nm+"."+md+"."+msg+"."+latt +"."+lngg;
sendSMS(phoneNumber,message);
}
else
Toast.makeText(getBaseContext(),
"Please fill all the entries.",
Toast.LENGTH_LONG).show();
}
//---sends a SMS message to another device---
private void sendSMS(String phoneNumber, String message)
{
/*
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, test.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
*/
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:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
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:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
}
这是我的主要活动
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/abc_action_bar_icon_vertical_padding"
tools:context="com.mts.visit.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_marginLeft="31dp"
android:layout_marginTop="78dp"
android:text="DST :" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:text="Name :" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="51dp"
android:text="Roll :" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:inputType="phone" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView3"
android:layout_toRightOf="@+id/textView1"
android:ems="10" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText2"
android:ems="10" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_centerVertical="true"
android:text="Message:" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView4"
android:layout_marginTop="20dp"
android:ems="13"
android:inputType="textMultiLine"
android:minWidth="@dimen/dialog_fixed_height_major" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText4"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:text="Submit" />
</RelativeLayout>
这是activity_main.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
我将这些权限包含在清单中。
06-20 15:29:37.630: W/dalvikvm(1371): threadid=1: thread exiting with uncaught exception (group=0xb3addba8)
06-20 15:29:37.660: E/AndroidRuntime(1371): FATAL EXCEPTION: main
06-20 15:29:37.660: E/AndroidRuntime(1371): Process: com.mts.visit, PID: 1371
06-20 15:29:37.660: E/AndroidRuntime(1371): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mts.visit/com.mts.visit.MainActivity}: android.view.InflateException: Binary XML file line #74: Error inflating class <unknown>
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.os.Handler.dispatchMessage(Handler.java:102)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.os.Looper.loop(Looper.java:136)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-20 15:29:37.660: E/AndroidRuntime(1371): at java.lang.reflect.Method.invokeNative(Native Method)
06-20 15:29:37.660: E/AndroidRuntime(1371): at java.lang.reflect.Method.invoke(Method.java:515)
06-20 15:29:37.660: E/AndroidRuntime(1371): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-20 15:29:37.660: E/AndroidRuntime(1371): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-20 15:29:37.660: E/AndroidRuntime(1371): at dalvik.system.NativeStart.main(Native Method)
06-20 15:29:37.660: E/AndroidRuntime(1371): Caused by: android.view.InflateException: Binary XML file line #74: Error inflating class <unknown>
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
06-20 15:29:37.660: E/AndroidRuntime(1371): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-20 15:29:37.660: E/AndroidRuntime(1371): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.Activity.setContentView(Activity.java:1929)
06-20 15:29:37.660: E/AndroidRuntime(1371): at com.mts.visit.MainActivity.onCreate(MainActivity.java:33)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.Activity.performCreate(Activity.java:5231)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-20 15:29:37.660: E/AndroidRuntime(1371): ... 11 more
06-20 15:29:37.660: E/AndroidRuntime(1371): Caused by: java.lang.reflect.InvocationTargetException
06-20 15:29:37.660: E/AndroidRuntime(1371): at java.lang.reflect.Constructor.constructNative(Native Method)
06-20 15:29:37.660: E/AndroidRuntime(1371): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
06-20 15:29:37.660: E/AndroidRuntime(1371): ... 24 more
06-20 15:29:37.660: E/AndroidRuntime(1371): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x6
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:464)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.view.View.<init>(View.java:3784)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.widget.TextView.<init>(TextView.java:623)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.widget.EditText.<init>(EditText.java:60)
06-20 15:29:37.660: E/AndroidRuntime(1371): at android.widget.EditText.<init>(EditText.java:56)
06-20 15:29:37.660: E/AndroidRuntime(1371): ... 27 more
我认为错误在于膨胀视图,但我不知道如何解决它 请帮助我,因为我是新手。
答案 0 :(得分:0)
你应该为@ dimen / dialog_fixed_height_major提供价值来解决这个问题。