android


FATAL EXCEPTION- Unfortunately App has stopped working


My App is crashing in emulator. i looked at logCat and found FATAL EXCEPTION is there but i dont know how to solve this. i read similar Question But there solution does not solve my issue.Please help me. i am not getting what is wrong in my code.
LogCat
09-12 16:25:41.390: E/AndroidRuntime(1270): FATAL EXCEPTION: main
09-12 16:25:41.390: E/AndroidRuntime(1270): Process: com.example.hareemaudio, PID: 1270
09-12 16:25:41.390: E/AndroidRuntime(1270): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hareemaudio/com.example.hareemaudio.MainActivity}: java.lang.NullPointerException
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.ActivityThread.access$700(ActivityThread.java:135)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.os.Handler.dispatchMessage(Handler.java:102)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.os.Looper.loop(Looper.java:137)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.ActivityThread.main(ActivityThread.java:4998)
09-12 16:25:41.390: E/AndroidRuntime(1270): at java.lang.reflect.Method.invokeNative(Native Method)
09-12 16:25:41.390: E/AndroidRuntime(1270): at java.lang.reflect.Method.invoke(Method.java:515)
09-12 16:25:41.390: E/AndroidRuntime(1270): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
09-12 16:25:41.390: E/AndroidRuntime(1270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
09-12 16:25:41.390: E/AndroidRuntime(1270): at dalvik.system.NativeStart.main(Native Method)
09-12 16:25:41.390: E/AndroidRuntime(1270): Caused by: java.lang.NullPointerException
09-12 16:25:41.390: E/AndroidRuntime(1270): at com.example.hareemaudio.MainActivity.getInit(MainActivity.java:42)
09-12 16:25:41.390: E/AndroidRuntime(1270): at com.example.hareemaudio.MainActivity.onCreate(MainActivity.java:30)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.Activity.performCreate(Activity.java:5243)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-12 16:25:41.390: E/AndroidRuntime(1270): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
09-12 16:25:41.390: E/AndroidRuntime(1270): ... 11 more
MainActivity
package com.example.hareemaudio;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
//import android.widget.Button;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
SeekBar seek_bar;
ImageButton play_button, pause_button;
MediaPlayer player;
TextView text_shown;
Handler seekHandler = new Handler();
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//btnPlay.setClickable(true);
//btnPlay.setEnabled(true);
getInit();
seekUpdation();
}
public void getInit() {
seek_bar = (SeekBar) findViewById(R.id.seek_bar);
play_button = (ImageButton) findViewById(R.id.play_button);
pause_button = (ImageButton) findViewById(R.id.pause_button);
text_shown = (TextView) findViewById(R.id.text_shown);
play_button.setOnClickListener(this);
pause_button.setOnClickListener(this);
player = MediaPlayer.create(this, R.raw.fatiha); //ye wo Audio file hai jo chalarae
seek_bar.setMax(player.getDuration());
}
Runnable run = new Runnable() {
#Override
public void run() {
seekUpdation();
}
};
public void seekUpdation() {
seek_bar.setProgress(player.getCurrentPosition());
seekHandler.postDelayed(run, 1000);
}
/** yaha pe abi play/pause button k enable disable ka function lagaugi */
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.play_button:
/*buttonPlay.setEnabled(false);
buttonPause.setEnabled(true);/*
//or
/*View button = findViewById(R.id.btnPlay);
button.setVisibility(View.GONE);
* */
//text_shown.setText("Playing...");
player.start(); // Start playing Audio
break;
case R.id.pause_button:
player.pause(); //Pause Audio
//text_shown.setText("Paused...");
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- Player Header -->
<LinearLayout
android:id="#+id/player_header_bg"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_alignParentTop="true"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<!-- Audio Title -->
<TextView
android:id="#+id/audioTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="1"
android:textColor="#04b3d2"
android:textSize="16dp"
android:textStyle="bold" />
<!-- Playlist button -->
<ImageButton
android:id="#+id/btnPlaylist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:src="#drawable/btn_playlist" />
</LinearLayout>
<!-- Sabak Image -->
<LinearLayout
android:id="#+id/AudioThumbnail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="50dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_weight="1.04"
android:src="#drawable/fatiha" />
</LinearLayout>
<!-- Player Footer -->
<LinearLayout
android:id="#+id/player_footer_bg"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:gravity="center" >
<!-- Player Buttons -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<!-- Previous Button -->
<!-- Backward Button -->
<ImageButton
android:id="#+id/btnBackward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/btn_backward" />
<!-- Play Button -->
<ImageButton
android:id="#+id/pause_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:clickable="false"
android:src="#drawable/btn_pause" />
<ImageButton
android:id="#+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_toLeftOf="#+id/btnBackward"
android:layout_toRightOf="#+id/btnForward"
android:src="#drawable/btn_play"
/>
<!-- Forward Button -->
<ImageButton
android:id="#+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/btn_forward" />
<!-- Next Button -->
</LinearLayout>
</LinearLayout>
<!-- SABAK Progress Bar/Seek bar -->
<!-- Timer Display -->
<!-- Repeat / Shuffle buttons -->
<!-- Repeat / Shuffle buttons -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/player_footer_bg"
android:gravity="center"
android:orientation="vertical" >
<!-- Link to recordsabak Screen -->
<SeekBar
android:id="#+id/audioProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="10dp"
android:progressDrawable="#drawable/seekbar_progress"
android:thumb="#drawable/seek_handler" />
</LinearLayout>
<LinearLayout
android:id="#+id/timerDisplay"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/AudioThumbnail" >
</LinearLayout>
<ImageButton
android:id="#+id/imageButton10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_marginRight="33dp"
android:layout_toLeftOf="#+id/imageButton2"
android:background="#null"
android:src="#drawable/mic5" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_alignParentRight="true"
android:layout_marginRight="104dp"
android:background="#null"
android:src="#drawable/btn_shuffle" />
</RelativeLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hareemaudio"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.hareemaudio.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>
</manifest>
One thing that I can see is that you've used R.id.seek_bar in the getInit()java file. However in the xml file there is no android:id by this name. That might be returning null. Try changing it to R.id.audioProgressBar
In your xml you have audioProgressBar, in your java code you have seek_bar, is seek_bar in some other activity?
Change:
seek_bar = (SeekBar) findViewById(R.id.seek_bar);
to
seek_bar = (SeekBar) findViewById(R.id.audioProgressBar);

Related Links

Scanning QR or barcodes on iPhone or Android in with just HTML 5
Item gets moved on ActionBar on Android 4.1.1
How to retrieve Data from curser
Synchronization between two ListViews scroll lagging
Can WindowTester be integrated with some other tool to make it work with Android?
Sencha Touch can not open camera
fragment to fragment trasaction is slow
ImageView layout_height on different screens - Android
Why the Android Studio need to download Gradle?
What does AccessibilityManager.interrupt() exactly do?
Intent doesn't redirect to an other activity
Android HTTPClient sometimes slow connecting?
ListViews are blinking with different datasets
Find text length minus the escape characters
How to make checkboxes work in a live wallpaper Android app?
The headers is too long in WebView

Categories

HOME
assembly
polymer
ng-idle
angular2-material
static
toolbox
apache-spark-mllib
package
devise
grafana
nested-if
interpolation
data-visualization
mvc5
qpython
okhttp
project
reactive-programming
siddhi
activecollab
openbugs
alpacajs
imessage
microsoft-ocr
dynamically-generated
strongname
game-theory
maze
android-maps
ms-access-2003
linked-data
datastax-enterprise-graph
bringtofront
cppreference
magento-1.8
mockjax
kodi
angularjs-material
spring-security4
modalviewcontroller
batching
video-capture
dm-script
modernizr
filesystemwatcher
sim-card
css-position
ogc
levenshtein-distance
parser-generator
softmax
contract
android-exoplayer
apache-directory
vaadin-elements
mesosphere
datamaps
mongotemplate
stdmap
boo
ampps
android-instrumentation
testrail
cudd
omxplayer
webjars
pacemaker
uicolor
android-dateutils
appscale
nss
tracker-enabled-dbcontext
kiosk
grass
atan2
fiware-monitoring
vacuum
airbrake
keyup
uvc
entity-framework-4.3
public-html
execve
addressing-mode
post-commit-hook
cbind
ora-00904
live555
memset
vbe
accesscontrolexception
spring-3
ie8-compatibility-mode
code-duplication
mvc-editor-templates
jquery-1.9
wp7test
superscrollorama
pstack
qtconcurrent
subgraph
extconf.rb
multiplexing
cgimage
mbeans
web-garden
isapi-extension
web-application-project
complex-event-processing
dojo-dnd
product-management
information-management
appliance
commercial-application

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App