java - Input event app issues -


i'm working through input event app. app has textfield , button. information entered sent receiver app handles action , must able write textview in main activity. explanation not confusing.

this built main app from: http://developer.android.com/guide/topics/ui/ui-events.html

this built receiver from: http://developer.android.com/training/sharing/receive.html

the main app loads layout blank. receiver crashes on load. can't figure out why, assistance appreciated.

mainactivity.java (main app)

package com.miller.main;  import java.util.list; import android.app.activity; import android.content.intent; import android.content.pm.packagemanager; import android.content.pm.resolveinfo; import android.os.bundle; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button;  public class mainactivity extends activity {      protected void oncreate(bundle savedinstancestate, bundle savedvalues) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);       // capture our button layout         final button button = (button)findviewbyid(r.id.corky);         onclicklistener mcorkylistener = null;         // register onclick listener implementation above         button.setonclicklistener(mcorkylistener);       // create anonymous implementation of onclicklistener         @suppresswarnings("unused") onclicklistener mcorkylistener1 = new onclicklistener() {             @suppresswarnings("null")             public void onclick(view v) {               // when button clicked                 // capture our button layout                 button.setonclicklistener(this);                 intent sendintent = new intent();                 sendintent.setaction(intent.action_send);                 sendintent.putextra(intent.extra_text, "this text send.");                 sendintent.settype("text/plain");                 packagemanager packagemanager = getpackagemanager();                 intent intent = null;                 list<resolveinfo> activities = packagemanager.queryintentactivities(intent, 0);                 boolean isintentsafe = activities.size() > 0;                 intent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_top);                 startactivity(sendintent);             }         };     }     @override     protected void onpause() {         log.w("monday", "paused");         super.onpause();         log.w("monday", "paused");         // activity taking focus (this activity "paused").     }     @override     protected void onstop() {         log.w("tuesday", "stopped");         super.onstop();         log.w("tuesday", "stopped");         // activity no longer visible (it "stopped")     } } 

activity_main.xml (main app)

<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="com.miller.main.mainactivity" >      <edittext         android:id="@+id/text_field"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:hint="@string/text_field"         android:inputtype="text" />      <button         android:id="@+id/corky"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/button_text"         android:layout_below="@+id/text_field" />  </relativelayout> 

mainactivity.java (receiver app)

package com.miller.receiver;  import java.util.arraylist; import android.app.activity; import android.content.intent; import android.net.uri; import android.os.bundle;  public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     }  // intent, action , mime type     intent intent = getintent();     string action = intent.getaction();     string type = intent.gettype(); {      if (intent.action_send.equals(action) && type != null) {         if ("text/plain".equals(type)) {             handlesendtext(intent); // handle text being sent         } else if (type.startswith("image/")) {             handlesendimage(intent); // handle single image being sent         }     } else if (intent.action_send_multiple.equals(action) && type != null) {         if (type.startswith("image/")) {             handlesendmultipleimages(intent); // handle multiple images being sent         }     } else {         // handle other intents, such being started home screen     } }  void handlesendtext(intent intent) {     string sharedtext = intent.getstringextra(intent.extra_text);     if (sharedtext != null) {         // update ui reflect text being shared     } }  void handlesendimage(intent intent) {     uri imageuri = (uri) intent.getparcelableextra(intent.extra_stream);     if (imageuri != null) {         // update ui reflect image being shared     } }  void handlesendmultipleimages(intent intent) {     arraylist<uri> imageuris = intent.getparcelablearraylistextra(intent.extra_stream);     if (imageuris != null) {         // update ui reflect multiple images being shared     } } } 

activity_main.xml receiver app default @ moment.

logcat receiver app

04-09 15:41:11.244: e/androidruntime(1114): fatal exception: main 04-09 15:41:11.244: e/androidruntime(1114): process: com.miller.receiver, pid: 1114 04-09 15:41:11.244: e/androidruntime(1114): java.lang.runtimeexception: unable instantiate activity componentinfo{com.miller.receiver/com.miller.receiver.mainactivity}: java.lang.nullpointerexception 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2121) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2245) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.activitythread.access$800(activitythread.java:135) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.activitythread$h.handlemessage(activitythread.java:1196) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.os.handler.dispatchmessage(handler.java:102) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.os.looper.loop(looper.java:136) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.activitythread.main(activitythread.java:5017) 04-09 15:41:11.244: e/androidruntime(1114):     @ java.lang.reflect.method.invokenative(native method) 04-09 15:41:11.244: e/androidruntime(1114):     @ java.lang.reflect.method.invoke(method.java:515) 04-09 15:41:11.244: e/androidruntime(1114):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 04-09 15:41:11.244: e/androidruntime(1114):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 04-09 15:41:11.244: e/androidruntime(1114):     @ dalvik.system.nativestart.main(native method) 04-09 15:41:11.244: e/androidruntime(1114): caused by: java.lang.nullpointerexception 04-09 15:41:11.244: e/androidruntime(1114):     @ com.miller.receiver.mainactivity.<init>(mainactivity.java:20) 04-09 15:41:11.244: e/androidruntime(1114):     @ java.lang.class.newinstanceimpl(native method) 04-09 15:41:11.244: e/androidruntime(1114):     @ java.lang.class.newinstance(class.java:1208) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.instrumentation.newactivity(instrumentation.java:1061) 04-09 15:41:11.244: e/androidruntime(1114):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2112) 04-09 15:41:11.244: e/androidruntime(1114):     ... 11 more 


Popular posts from this blog