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

Android RecyclerView move item to end of View
Android. Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
ionic/cordova home screen widget (Android)
“Error:Invalid keystore format” when I'm trying to build a sample
What changes we need to do in the android application to make it multiwindow application?
In RecycleView onScrolling images are flickering
Android: How to include phone number on Intent.createChooser activity for native SMS option
Resize image from sd card and save
start NFC exchanges on android python kivy platform
Error when deleting an item from listview in android
Tag tag = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_TAG);
How to get records based on one column in sqlite3 in android
Chrome Custom Tabs
Is it possible to add a ScrollView to a AppBarLayout
How to detect KEYCODE_DEL on soft keyboard?
Text Editor keyboard overlaps with the recyclerview list

Categories

HOME
uml
httparty
cheerio
polymer
gpu
spring-data-redis
rendering
ms-access-2016
pdfbox
aws-cli
visual-studio-emulator
pyqt4
settings
tvos
modal-dialog
performancepoint
arangodb
enthought
emoji
intershop
feathersjs
asciidoctor-pdf
blade
dynamically-generated
jackson-modules
linked-data
firebase-analytics
user-defined-functions
jaws
google-earth
alm
userdefaults
eviews
hibernate-validator
catch-unit-test
clickjacking
twos-complement
dynamic-jasper
mnist
protege4
apic
git-rewrite-history
amazon-ses
recurrent-neural-network
gdata
metawidget
signals-slots
odoo-website
apriori
android-checkbox
pom.xml
cnc
oracleclient
skin
cd-burning
latin
flex4.6
mongodb-php
respondcms
cfchart
aurora
dbamp
kiosk
ellucian-scribe
fink
halcon
np-spring
qbxml
spring-retry
directdraw
sapi
decimalformat
ess
flock
morton-number
iced-coffeescript
haskell-warp
branch-and-bound
airbrake
mass-assignment
rapidsvn
sonarqube-5.0
contrast
wcm
codeplex
xml-dsig
grails-plugin-rabbitmq
square-bracket
syndicationfeed
printdialog
kogrid
cffile
diem
bjyauthorize
qtconcurrent
zope.interface
apache-whirr
kqueue
floating-point-exceptions
apache-commons-dbutils
screen-size
listactivity
cgbitmapcontextcreate
easyb
office-2007
binomial-heap
unmanagedresources

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