• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Intent from Runnable Error

I am new to android , and I am trying to implement a timer that every second calls a "cameraActivity" class that takes a picture and stores it into the sd card.
In the Runnable I am creating a new intent .
I get the following error from the log:
: ERROR/AndroidRuntime(18897): at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(18897): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(18897): at android.content.ComponentName.<init>(ComponentName.java:75)
ERROR/AndroidRuntime(18897): at android.content.Intent.<init>(Intent.java:2754)
ERROR/AndroidRuntime(18897): at timer.erez.temp.TimertempActivity$1.<init>(TimertempActivity.java:40)
ERROR/AndroidRuntime(18897): at timer.erez.temp.TimertempActivity.<init>(TimertempActivity.java:38)
ERROR/AndroidRuntime(18897): at java.lang.Class.newInstanceImpl(Native Method)
ERROR/AndroidRuntime(18897): at java.lang.Class.newInstance(Class.java:1429)

The following code is:
public class TimertempActivity extends Activity {
private Timer MyTimer;
private Preview preview;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MyTimer = new Timer();
MyTimer.schedule(new TimerTask(){
@Override
public void run(){
TimerMethod();
}
},0,1000);
}
private void TimerMethod()
{
this.runOnUiThread(Timer_Tick);
}
private Runnable Timer_Tick = new Runnable() {

Intent intent = new Intent(null,CameraActivity.class);
int index=0;

@Override
public void run() {
// TODO Auto-generated method stub
startActivity(intent);
//index=index+1;

}
};

}
 
Add your cameraActivity to your AndroidManifest.xml

I did.
still app crash
My Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="timer.erez.temp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TimertempActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CameraActivity" android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".CameraActivity" android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
 
You should only have one Activity with:

<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />


Also looks like you have CameraActivity twice
 
Back
Top Bottom