0

我对 StackOverFlow 比较陌生,所以如果我在这里格式化错误或其他新手错误,请原谅我并随时编辑我的帖子以使其清楚。我会确保不再重复这些错误。

无论如何,我正在为我高中的计算机科学课开发一个安卓应用程序(非常基础),而且我相对接近完成。我真的很沮丧,因为我的应用程序的一个方面一直导致应用程序崩溃并给出错误“不幸的是应用程序已停止”。我想知道你们是否可以帮助我。

基本上,我的意思是这个人在文本字段(EditText)中输入他们的名字,然后他们选择 1/2 的单选按钮(英语或法语问候语),然后下面的标签(TextView)应该是根据单选按钮选择显示为 Hello +“他们的姓名输入”或 Bonjour。但是,输入后,当我单击“显示!”时,应用程序就会崩溃!按钮。我很感激我能从你们那里得到的任何帮助:)

请在下面找到 java 和 xml 文件:------------------------------------

    import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    private EditText text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @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;
    }

    /** Mouse Listener AKA Called soon as user clicks the Send button */
    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }

    public void showAboutMessage(View v){
        Toast.makeText(this, "Grade 12 Student @ Bluevale Collegiate Institute!", Toast.LENGTH_LONG).show();
    } 


    private boolean flipsided = false;
    public void flipImage (View view){
        ImageView portrait = (ImageView)
        findViewById (R.id.faceImageView);

        if(flipsided){
            portrait.setImageResource(R.drawable.normal);
        }else{
            Toast.makeText(this, "Yes, that's me in NYC :)", Toast.LENGTH_LONG).show();
        }
        flipsided=!flipsided;
    }

    @SuppressLint("DefaultLocale")
    public void onClick(View view){
            RadioButton engButton = (RadioButton) findViewById(R.id.radioButton1);
            RadioButton frenchButton = (RadioButton) findViewById(R.id.radioButton2);

            if(text.getText().length() == 0){
                Toast.makeText(this, "Please enter a valid name!",Toast.LENGTH_LONG).show();
                return;
            }
            TextView label = (TextView) findViewById(R.id.JLabel);

            if(engButton.isChecked()){
                label.setText("Hello" + text.getText().toString().toUpperCase());
                frenchButton.setChecked(false);
                engButton.setChecked(true);
            }else{
                label.setText("Bonjour" + text.getText().toString().toUpperCase());
                frenchButton.setChecked(false);
                engButton.setChecked(true);

        }
    }

然后这是我的 XML 文件: ------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<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:orientation="horizontal"
    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=".MainActivity" >

    <CheckedTextView
        android:id="@+id/checkedTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/my_name"
        android:textSize="27sp" />

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkedTextView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="1dp" />

    <ImageView
        android:id="@+id/faceImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/ratingBar1"
        android:layout_marginTop="20dp"
        android:onClick="flipImage"
        android:src="@drawable/normal" />

    <CheckedTextView
        android:id="@+id/checkedTextView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="21dp"
        android:text="@string/rate" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/faceImageView"
        android:layout_below="@+id/aboutMeButton"
        android:layout_marginTop="14dp"
        android:onClick="sendMessage"
        android:text="@string/button_send" />

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignLeft="@+id/faceImageView"
        android:ems="10"
        android:hint="@string/edit_message" />

    <Button
        android:id="@+id/aboutMeButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkedTextView1"
        android:layout_centerHorizontal="true"
        android:onClick="showAboutMessage"
        android:text="@string/about" />

</RelativeLayout>

第二个 XML 文件 -------------------

<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=".DisplayMessageActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:ems="10"
        android:hint="@string/enter_name" />

    <Button
        android:id="@+id/button13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:onClick="onClick"
        android:text="@string/button_print" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_centerVertical="true" >


    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/JLabel"
        android:layout_below="@+id/radioGroup1"
        android:layout_marginTop="23dp"
        android:text="@string/radio_button2"
        android:textSize="20sp" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/radioButton2"
        android:layout_alignLeft="@+id/radioButton2"
        android:layout_marginBottom="40dp"
        android:checked="true"
        android:text="@string/radio_button1"
        android:textSize="20sp" />

    </RadioGroup>

    <TextView
        android:id="@+id/JLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/radioGroup1"
        android:layout_below="@+id/radioGroup1"
        android:layout_marginTop="30dp"
        android:text="@string/JLabel"
        android:textSize="18sp" />

</RelativeLayout>

这是我的 logcat 文件:

06-18 21:13:04.859: D/AndroidRuntime(1826): Shutting down VM
06-18 21:13:04.859: W/dalvikvm(1826): threadid=1: thread exiting with uncaught exception (group=0xb4d14908)
06-18 21:13:04.859: E/AndroidRuntime(1826): FATAL EXCEPTION: main
06-18 21:13:04.859: E/AndroidRuntime(1826): java.lang.IllegalStateException: Could not find a method onClick(View) in the activity class com.example.bci_snsapplication.DisplayMessageActivity for onClick handler on view class android.widget.Button with id 'button13'
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.view.View$1.onClick(View.java:3584)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.view.View.performClick(View.java:4202)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.view.View$PerformClick.run(View.java:17340)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.os.Handler.handleCallback(Handler.java:725)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.os.Looper.loop(Looper.java:137)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.app.ActivityThread.main(ActivityThread.java:5039)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at java.lang.reflect.Method.invokeNative(Native Method)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at java.lang.reflect.Method.invoke(Method.java:511)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at dalvik.system.NativeStart.main(Native Method)
06-18 21:13:04.859: E/AndroidRuntime(1826): Caused by: java.lang.NoSuchMethodException: onClick [class android.view.View]
06-18 21:13:04.859: E/AndroidRuntime(1826):     at java.lang.Class.getConstructorOrMethod(Class.java:460)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at java.lang.Class.getMethod(Class.java:915)
06-18 21:13:04.859: E/AndroidRuntime(1826):     at android.view.View$1.onClick(View.java:3577)
06-18 21:13:04.859: E/AndroidRuntime(1826):     ... 11 more
06-18 21:13:04.899: E/DropBoxManagerService(1192): Can't write: data_app_crash
06-18 21:13:04.899: E/DropBoxManagerService(1192): java.io.IOException: Can't mkdir: /data/system/dropbox
06-18 21:13:04.899: E/DropBoxManagerService(1192):  at com.android.server.DropBoxManagerService.init(DropBoxManagerService.java:582)
06-18 21:13:04.899: E/DropBoxManagerService(1192):  at com.android.server.DropBoxManagerService.add(DropBoxManagerService.java:185)
06-18 21:13:04.899: E/DropBoxManagerService(1192):  at android.os.DropBoxManager.addText(DropBoxManager.java:272)
06-18 21:13:04.899: E/DropBoxManagerService(1192):  at com.android.server.am.ActivityManagerService$12.run(ActivityManagerService.java:8545)
06-18 21:13:04.909: W/ActivityManager(1192):   Force finishing activity com.example.bci_snsapplication/.DisplayMessageActivity
06-18 21:13:05.219: W/Trace(1192): Unexpected value from nativeGetEnabledTags: 0
06-18 21:13:05.219: W/Trace(1192): Unexpected value from nativeGetEnabledTags: 0

更多 LOGCAT 详细信息----------------------------------------------------------- ----------

06-18 22:47:25.029: W/Trace(1663): Unexpected value from nativeGetEnabledTags: 0
06-18 22:47:25.029: D/ExchangeService(1663): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false
06-18 22:47:25.029: W/Trace(1663): Unexpected value from nativeGetEnabledTags: 0
06-18 22:47:25.029: W/ActivityManager(1193): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
06-18 22:47:25.036: D/ExchangeService(1663): !!! Email application not found; stopping self
06-18 22:47:25.036: W/Trace(1663): Unexpected value from nativeGetEnabledTags: 0
06-18 22:47:25.056: W/ActivityManager(1193): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
06-18 22:47:25.056: W/Trace(1663): Unexpected value from nativeGetEnabledTags: 0
06-18 22:47:25.056: E/ActivityThread(1663): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b5036390 that was originally bound here
06-18 22:47:25.056: E/ActivityThread(1663): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b5036390 that was originally bound here
06-18 22:47:25.056: E/ActivityThread(1663):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-18 22:47:25.056: E/ActivityThread(1663):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-18 22:47:25.056: E/ActivityThread(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-18 22:47:25.056: E/ActivityThread(1663):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-18 22:47:25.056: E/ActivityThread(1663):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 22:47:25.056: E/ActivityThread(1663):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 22:47:25.056: E/ActivityThread(1663):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 22:47:25.056: E/ActivityThread(1663):     at java.lang.Thread.run(Thread.java:856)
06-18 22:47:25.088: E/StrictMode(1663): null
06-18 22:47:25.088: E/StrictMode(1663): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b5036390 that was originally bound here
06-18 22:47:25.088: E/StrictMode(1663):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-18 22:47:25.088: E/StrictMode(1663):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-18 22:47:25.088: E/StrictMode(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-18 22:47:25.088: E/StrictMode(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-18 22:47:25.088: E/StrictMode(1663):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-18 22:47:25.088: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-18 22:47:25.088: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-18 22:47:25.088: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-18 22:47:25.088: E/StrictMode(1663):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-18 22:47:25.088: E/StrictMode(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-18 22:47:25.088: E/StrictMode(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-18 22:47:25.088: E/StrictMode(1663):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-18 22:47:25.088: E/StrictMode(1663):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 22:47:25.088: E/StrictMode(1663):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 22:47:25.088: E/StrictMode(1663):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 22:47:25.088: E/StrictMode(1663):     at java.lang.Thread.run(Thread.java:856)
06-18 22:47:25.088: W/ActivityManager(1193): Unbind failed: could not find connection for android.os.BinderProxy@b51f0d58
06-18 22:47:25.096: E/ActivityThread(1663): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b50238c8 that was originally bound here
06-18 22:47:25.096: E/ActivityThread(1663): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b50238c8 that was originally bound here
06-18 22:47:25.096: E/ActivityThread(1663):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-18 22:47:25.096: E/ActivityThread(1663):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-18 22:47:25.096: E/ActivityThread(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-18 22:47:25.096: E/ActivityThread(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-18 22:47:25.096: E/ActivityThread(1663):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-18 22:47:25.096: E/ActivityThread(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-18 22:47:25.096: E/ActivityThread(1663):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-18 22:47:25.096: E/ActivityThread(1663):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 22:47:25.096: E/ActivityThread(1663):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 22:47:25.096: E/ActivityThread(1663):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 22:47:25.096: E/ActivityThread(1663):     at java.lang.Thread.run(Thread.java:856)
06-18 22:47:25.108: E/StrictMode(1663): null
06-18 22:47:25.108: E/StrictMode(1663): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b50238c8 that was originally bound here
06-18 22:47:25.108: E/StrictMode(1663):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-18 22:47:25.108: E/StrictMode(1663):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-18 22:47:25.108: E/StrictMode(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-18 22:47:25.108: E/StrictMode(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-18 22:47:25.108: E/StrictMode(1663):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-18 22:47:25.108: E/StrictMode(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-18 22:47:25.108: E/StrictMode(1663):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-18 22:47:25.108: E/StrictMode(1663):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 22:47:25.108: E/StrictMode(1663):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 22:47:25.108: E/StrictMode(1663):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 22:47:25.108: E/StrictMode(1663):     at java.lang.Thread.run(Thread.java:856)
06-18 22:47:25.108: W/ActivityManager(1193): Unbind failed: could not find connection for android.os.BinderProxy@b539b310
06-18 22:47:25.436: W/Trace(1964): Unexpected value from nativeGetEnabledTags: 0



06-18 22:49:05.357: E/ActivityThread(1663): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b5085b08 that was originally bound here
06-18 22:49:05.357: E/ActivityThread(1663): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b5085b08 that was originally bound here
06-18 22:49:05.357: E/ActivityThread(1663):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-18 22:49:05.357: E/ActivityThread(1663):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-18 22:49:05.357: E/ActivityThread(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-18 22:49:05.357: E/ActivityThread(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-18 22:49:05.357: E/ActivityThread(1663):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-18 22:49:05.357: E/ActivityThread(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-18 22:49:05.357: E/ActivityThread(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-18 22:49:05.357: E/ActivityThread(1663):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-18 22:49:05.357: E/ActivityThread(1663):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-18 22:49:05.357: E/ActivityThread(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-18 22:49:05.357: E/ActivityThread(1663):     at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-18 22:49:05.357: E/ActivityThread(1663):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-18 22:49:05.357: E/ActivityThread(1663):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 22:49:05.357: E/ActivityThread(1663):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 22:49:05.357: E/ActivityThread(1663):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 22:49:05.357: E/ActivityThread(1663):     at java.lang.Thread.run(Thread.java:856)
06-18 22:49:05.357: E/StrictMode(1663): null
06-18 22:49:05.357: E/StrictMode(1663): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b5085b08 that was originally bound here
06-18 22:49:05.357: E/StrictMode(1663):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-18 22:49:05.357: E/StrictMode(1663):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-18 22:49:05.357: E/StrictMode(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-18 22:49:05.357: E/StrictMode(1663):     at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-18 22:49:05.357: E/StrictMode(1663):     at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-18 22:49:05.357: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-18 22:49:05.357: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-18 22:49:05.357: E/StrictMode(1663):     at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-18 22:49:05.357: E/StrictMode(1663):     at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-18 22:49:05.357: E/StrictMode(1663):     at 
4

1 回答 1

2

问题出在你的DisplayMessageActivity课上。看来你没有onClick()方法。因此,当您单击Button它时,它会崩溃。由于您在 xml 中有android:onClick="onClick",因此您需要该类中的函数,例如

public void onClick(View v)
{
    // put code here
}

EditText除非这是复制/粘贴错误,否则您似乎命名错误。你有

private EditText text;

但是你初始化

EditText editText = (EditText) findViewById(R.id.edit_message);

然后你尝试调用未初始化的函数text

if(text.getText().length() == 0){

导致一个NPE. 我不知道这些是否应该是两个不同的但是,无论哪种方式,我都没有看到text任何地方初始化

于 2013-06-18T19:53:54.827 回答