android - Unable to start Activity component info -


hello guys second time facing problem in last 2 days. guess there place in code in going horribly wrong. anyways trying here invoke method in class display particular text file in activity class.

mainactivity is:

package com.example.testflashfile;  public class mainactivity extends activity{     button nextbutton;     button playbutton;     button backbutton;     readtext readtext=new readtext(this);     context contextobject;     gesturedetector gesturedetector;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         requestwindowfeature(window.feature_no_title);         setrequestedorientation(activityinfo.screen_orientation_sensor);         setcontentview(r.layout.activity_main);          textview hellotxt = (textview)findviewbyid(r.id.displaytext);          hellotxt.settext(readtext.readtxt());          gesturedetector = new gesturedetector(this.getapplicationcontext(),new mygesturedetector());         view mainview = (view) findviewbyid(r.id.mainview);          // set touch listener main view our custom gesture listener         mainview.setontouchlistener(new view.ontouchlistener() {             public boolean ontouch(view v, motionevent event) {                 if (gesturedetector.ontouchevent(event)) {                     return true;                 }                 return false;             }         });          playbutton=(button)findviewbyid(r.id.play);         playbutton.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent startanimation=new intent(mainactivity.this,playanimationactivity.class);                 startanimation.putextra("swf_name","a");                 startactivity(startanimation);             }         });          nextbutton=(button)findviewbyid(r.id.next);         nextbutton.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent intent=new intent(mainactivity.this,secondactivity.class);                 startactivity(intent);              }         });          backbutton=(button)findviewbyid(r.id.back);         backbutton.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent intent=new intent(mainactivity.this,fifthactivity.class);                 startactivity(intent);              }         });     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.activity_main, menu);         return true;     }      public class mygesturedetector extends simpleongesturelistener   {          @override         public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {             if (math.abs(e1.gety() - e2.gety()) > globalvariables.swipe_max_off_path) {                 return false;             }              // right left swipe             if(e1.getx() - e2.getx() > globalvariables.swipe_min_distance && math.abs(velocityx) > globalvariables.swipe_threshold_velocity) {                  intent i= new intent(mainactivity.this,secondactivity.class);                 startactivity(i);                  //  left right  swipe             }  else if (e2.getx() - e1.getx() > globalvariables.swipe_min_distance && math.abs(velocityx) > globalvariables.swipe_threshold_velocity) {                   intent i= new intent(mainactivity.this,fifthactivity.class);                 startactivity(i);              }              return false;         }          @override         public boolean ondown(motionevent e) {             return true;         }     } } 

the method readtxt() defined in class below:

package com.example.testflashfile;  public class readtext {     context context;     public readtext(context c) {         context = c;         readtxt();     }      public string readtxt() {         inputstream inputstream = context.getresources().openrawresource(r.raw.textone);          bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream();          int i;         try {             = inputstream.read();             while (i != -1)             {                 bytearrayoutputstream.write(i);                 = inputstream.read();             }              inputstream.close();         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }         return bytearrayoutputstream.tostring();     }  } 

the manifest file :

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.testflashfile"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />      <application         android:allowbackup="true"         android:hardwareaccelerated="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.testflashfile.mainactivity"             android:label="@string/app_name"             android:screenorientation="portrait" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity             android:name="com.example.testflashfile.secondactivity"             android:screenorientation="portrait" >         </activity>         <activity             android:name="com.example.testflashfile.thirdactivity"             android:screenorientation="portrait" >         </activity>         <activity             android:name="com.example.testflashfile.fourthactivity"             android:screenorientation="portrait" >         </activity>         <activity             android:name="com.example.testflashfile.fifthactivity"             android:screenorientation="portrait" >         </activity>         <activity             android:name="com.example.testflashfile.readtext"             android:screenorientation="portrait" >         </activity>         <activity             android:name="com.example.testflashfile.playanimationactivity"             android:screenorientation="portrait" >         </activity>     </application>  </manifest> 

the log cat :

03-13 11:01:47.792: d/androidruntime(630): shutting down vm 03-13 11:01:47.843: w/dalvikvm(630): threadid=1: thread exiting uncaught exception (group=0x40015560) 03-13 11:01:47.972: e/androidruntime(630): fatal exception: main 03-13 11:01:47.972: e/androidruntime(630): java.lang.runtimeexception: unable instantiate activity componentinfo{com.example.testflashfile/com.example.testflashfile.mainactivity}: java.lang.nullpointerexception 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1569) 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.activitythread.access$1500(activitythread.java:117) 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.activitythread$h.handlemessage(activitythread.java:931) 03-13 11:01:47.972: e/androidruntime(630):  @ android.os.handler.dispatchmessage(handler.java:99) 03-13 11:01:47.972: e/androidruntime(630):  @ android.os.looper.loop(looper.java:123) 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.activitythread.main(activitythread.java:3683) 03-13 11:01:47.972: e/androidruntime(630):  @ java.lang.reflect.method.invokenative(native method) 03-13 11:01:47.972: e/androidruntime(630):  @ java.lang.reflect.method.invoke(method.java:507) 03-13 11:01:47.972: e/androidruntime(630):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 03-13 11:01:47.972: e/androidruntime(630):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 03-13 11:01:47.972: e/androidruntime(630):  @ dalvik.system.nativestart.main(native method) 03-13 11:01:47.972: e/androidruntime(630): caused by: java.lang.nullpointerexception 03-13 11:01:47.972: e/androidruntime(630):  @ android.content.contextwrapper.getresources(contextwrapper.java:80) 03-13 11:01:47.972: e/androidruntime(630):  @ com.example.testflashfile.readtext.readtxt(readtext.java:24) 03-13 11:01:47.972: e/androidruntime(630):  @ com.example.testflashfile.readtext.<init>(readtext.java:14) 03-13 11:01:47.972: e/androidruntime(630):  @ com.example.testflashfile.mainactivity.<init>(mainactivity.java:26) 03-13 11:01:47.972: e/androidruntime(630):  @ java.lang.class.newinstanceimpl(native method) 03-13 11:01:47.972: e/androidruntime(630):  @ java.lang.class.newinstance(class.java:1409) 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.instrumentation.newactivity(instrumentation.java:1021) 03-13 11:01:47.972: e/androidruntime(630):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1561) 03-13 11:01:47.972: e/androidruntime(630):  ... 11 more 03-13 11:01:52.054: i/process(630): sending signal. pid: 630 sig: 9 

things have tried: 1. class readtext mentioned in manifest. 2. checked similar threads on stack overflow in related questions.

please note: problem in line number 41:

hellotxt.settext(readtext.readtxt()); 

any help/suggestions/pointers write question appreciated.

answer: (thanks @ρяσѕρєя k )

the readtext=new readtext(this); should inside oncreate method of activity.

that solved problem. still know why defining inside oncreate essential.

thanks.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -