0

私はAndroidで簡単なアプリケーションを設計しましたが、エミュレーターで実行するとアプリケーションが停止したことが表示されます...解決策を見つけようとしてブレークポイントを使用しました...しかし、ブレークポイントを設定してアプリケーションをデバッグすると、「ソースが見つかりません」と表示されますddmsの観点から

ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent).

ここにいる誰かが私が今していることを提案できますか...

これは私のログがどのように見えるかです

02-20 04:28:21.232: D/AndroidRuntime(607): Shutting down VM
02-20 04:28:21.232: W/dalvikvm(607): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-20 04:28:21.262: E/AndroidRuntime(607): FATAL EXCEPTION: main
02-20 04:28:21.262: E/AndroidRuntime(607): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.apps/com.example.apps.Act}: java.lang.NullPointerException
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.os.Looper.loop(Looper.java:123)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-20 04:28:21.262: E/AndroidRuntime(607):  at java.lang.reflect.Method.invokeNative(Native Method)
02-20 04:28:21.262: E/AndroidRuntime(607):  at java.lang.reflect.Method.invoke(Method.java:521)
02-20 04:28:21.262: E/AndroidRuntime(607):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-20 04:28:21.262: E/AndroidRuntime(607):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-20 04:28:21.262: E/AndroidRuntime(607):  at dalvik.system.NativeStart.main(Native Method)
02-20 04:28:21.262: E/AndroidRuntime(607): Caused by: java.lang.NullPointerException
02-20 04:28:21.262: E/AndroidRuntime(607):  at com.example.apps.Act.onCreate(Act.java:16)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-20 04:28:21.262: E/AndroidRuntime(607):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-20 04:28:21.262: E/AndroidRuntime(607):  ... 11 more
02-20 04:28:31.283: I/Process(607): Sending signal. PID: 607 SIG: 9

アクティビティクラス

package com.example.apps; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 

public class Act extends Activity { 

    Rest r=new Rest(); 

@Override 
public void onCreate(Bundle savedInstanceState) {  
   super.onCreate(savedInstanceState); 
   Button save=(Button)findViewById(R.id.save); 
   save.setOnClickListener(onSave); 
} 

private View.OnClickListener onSave=new View.OnClickListener() { 

     public void onClick(View v) { 
         EditText name=(EditText)findViewById(R.id.name); 
         EditText address=(EditText)findViewById(R.id.addr);  
         r.setName(name.getText().toString());
         r.setAddress(address.getText().toString()); 
     }  
}; 

} 
4

1 に答える 1

0

To make it easy, let's change your onClick() like

save.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
  // do stuff here
}
});

Where save is your button. From now on, edit your question with the updated code so its easier to read. I was having trouble reading your code in the comment but it looks like if you change it like this it should work for you. Here is a good discussion about the different ways to use onClick()

I was going to delete but this information may help others. However, as pointed out by @dymmeh setContentView() isn't called so there is no layout to get your button from. This needs to be called with the appropriate layout, R.layout.your_layout before you can reference any views, Buttons, EditText, etc...

于 2013-02-19T23:13:41.207 に答える