代码: package com.example.dxfs; import android.support.v7.app.ActionBarActivity; import android.support.v4.app.Fragment; import android.telephony.SmsManager; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; public class MainActivity extends ActionBarActivity implements OnClickListener{ private EditText putnum; private EditText putword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); putnum =(EditText) findViewById(R.id.put_num); putword =(EditText) findViewById(R.id.put_word); Button button=(Button) findViewById(R.id.bu); button.setOnClickListener(this); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()) .commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } } @Override public void onClick(View v) { // TODO Auto-generated method stub String number= putnum.getText().toString(); String word= putword.getText().toString(); SmsManager smsManager=SmsManager.getDefault(); smsManager.sendTextMessage(number, null, word, null, null); } } 控制台是这样的。 |
|
那是警告。不是异常。
|
|
问题是编译运行之后会出问题啊,直接就进不了了
|
|
报什么异常了吗
|
|
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix. |
|
你结合你的布局看看一下~~可能出错就在于Button这一块 你找一下~~
|
|
<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" tools:context=".MainActivity" > <TextView android:id="@+id/cd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cds" /> <EditText android:inputType="number" android:id="@+id/put_num" android:layout_below="@+id/cd" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/er" android:layout_below="@+id/put_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/ee" /> <EditText android:inputType="text" android:id="@+id/put_word" android:layout_below="@+id/er" android:layout_width="match_parent" android:layout_height="150dp" /> <Button android:id="@+id/bu" android:layout_below="@+id/put_word" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/by" /> </RelativeLayout> |
|
10分 |
android:layout_below=”@+id/put_word”
这里改成 android:layout_below=”@id/put_word” |
10分 |
+1 在@后面使用“+”,表示当修改完某个布局文件并保存后,系统会自动在R.java文件中 |
有结果了吗 亲
|