Question

my app force closes I do not know why. All it should do is vibrating when it is in the foreground and stop if it is not but when I start it on my phone it force closes. I added lines about vibrator usage into the manifest by hand. Maybe this is the problem. I have to anything else with it to be valid for the app?

My manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kevinboonemidi"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="android.permission.VIBRATE" ></permission>
<uses-permission android:name="android.permission.VIBRATE"/>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.haptic.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

My code:

package com.example.haptic_sof;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.example.kevinboonemidi.R;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.GestureDetector; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.View.OnTouchListener;

public class MainActivity extends Activity 
{

    protected Vibrator v = null;


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

        long pwmCycles[];
        pwmCycles = new long[4];

        v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        long[] pattern = { 0, 200, 10 };
        v.vibrate(pattern, 0);  

    }

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

    protected void onPause(){
        super.onPause();
        v.cancel();
    }

    protected void onStop()
    {
        super.onStop();
        v.cancel();
    }

}
Was it helpful?

Solution

Your packages are a mess.

You define com.example.kevinboonemidi as your package in the manifest, declare your Activity to be in com.example.haptic and actually put your Activity in com.example.haptic_sof.

Change android:name="com.example.haptic.MainActivity" to android:name="com.example.haptic_sof.MainActivity" and your app should run, though you may need to end up using one package entirely at least to start with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top