在通知栏上添加自定义搜索栏时出现nullpointer异常

时间:2014-05-01 06:43:23

标签: android

我开发了一个音频媒体播放器应用程序但是当我在通知栏上创建一部分内容时会出现问题,例如您可以播放暂停一首歌曲,接下来,通知栏中的上一首歌曲,还可以添加通知栏但添加时通知栏中的自定义搜索栏发生了一些错误以下是我的代码和错误是... 在通知栏上显示的Xml代码..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <!-- Progress Bar/Seek bar -->
    <SeekBar
            android:id="@+id/songProgressBarn"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_marginRight="20dp" 
             android:layout_marginLeft="20dp"
             android:layout_marginBottom="20dp"
             android:layout_above="@id/player_footer_bg"
             android:thumb="@drawable/seek_handler"
             android:progressDrawable="@drawable/seekbar_progress"
             android:paddingLeft="6dp"
             android:paddingRight="6dp"/>

     <LinearLayout 
        android:id="@+id/player_footer_bg"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:background="@layout/player_footer_db"
        android:gravity="center">

        <!-- Player Buttons -->
        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:background="@layout/rounded_corner"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">
            <!-- Previous Button -->
            <ImageButton
                android:id="@+id/btnPrevious" 
                android:src="@drawable/btn_previous"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
             <!-- Play Button -->
            <ImageButton 
                android:id="@+id/btnPlay"
                android:src="@drawable/btn_play"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
            <!-- Next Button -->
            <ImageButton 
                android:id="@+id/btnNext"
                android:src="@drawable/btn_next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@null"/>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

这是我发送给广播接收者的主要活动代码

NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(this);

String ns=Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager=(NotificationManager)getSystemService(ns);
@SuppressWarnings("deprecation")
Notification notification=new Notification(R.drawable.bg,"Time",System.currentTimeMillis());
notificationView=new RemoteViews(getPackageName(),R.layout.main);
Intent notificationIntent=new Intent(this,PlayerAudioActivity.class);
PendingIntent pendingNotificationIntent=PendingIntent.getActivity(this,0,notificationIntent, 0);
notification.contentView.setProgressBar(R.id.songProgressBarn, 100, 0, false);   
notification.contentView=notificationView;
notification.flags|=Notification.FLAG_NO_CLEAR;

//supposed button call intent

    Log.d("humayoon tum kam saee say karoo na"+R.id.btnPlay, "wawoooo");

Intent switchIntent=new Intent(this,MyReceiver.class);
switchIntent.setAction("btnplay");
 Toast.makeText(getBaseContext(), ""+switchIntent, Toast.LENGTH_LONG).show();
PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 0, switchIntent, 0);
notificationView.setOnClickPendingIntent(R.id.btnPlay, pendingIntent);

Intent switchIntent2=new Intent(this,MyReceiver.class);
switchIntent2.setAction("btnnext");
PendingIntent pendingIntent2=PendingIntent.getBroadcast(this, 0, switchIntent2, 0);
notificationView.setOnClickPendingIntent(R.id.btnNext, pendingIntent2);

Intent switchIntent3=new Intent(this,MyReceiver.class);
switchIntent3.setAction("btnprevious");
PendingIntent pendingIntent3=PendingIntent.getBroadcast(this, 0, switchIntent3, 0);
notificationView.setOnClickPendingIntent(R.id.btnPrevious, pendingIntent3);

我的广播接收代码是

package com.Audio.audioplayer;

import java.io.IOException;

import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat.Builder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver implements  Listenercalling{
    public static final String CUSTOM_INTENT = "jason.wei.custom.intent.action.TEST";
    public static final String PLAY_ACTION = "Play";
    public static final String PREVIOUS_ACTION = "Previous";
    public static final String NEXT_ACTION = "NEXT";
    private static Listenercalling ls=new PlayerAudioActivity();
    private static final String TAG = "waaaawoooooooooOOOOOOjnjkhdfku";
    public void onReceive(Context context, Intent intent) {
        //btnplay=(ImageButton)btnplay;
         final String action=intent.getAction();
         //Log.v("Play Call"+action,"Pressed YES");
//       if(PLAY_ACTION.equals(action)) {
//              Log.v("Play Call","Pressed YES");
//          } else if(PREVIOUS_ACTION.equals(action)) {
//              Log.v("Previous Call","Pressed NO");
//          } else if(NEXT_ACTION.equals(action)) {
//              Log.v("Next Call","Pressed MAYBE");
//          }
         if(action.equals("btnplay"))
         {
            ls.getplay();
             Log.d("play clicked,,,,,,,,,,,,,,,,,,", ""+action);

         }
         if(action.equals("btnnext"))
         {
             ls.getnext();
             Log.d("next clicked,,,,,,,,,,,,,,,,,,", ""+action);

         }
         if(action.equals("btnprevious"))
         {
             ls.getprevious();
             Log.d("previous clicked,,,,,,,,,,,,,,,,,,", ""+action);

         }
        // if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)){

//           Bundle extras=intent.getExtras();
//           String ieString=extras.getString("Locale");
    //       try{
//               final int Appwidgid=extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
//               if(Appwidgid!=AppWidgetManager.INVALID_APPWIDGET_ID)
//               {
//                   this.onDeleted(context, new int[] { Appwidgid });
//               }
//            else {
//                onReceive(context, intent);
//                 }
//              context.startService(new Intent(context,PlayerAudioActivity.class));
//              Log.i(TAG,"Starting Service ConnectivityListener");
//          }catch(Exception e){
//              Log.e(TAG,e.toString());
//          }
//       }
    }



    public void setMyInterface(PlayerAudioActivity pl)
    {
        Log.d("wawwwooo"+pl, "lfkero");

        ls=pl;
    }
    @Override
    public void getplay() {

        //Log.d("wawwwooo", "getplayreciever calling");
        PlayerAudioActivity pl=new PlayerAudioActivity();   
        ls.getplay(); 

    }

    public void getnext()
    {
         PlayerAudioActivity pl=new PlayerAudioActivity();  
            ls.getnext(); 
    }
    public void getprevious()
    {
         PlayerAudioActivity pl=new PlayerAudioActivity();  
            ls.getprevious(); 
    }
}

errorz正在关注..

05-01 11:41:19.627: W/dalvikvm(4942): threadid=1: thread exiting with uncaught exception (group=0x41c099a8)
05-01 11:41:19.630: E/AndroidRuntime(4942): FATAL EXCEPTION: main
05-01 11:41:19.630: E/AndroidRuntime(4942): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Audio.audioplayer/com.Audio.audioplayer.PlayerAudioActivity}: java.lang.NullPointerException
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.ActivityThread.access$600(ActivityThread.java:156)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.os.Looper.loop(Looper.java:153)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.ActivityThread.main(ActivityThread.java:5299)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at java.lang.reflect.Method.invokeNative(Native Method)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at java.lang.reflect.Method.invoke(Method.java:511)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at dalvik.system.NativeStart.main(Native Method)
05-01 11:41:19.630: E/AndroidRuntime(4942): Caused by: java.lang.NullPointerException
05-01 11:41:19.630: E/AndroidRuntime(4942):     at com.Audio.audioplayer.SongsManager.getPlayList(SongsManager.java:20)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at com.Audio.audioplayer.PlayerAudioActivity.onCreate(PlayerAudioActivity.java:101)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.Activity.performCreate(Activity.java:5122)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
05-01 11:41:19.630: E/AndroidRuntime(4942):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
05-01 11:41:19.630: E/AndroidRuntime(4942):     ... 11 more

0 个答案:

没有答案