public void onClick(View v) {
Toast.makeText(MainActivity.this,"You taped!",Toast.LENGTH_SHORT).show();
try {
startActivity(new Intent(MainActivity.this, FuelChoiceActivity.class));
}catch (Exception e){
System.out.println(e);
}
}
Here is my code. I've added the new activity to my manifest.xml. The try/catch block is not returning any exeption. When i press the button the toast is executed and displayed but the page is not changing. This onClickListener is inside an adapter method 'getView'so it can be obtained by any button generated from the adapter. I tried putting other events and they work! The only thing that doesn't is going to the new Activity.
here is my log when i debug and click on a button:
D/AbsListView: reportScrollStateChange: newState = 0, mLastScrollState = 0, mOnScrollListener = null, mScrollY = 0, mTouchMode = -1, mFirstPosition = 0
V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
D/ActivityThread: ACT-AM_ON_PAUSE_CALLED ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
D/ActivityThread: ACT-PAUSE_ACTIVITY handled : 1 / android.os.BinderProxy#32487069
D/AbsListView: onWindowFocusChanged: hasWindowFocus=false, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview}
D/OpenGLRenderer: Flushing caches (mode 0)
D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
V/ActivityThread: Handling launch of ActivityRecord{1ff7b407 token=android.os.BinderProxy#19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}
V/ActivityThread: ActivityRecord{1ff7b407 token=android.os.BinderProxy#19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}: app=android.app.Application#a0dbe1c, appName=com.example.stamatis.redhotpepper, pkg=com.example.stamatis.redhotpepper, comp={com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}, dir=/data/app/com.example.stamatis.redhotpepper-1/base.apk
D/ActivityThread: ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{1ff7b407 token=android.os.BinderProxy#19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}
D/ActivityThread: ACT-PAUSE_ACTIVITY_FINISHING handled : 0 / android.os.BinderProxy#19bbf934
V/ActivityThread: Performing resume of ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
D/ActivityThread: ACT-AM_ON_RESUME_CALLED ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
V/ActivityThread: Resume ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} started activity: false, hideForNow: false, finished: false
V/ActivityThread: Resuming ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} with isForward=true
V/PhoneWindow: DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{dfe4562 com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{1d6eaa25 V.E..... R.....I. 0,0-480,782}
V/ActivityThread: Scheduling idle handler for ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}}
D/ActivityThread: ACT-RESUME_ACTIVITY handled : 1 / android.os.BinderProxy#32487069
D/AbsListView: onWindowFocusChanged: hasWindowFocus=true, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview}
V/InputMethodManager: onWindowFocus: com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} softInputMode=272 first=false flags=#1810100
D/ActivityThread: ACT-DESTROY_ACTIVITY handled : 1 / android.os.BinderProxy#19bbf934
D/OpenGLRenderer: Flushing caches (mode 0)
D/OpenGLRenderer: Flushing caches (mode 0)
D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02)
Thanks for reading and your time. I would appreciate thoughts.
My main activity extends Activity
public class MainActivity extends Activity
In this activity i was trying to to move to another that it was extending AppCombatActivity class.
public class FuelChoiceActivity extends AppCombatActivity
so the syntax and all is right. So i changed the FuelChoiceActivity(the activity i desired to move at) extend to :
public class FuelChoiceActivity extends Activity
Seems like you cannot move to another activity if they both dont extend the same class.
Related
I'm new to Android and Java development and am looking for some guidance in setting up a simple soundboard app. What I am trying to do and am having issues in getting it working effectively is handling events for multiple mediaplayers.
For example I am creating a soundboard whereby when I click a button I want all other sounds to be stopped and released from memory and the button I have just pressed to play its assigned sound. I realise that repeating code blocks is not a good programming approach, but I have tried this with arrays and switch statements too with little effect. Any guidance on how to effectively release sounds from memory when using multiple MediaPlayers would be very useful to me. I have included my code below for 4 buttons (I have over 30 on this app)
public class MainActivity extends AppCompatActivity {
private MediaPlayer Meow1,Meow2,Meow3,Meow4;
private Button meowButton1,meowButton2,meowButton3,meowButton4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Meow1 = new MediaPlayer();
Meow1 = MediaPlayer.create(getApplicationContext(), R.raw.meow1);
// final Boolean Meow1Pause = !Meow1.isPlaying() && Meow1.getCurrentPosition() >1;
meowButton1 = (Button) findViewById(R.id.Meow1);
meowButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow1.isPlaying())
{ pauseMusic1();
} else {
Meow1.start();
}}
});
Meow1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer Meow1) {
Meow1.stop();
Meow1.reset();
Meow1.release();
}
});
Meow2 = new MediaPlayer();
Meow2 = MediaPlayer.create(getApplicationContext(), R.raw.meow2);
meowButton2 = (Button) findViewById(R.id.Meow2);
meowButton2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow2.isPlaying() ){
pauseMusic();
} else {
Meow2.start();
}}
});
Meow2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer Meow1) {
Meow2.stop();
Meow2.reset();
Meow2.release();
}
});
Meow3 = new MediaPlayer();
Meow3 = MediaPlayer.create(getApplicationContext(), R.raw.meow3);
meowButton3 = (Button) findViewById(R.id.Meow3);
meowButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow3.isPlaying())
{ pauseMusic();
} else {
Meow3.start();
}}
});
Meow3.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer Meow1) {
Meow3.stop();
Meow3.reset();
Meow3.release();
}
});
Meow4 = new MediaPlayer();
Meow4 = MediaPlayer.create(getApplicationContext(), R.raw.meow4);
meowButton4 = (Button) findViewById(R.id.Meow4);
meowButton4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Meow4.isPlaying())
{ pauseMusic();
} else {
Meow4.start();
}}
});
}
public void pauseMusic() {
if(Meow1 != null && Meow1.isPlaying()) Meow1.pause();
if(Meow2 != null && Meow2.isPlaying()) Meow2.pause();
if(Meow3 != null && Meow3.isPlaying()) Meow3.pause();
if(Meow4 != null && Meow4.isPlaying()) Meow4.pause();
}
}
Run Compiler:
A: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SplashScreen, firebase_previous_id(_pi)=-6549553702477848745, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-6549553702477848744}]
I/zygote: Do partial code cache collection, code=124KB, data=67KB
I/zygote: After code cache collection, code=124KB, data=67KB
I/zygote: Increasing code cache capacity to 512KB
V/FA: Activity resumed, time: 6376787
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
I/chatty: uid=10085(u0_a85) RenderThread identical 2 lines
D/EGL_emulation: eglMakeCurrent: 0x980fde60: ver 3 0 (tinfo 0xa3c3c290)
V/FA: Inactivity, disconnecting from the service
V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer: resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
cleanDrmObj: mDrmObj=null mDrmSessionId=null
D/TAG1: Button 2 pressed
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: g.convery.cat_sounds, PID: 12276
java.lang.IllegalStateException
at android.media.MediaPlayer.isPlaying(Native Method)
at g.convery.cat_sounds.MainActivity$1.onClick(MainActivity.java:97)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
W/MediaPlayer-JNI: MediaPlayer finalized without being released
W/MediaPlayer-JNI: MediaPlayer finalized without being released
Application terminated.
LOGCAT:
05-31 09:21:30.099 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
05-31 09:21:30.211 12276-12288/g.convery.cat_sounds I/chatty: uid=10085(u0_a85) FinalizerDaemon identical 33 lines
05-31 09:21:30.212 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
05-31 09:21:30.283 12276-12284/g.convery.cat_sounds I/zygote: Do partial code cache collection, code=124KB, data=67KB
05-31 09:21:30.286 12276-12284/g.convery.cat_sounds I/zygote: After code cache collection, code=124KB, data=67KB
05-31 09:21:30.287 12276-12284/g.convery.cat_sounds I/zygote: Increasing code cache capacity to 512KB
05-31 09:21:31.159 12276-12307/g.convery.cat_sounds I/chatty: uid=10085(u0_a85) RenderThread identical 2 lines
05-31 09:24:41.746 12276-12276/g.convery.cat_sounds E/AndroidRuntime: FATAL EXCEPTION: main
Process: g.convery.cat_sounds, PID: 12276
java.lang.IllegalStateException
at android.media.MediaPlayer.isPlaying(Native Method)
at g.convery.cat_sounds.MainActivity$1.onClick(MainActivity.java:97)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
05-31 09:24:47.955 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
05-31 09:24:47.956 12276-12288/g.convery.cat_sounds W/MediaPlayer-JNI: MediaPlayer finalized without being released
You are using the media player after releasing it. Remove these lines from your onCompletionListener and add them to onDestroy of your activity instead
Meow1.release();
Meow2.release();
Meow3.release();
Meow4.release();
Also calling create automatically creates a new instance, you can remove these lines as well
Meow1 = new MediaPlayer();
Meow2 = new MediaPlayer();
Meow3 = new MediaPlayer();
Meow4 = new MediaPlayer();
A better approach would be to use a single media player and just change the datesource when ever user wants to play different source, but this method will take some time before it plays the audio as it will prepare the audio everytime, this would be negligible unless your audio size is quite huge
Look how you're controlling your media now:
if (Meow4.isPlaying()) {
pauseMusic();
} else {
Meow4.start();
}
The first time you call Meow4.isPlaying() you will receive IllegalStateException because your player is not initialized.
Look how your MediaPlayer state is defined and call appropriate function
The second point, when you encounter a duplicate block, you should think of a function.
Meow3 = new MediaPlayer();
Meow3 = MediaPlayer.create(getApplicationContext(), R.raw.meow3);
meowButton3 = (Button) findViewById(R.id.Meow3);
meowButton3.setOnClickListener(new View.OnClickListener() {
});
meowButton3.setOnCompletionListener...
in a function: registerPlayer(Context context, int resourceId, Button controlButton)
Or with higher level of abstraction, create a subclass of `MediaPlayer` and wrap these logic inside it
Definitely you don't want to Meow1.pause() over and over. Instead, store your MeoX in a list then loop over it:
List<MediaPlayer> players = new ArrayList<>();
players.add(Meow1);
....
public void pauseMusic() {
players.stream().filter(p -> p != null && p.isPlaying()).forEach(p -p.pause());
}
Just wanted to see if anyone could help me out or point me in the right direction. I'm learning how to make a simple music player where the user clicks on list view items and it streams the mp3. There's a play button up top and next and previous song buttons (haven't added seek functionality yet). However it keeps crashing when I select new song. Here's my activity code:
public class AudioActivity extends AppCompatActivity {
ListView listView;
ArrayList<String> musicList;
ArrayAdapter adapter;
MediaPlayer player;
ImageButton prev;
ImageButton play;
ImageButton next;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
prev = (ImageButton) findViewById(R.id.previous);
play = (ImageButton) findViewById(R.id.play);
next = (ImageButton) findViewById(R.id.next);
listView = findViewById(R.id.musiclist);
musicList = new ArrayList<>();
musicList.add("song");
musicList.add("song1");
musicList.add("song2");
musicList.add("song3");
musicList.add("song4");
adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, musicList);
listView.setAdapter(adapter);
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
String url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3";
try {
player.stop();
//player.release();
player.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
try {
player.prepare();
} catch (IOException e) {
e.printStackTrace();
}
break;
case 1:
url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-8.mp3";
try {
player.stop();
//player.release();
player.setDataSource(url);
} catch (IOException e) {
e.printStackTrace();
}
try {
player.prepare();
} catch (IOException e) {
e.printStackTrace();
}
break;
default:
break;
}
player.start();
}
});
}
public void onPlayBtnClicked(){
if(!player.isPlaying())
{
player.start();
}else
{
player.pause();
}
}
}
04/05 00:08:09: Launching app
$ adb shell am start -n "com.example.brads.group08/com.example.brads.group08.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08
Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08
Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08
Connecting to com.example.brads.group08
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.brads.group08 is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/zygote: Debugger is active
Connected to the target VM, address: 'localhost:8600', transport: 'socket'
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/chatty: uid=10091(com.example.brads.group08) identical 4 lines
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1448)
I/InstantRun: starting instant run server: is main process
D/OpenGLRenderer: HWUI GL Pipeline
[ 04-05 04:08:16.176 10444:10464 D/ ]
HostConnection::get() New Host Connection established 0xa5a26b40, tid 10464
I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/EGL_emulation: eglCreateContext: 0xa5a70f60: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
I/zygote: Do partial code cache collection, code=21KB, data=30KB
I/zygote: After code cache collection, code=21KB, data=30KB
I/zygote: Increasing code cache capacity to 128KB
I/zygote: Do partial code cache collection, code=31KB, data=56KB
I/zygote: After code cache collection, code=31KB, data=56KB
I/zygote: Increasing code cache capacity to 256KB
I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/zygote: Do full code cache collection, code=116KB, data=72KB
I/zygote: After code cache collection, code=90KB, data=45KB
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
W/MediaPlayer: Use of stream types is deprecated for operations other than volume control
W/MediaPlayer: See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680)
E/MediaPlayerNative: stop called in state 1, mPlayer(0x0)
E/MediaPlayerNative: error (-38, 0)
V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService#89d8a5e): Cookies: null
V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager#a4007a4
V/MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService#89d8a5e): cookieHandler: java.net.CookieManager#a4007a4 Cookies: null
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/Choreographer: Skipped 163 frames! The application may be doing too much work on its main thread.
E/MediaPlayer: Error (-38,0)
I/zygote: Do partial code cache collection, code=123KB, data=81KB
I/zygote: After code cache collection, code=123KB, data=81KB
I/zygote: Increasing code cache capacity to 512KB
V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService#7615caf): Cookies: null
E/MediaPlayerNative: attachNewPlayer called in state 64
E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.IllegalStateException
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1172)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127)
at com.example.brads.group08.AudioActivity$1.onItemClick(AudioActivity.java:65)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127)
at android.widget.AbsListView.onTouchUp(AbsListView.java:4054)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3813)
at android.view.View.dispatchTouchEvent(View.java:11776)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:12015)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.brads.group08, PID: 10444
java.lang.IllegalStateException
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1172)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127)
at com.example.brads.group08.AudioActivity$1.onItemClick(AudioActivity.java:65)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127)
at android.widget.AbsListView.onTouchUp(AbsListView.java:4054)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3813)
at android.view.View.dispatchTouchEvent(View.java:11776)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:12015)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
I am establishing server-client communication between Android app and ESP8266 NodeMCU-1.0. The ESP is creating server on specified network and the mobile is connecting to same network.
For testing purpose I am sending "try123" string when the send button is pressed. And receiving appropriate response on the serial monitor of IDE (i.e. data is received on server). But the server response which is "Test_successful" string. I am sending this string to client using client.print. In app I am toasting the server response.
The problem is that if I am making the HTTP request using browser using the locally generated URL, then the response "Test_successful" is visible. But In app toast it's showing empty and while debugging it's showing error Unexpected line status.
ESP code (server side):
#include <ESP8266WiFi.h>
const char* ssid = "DARSHAN95";
const char* password = "12345678";
//const char* ssid = "TP-LINK_42C148";
//const char* password = "";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
//client.flush();
delay(100);
// Send the response to the client
client.print("Test_Sucessfull");
delay(200);
Serial.println("Client disonnected");
}
Android App code:
Please ignore the text input block on the and its code.
package com.example.access.test123;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class MainActivity extends AppCompatActivity {
EditText Message;
Button Send;
String data;
HttpURLConnection http;
String sendingMessage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Message = (EditText) findViewById(R.id.message);
Send = (Button) findViewById(R.id.send);
Send.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
HttpAsync task = new HttpAsync();
task.execute();
}
});
}
public void sendDataMethod() throws UnsupportedEncodingException{
sendingMessage = Message.getText().toString();
String data = "Error";
BufferedReader reader = null;
//Sending Data
try{
String ip = "http://192.168.43.76/?try123";
//String address = ip + sendingMessage;
//URL url = new URL(address);
URL url = new URL(ip);
URLConnection conn = url.openConnection();
http = (HttpURLConnection)conn;
http.setRequestMethod("POST"); // PUT is another valid option
http.setDoOutput(true);
http.setDoInput(true);
//Server Response
int i = http.getResponseCode();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
sb.append(line + "\n");
}
data = sb.toString();
}
catch(IOException e){;
Log.d("Error2", e.toString());
}
finally {
try{
if(reader != null) {
reader.close();
}
}
catch (IOException ex){
Log.d("Error3", ex.toString());
}
}
}
private class HttpAsync extends AsyncTask {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Object doInBackground(Object[] objects) {
try {
sendDataMethod();
}
catch (UnsupportedEncodingException e) {
Log.d("Error", e.toString());
}
return null;
}
#Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
Toast.makeText(MainActivity.this, data, Toast.LENGTH_SHORT).show();
}
}
}
Debugging results:
02/07 22:40:23: Launching app
$ adb install-multiple -r -t A:\New folder\Test123\app\build\intermediates\split-apk\debug\dep\dependencies.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_1.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_2.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_3.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_6.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_9.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_8.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_7.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_4.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_5.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_0.apk A:\New folder\Test123\app\build\outputs\apk\debug\app-debug.apk
Split APKs installed
$ adb shell am start -n "com.example.access.test123/com.example.access.test123.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Waiting for application to come online: com.example.access.test123.test | com.example.access.test123
Connecting to com.example.access.test123
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/art: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8601', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1436)
W/System: ClassLoader referenced unknown path: /data/app/com.example.access.test123-2/lib/arm64
I/art: Starting a blocking GC HeapTrim
I/InstantRun: starting instant run server: is main process
I/art: Starting a blocking GC Instrumentation
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView#3280086[]
D/WindowClient: Add to mViews: DecorView#3280086[MainActivity], this = android.view.WindowManagerGlobal#d5cc9ee
D/OpenGLRenderer: Dumper init 4 threads <0x7c6a19ee40>
D/OpenGLRenderer: <com.example.access.test123> is running.
D/OpenGLRenderer: CanvasContext() 0x7c6773f880
D/ViewRootImpl[MainActivity]: hardware acceleration is enabled, this = ViewRoot{500151c com.example.access.test123/com.example.access.test123.MainActivity,ident = 0}
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{500151c com.example.access.test123/com.example.access.test123.MainActivity,ident = 0}, this = DecorView#3280086[MainActivity]
D/OpenGLRenderer: CanvasContext() 0x7c6773f880 initialize window=0x7c73e55e00, title=com.example.access.test123/com.example.access.test123.MainActivity
D/Surface: Surface::allocateBuffers(this=0x7c73e55e00)
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/OpenGLRenderer: Created EGL context (0x7c6a19f600)
D/OpenGLRenderer: ProgramCache.init: enable enhancement 1
I/OpenGLRenderer: Get disable program binary service property (0)
I/OpenGLRenderer: Initializing program atlas...
I/ProgramBinary/Service: ProgramBinaryService client side disable debugging.
I/ProgramBinary/Service: ProgramBinaryService client side disable binary content debugging.
D/ProgramBinary/Service: BpProgramBinaryService.getReady
D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryData
I/OpenGLRenderer: Program binary detail: Binary length is 249276, program map length is 124.
I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 74, and path is /dev/ashmem.
I/OpenGLRenderer: No need to use file discriptor anymore, close fd(74).
D/OpenGLRenderer: Initializing program cache from 0x0, size = -1
D/MALI: eglCreateImageKHR:513: [Crop] 0 0 896 1344 img[896 1344]
D/Surface: Surface::connect(this=0x7c73e55e00,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
D/OpenGLRenderer: CacheTexture 3 upload: x, y, width height = 0, 0, 189, 441
D/OpenGLRenderer: ProgramCache.generateProgram: 0
D/OpenGLRenderer: ProgramCache.generateProgram: 34359738371
D/OpenGLRenderer: ProgramCache.generateProgram: 5242945
D/OpenGLRenderer: ProgramCache.generateProgram: 5242944
D/OpenGLRenderer: ProgramCache.generateProgram: 240518168576
D/OpenGLRenderer: ProgramCache.generateProgram: 68724719680
V/InputMethodManager: onWindowFocus: android.support.v7.widget.AppCompatEditText{8687c92 VFED..CL. .F....ID 228,66-851,212 #7f070042 app:id/message} softInputMode=288 first=true flags=#81810100
D/OpenGLRenderer: ProgramCache.generateProgram: 103084458052
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/System.out: [socket][0] connection /192.168.43.76:80;LocalPort=-1(0)
[ 02-07 22:40:39.251 29396:29665 D/ ]
[Posix_connect Debug]Process com.example.access.test123 :80
I/System.out: [socket][/192.168.43.1:49348] connected
I/System.out: [OkHttp] sendRequest>>
I/System.out: [OkHttp] sendRequest<<
D/Error2: java.net.ProtocolException: Unexpected status line: Test_Sucessfull
D/WindowClient: Add to mViews: android.widget.LinearLayout{3957537 V.E...... ......I. 0,0-0,0}, this = android.view.WindowManagerGlobal#d5cc9ee
D/OpenGLRenderer: CanvasContext() 0x7c56092d40
D/ViewRootImpl[Toast]: hardware acceleration is enabled, this = ViewRoot{f7a400d Toast,ident = 1}
D/Surface: Surface::allocateBuffers(this=0x7c58339e00)
D/OpenGLRenderer: CanvasContext() 0x7c56092d40 initialize window=0x7c58339e00, title=Toast
D/Surface: Surface::connect(this=0x7c58339e00,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
D/OpenGLRenderer: ProgramCache.generateProgram: 1
D/Surface: Surface::disconnect(this=0x7c58339e00,api=1)
D/Surface: Surface::disconnect(this=0x7c58339e00,api=1)
D/WindowClient: Remove from mViews: android.widget.LinearLayout{3957537 V.E...... ......ID 0,0-156,140}, this = android.view.WindowManagerGlobal#d5cc9ee
I/art: Do partial code cache collection, code=28KB, data=28KB
I/art: After code cache collection, code=27KB, data=28KB
I/art: Increasing code cache capacity to 128KB
Note: At D/Error2: java.net.ProtocolException: Unexpected status line: Test_Sucessfull
The string is received but with above error.
Results:
IDE monitor displaying data sent from client i.e. app
Finally Found the solution, the error was with the syntax of the response packet sent from ESP side
so just replaced
client.print("Test_Successfull");
with
client.print("HTTP/1.1 200 OK\r\nConnection: Closed\r\n\r\nTest_Successful");
When I run the below Java for Android code, I get a NullPointerException on the line that calls getSkuDetails in the doInBackground method in the GetItemList class. But when I step through in the debugger, all the parameters to getSkuDetails have values. pName is not an empty string and querySkus has two items in it. The exact error message I'm getting is "Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference." Does anyone know why?
package com.myknitcards;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.vending.billing.IInAppBillingService;
import android.app.Activity;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class AvailableCards extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_available_cards);
String packagename = this.getPackageName();
TextView priceView = (TextView)findViewById(R.id.availablePrice);
new GetItemList(packagename, priceView).execute();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.available_cards, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class GetItemList extends AsyncTask<Integer, Integer, Long> {
private String pName;
private TextView pView;
GetItemList(String packagename, TextView priceView){
pName = packagename;
pView = priceView;
}
IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
#Override
protected Long doInBackground(Integer... params) {
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("i001");
skuList.add("i002");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = null;
try {
skuDetails = mService.getSkuDetails(3, pName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object;
object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
String mFirstIntermediate;
String mSecondIntermediate;
if (sku.equals("i001")) mFirstIntermediate = price;
else if (sku.equals("i002")) mSecondIntermediate = price;
pView.setText(sku + ": " + price);
}
}
} catch (NullPointerException ne) {
Log.d("Synch Billing", "Error Null Pointer: " + ne.getMessage());
ne.printStackTrace();
}
catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error Remote: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException je) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error JSON: " + je.getMessage());
je.printStackTrace();
}
return null;
}
}
Here's my log:
01-25 19:02:18.888: D/AndroidRuntime(4802): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
01-25 19:02:18.894: D/AndroidRuntime(4802): CheckJNI is OFF
01-25 19:02:18.951: D/ICU(4802): No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
01-25 19:02:19.016: I/Radio-JNI(4802): register_android_hardware_Radio DONE
01-25 19:02:19.048: D/AndroidRuntime(4802): Calling main entry com.android.commands.pm.Pm
01-25 19:02:19.054: I/art(4802): System.exit called, status: 0
01-25 19:02:19.055: I/AndroidRuntime(4802): VM exiting with result code 0.
01-25 19:02:19.904: D/AndroidRuntime(4816): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
01-25 19:02:19.911: D/AndroidRuntime(4816): CheckJNI is OFF
01-25 19:02:19.969: D/ICU(4816): No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
01-25 19:02:20.030: I/Radio-JNI(4816): register_android_hardware_Radio DONE
01-25 19:02:20.061: D/AndroidRuntime(4816): Calling main entry com.android.commands.am.Am
01-25 19:02:20.065: I/ActivityManager(607): Force stopping com.myknitcards appid=10087 user=-1: set debug app
01-25 19:02:20.066: I/ActivityManager(607): Killing 4727:com.myknitcards/u0a87 (adj 7): stop com.myknitcards
01-25 19:02:20.077: D/GraphicsStats(607): Buffer count: 3
01-25 19:02:20.077: I/WindowState(607): WIN DEATH: Window{9799d39 u0 com.myknitcards/com.myknitcards.MyKnitCardsMain}
01-25 19:02:20.179: I/ActivityManager(607): Force finishing activity ActivityRecord{16bdee6 u0 com.myknitcards/.MyKnitCardsMain t53}
01-25 19:02:20.182: W/ActivityManager(607): Spurious death for ProcessRecord{d0de1a6 0:com.myknitcards/u0a87}, curProc for 4727: null
01-25 19:02:20.183: I/ActivityManager(607): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.myknitcards/.MyKnitCardsMain} from uid 2000 on display 0
01-25 19:02:20.195: D/AndroidRuntime(4816): Shutting down VM
01-25 19:02:20.226: I/ActivityManager(607): Start proc 4826:com.myknitcards/u0a87 for activity com.myknitcards/.MyKnitCardsMain
01-25 19:02:20.233: I/art(4826): Late-enabling -Xcheck:jni
01-25 19:02:20.272: E/art(4826): Failed sending reply to debugger: Broken pipe
01-25 19:02:20.272: I/art(4826): Debugger is no longer active
01-25 19:02:20.292: W/ActivityThread(4826): Application com.myknitcards is waiting for the debugger on port 8100...
01-25 19:02:20.293: I/System.out(4826): Sending WAIT chunk
01-25 19:02:20.341: I/OpenGLRenderer(607): Initialized EGL, version 1.4
01-25 19:02:21.296: I/art(4826): Debugger is active
01-25 19:02:21.495: I/System.out(4826): Debugger has connected
01-25 19:02:21.495: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:21.695: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:21.895: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.096: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.297: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.498: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.698: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.898: I/System.out(4826): debugger has settled (1457)
01-25 19:02:22.975: W/System(4826): ClassLoader referenced unknown path: /data/app/com.myknitcards-1/lib/arm
01-25 19:02:23.044: D/OpenGLRenderer(4826): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-25 19:02:23.076: D/Finsky(1556): [101] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:23.080: D/Finsky(1556): [143] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:23.084: D/com.myknitcards(4826): In-app Billing is set up OK
01-25 19:02:23.105: I/Adreno-EGL(4826): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
01-25 19:02:23.108: I/OpenGLRenderer(4826): Initialized EGL, version 1.4
01-25 19:02:23.133: W/AppOps(607): Finishing op nesting under-run: uid 1000 pkg android code 24 time=1451855407389 duration=1783 nesting=0
01-25 19:02:23.222: I/ActivityManager(607): Displayed com.myknitcards/.MyKnitCardsMain: +3s7ms
01-25 19:02:23.225: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:23.231: D/WifiStateMachine(607): starting scan for "BooNetwork-5G"WPA_PSK with 2462,5785
01-25 19:02:24.523: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:24.524: I/ActivityManager(607): START u0 {cmp=com.myknitcards/.AvailableCards} from uid 10087 on display 0
01-25 19:02:24.533: D/audio_hw_primary(196): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
01-25 19:02:24.533: D/ACDB-LOADER(196): ACDB -> send_afe_cal
01-25 19:02:24.533: D/audio_hw_primary(196): enable_snd_device: snd_device(2: speaker)
01-25 19:02:24.542: D/audio_hw_primary(196): enable_audio_route: apply and update mixer path: low-latency-playback
01-25 19:02:24.666: I/ActivityManager(607): Displayed com.myknitcards/.AvailableCards: +134ms
01-25 19:02:24.667: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:24.719: D/OpenGLRenderer(4826): endAllStagingAnimators on 0xb388d500 (RippleDrawable) with handle 0xb36fe690
01-25 19:02:27.777: D/audio_hw_primary(196): disable_audio_route: reset and update mixer path: low-latency-playback
01-25 19:02:27.778: D/audio_hw_primary(196): disable_snd_device: snd_device(2: speaker)
01-25 19:02:31.524: D/Synch Billing(4826): Error Null Pointer: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
01-25 19:02:34.741: W/System.err(4826): java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
01-25 19:02:34.742: W/System.err(4826): at com.myknitcards.GetItemList.doInBackground(AvailableCards.java:87)
01-25 19:02:34.742: W/System.err(4826): at com.myknitcards.GetItemList.doInBackground(AvailableCards.java:1)
01-25 19:02:34.742: W/System.err(4826): at android.os.AsyncTask$2.call(AsyncTask.java:295)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-25 19:02:34.743: W/System.err(4826): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
01-25 19:02:34.743: W/System.err(4826): at java.lang.Thread.run(Thread.java:818)
01-25 19:02:38.949: W/art(4826): Debugger told VM to exit with status 1
01-25 19:02:39.025: D/GraphicsStats(607): Buffer count: 3
01-25 19:02:39.026: I/WindowState(607): WIN DEATH: Window{f33f18e u0 com.myknitcards/com.myknitcards.MyKnitCardsMain}
01-25 19:02:39.029: I/WindowState(607): WIN DEATH: Window{6d143a7 u0 com.myknitcards/com.myknitcards.AvailableCards}
01-25 19:02:39.047: I/Zygote(206): Process 4826 exited cleanly (1)
01-25 19:02:39.066: I/ActivityManager(607): Process com.myknitcards (pid 4826) has died
01-25 19:02:39.068: W/ActivityManager(607): Force removing ActivityRecord{d4915cb u0 com.myknitcards/.AvailableCards t54}: app died, no saved state
01-25 19:02:39.080: I/ActivityManager(607): Start proc 4874:com.myknitcards/u0a87 for activity com.myknitcards/.MyKnitCardsMain
01-25 19:02:39.100: I/art(4874): Late-enabling -Xcheck:jni
01-25 19:02:39.157: W/System(4874): ClassLoader referenced unknown path: /data/app/com.myknitcards-1/lib/arm
01-25 19:02:39.223: D/OpenGLRenderer(4874): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-25 19:02:39.264: I/Adreno-EGL(4874): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
01-25 19:02:39.267: I/OpenGLRenderer(4874): Initialized EGL, version 1.4
01-25 19:02:39.342: D/Finsky(1556): [100] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:39.346: D/Finsky(1556): [101] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:39.347: D/com.myknitcards(4874): In-app Billing is set up OK
01-25 19:02:39.404: I/ActivityManager(607): Displayed com.myknitcards/.MyKnitCardsMain: +335ms
01-25 19:02:39.404: W/InputMethodManagerService(607): Got RemoteException sending setActive(false) notification to pid 4826 uid 10087
01-25 19:02:39.412: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:40.885: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:40.888: I/ActivityManager(607): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher (has extras)} from uid 1000 on display 0
01-25 19:02:40.895: D/audio_hw_primary(196): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
01-25 19:02:40.895: D/ACDB-LOADER(196): ACDB -> send_afe_cal
01-25 19:02:40.895: D/audio_hw_primary(196): enable_snd_device: snd_device(2: speaker)
01-25 19:02:40.905: D/audio_hw_primary(196): enable_audio_route: apply and update mixer path: low-latency-playback
01-25 19:02:41.013: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:41.014: I/art(607): Background partial concurrent mark sweep GC freed 25641(1654KB) AllocSpace objects, 19(376KB) LOS objects, 33% free, 18MB/27MB, paused 2.227ms total 106.933ms
01-25 19:02:41.560: W/OpenGLRenderer(1111): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
01-25 19:02:41.560: W/OpenGLRenderer(1111): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
01-25 19:02:43.233: D/WifiStateMachine(607): starting scan for "BooNetwork-5G"WPA_PSK with 2462,5785
01-25 19:02:43.616: I/PowerManagerService(607): Going to sleep due to lid switch (uid 1000)...
01-25 19:02:43.616: I/PowerManagerService(607): Sleeping (uid 1000)...
01-25 19:02:43.621: W/AudioPolicyIntefaceImpl(196): getOutputForAttr uid 10012 tried to pass itself off as 1000
01-25 19:02:43.622: W/AudioFlinger(196): uid 10012 tried to pass itself off as 1000
01-25 19:02:43.625: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:43.632: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:43.698: I/ActivityManager(607): Config changes=480 {1.0 310mcc?mnc en_US ldltr sw600dp w960dp h528dp 320dpi lrg land finger -keyb/v/h -nav/h s.6}
01-25 19:02:43.700: I/InputReader(607): Reconfiguring input devices. changes=0x00000004
01-25 19:02:43.700: I/InputReader(607): Device reconfigured: id=6, name='elan-touchscreen', size 1200x1920, orientation 1, mode 1, display id 0
01-25 19:02:43.703: V/AudioService.RotationHelper(607): publishing device rotation =1 (x90deg)
01-25 19:02:43.707: D/audio_hw_primary(196): adev_set_parameters: enter: rotation=90
01-25 19:02:44.040: D/Launcher.Model(1111): DbDebug Modify item (Play Music) in db, id: 4 (2, 0, 0, 0) --> (2, 0, 0, 0)
01-25 19:02:44.040: D/Launcher.Model(1111): DbDebug Modify item (Play Books) in db, id: 6 (2, 0, 1, 0) --> (2, 0, 1, 0)
01-25 19:02:44.041: D/Launcher.Model(1111): DbDebug Modify item (Play Movies & TV) in db, id: 8 (2, 0, 2, 0) --> (2, 0, 2, 0)
01-25 19:02:44.041: D/Launcher.Model(1111): DbDebug Modify item (Play Games) in db, id: 10 (2, 0, 3, 0) --> (2, 0, 3, 0)
01-25 19:02:44.042: D/Launcher.Model(1111): DbDebug Modify item (Play Newsstand) in db, id: 12 (2, 0, 0, 1) --> (2, 0, 0, 1)
01-25 19:02:44.042: D/Launcher.Model(1111): DbDebug Modify item (Google+) in db, id: 14 (2, 0, 1, 1) --> (2, 0, 1, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Keep) in db, id: 16 (2, 0, 2, 1) --> (2, 0, 2, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Calendar) in db, id: 20 (2, 0, 3, 1) --> (2, 0, 3, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Currents) in db, id: 22 (2, 0, 0, 2) --> (2, 0, 0, 2)
01-25 19:02:44.044: D/Launcher.Model(1111): DbDebug Modify item (Photos) in db, id: 24 (2, 0, 1, 2) --> (2, 0, 1, 2)
01-25 19:02:44.044: D/Launcher.Model(1111): DbDebug Modify item (Earth) in db, id: 26 (2, 0, 2, 2) --> (2, 0, 2, 2)
01-25 19:02:44.147: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:44.190: I/Launcher(1111): Deferring update until onResume
01-25 19:02:44.191: I/Launcher(1111): Deferring update until onResume
01-25 19:02:44.202: I/WindowManager(607): Screen frozen for +551ms due to Window{b92ff9b u0 com.android.launcher/com.android.launcher2.Launcher}
01-25 19:02:44.222: V/KeyguardServiceDelegate(607): onScreenTurnedOff()
01-25 19:02:44.249: I/DisplayManagerService(607): Display device changed state: "Built-in Screen", OFF
01-25 19:02:44.249: D/SurfaceFlinger(188): Set power mode=0, type=0 flinger=0xb6aa4000
01-25 19:02:44.529: D/SurfaceControl(607): Excessive delay in setPowerMode(): 280ms
01-25 19:02:44.530: E/ANDR-PERF-LOCK(204): Failed to apply optimization for resource: 4 level: 0
01-25 19:02:44.540: D/audio_hw_primary(196): adev_set_parameters: enter: screen_state=off
01-25 19:02:44.545: W/qcom_sensors_hal(607): hal_acquire_resources, no active sensors!
01-25 19:02:44.554: E/native(607): do suspend true
01-25 19:02:44.580: D/PhoneStatusBar(705): disable: < expand ICONS* alerts SYSTEM_INFO* back home recent clock search quick_settings >
01-25 19:02:44.721: D/PhoneStatusBar(705): disable: < expand ICONS alerts SYSTEM_INFO back HOME* RECENT* clock SEARCH* quick_settings >
01-25 19:02:46.209: I/art(607): Starting a blocking GC Explicit
01-25 19:02:46.280: I/art(607): Explicit concurrent mark sweep GC freed 14241(923KB) AllocSpace objects, 8(160KB) LOS objects, 33% free, 17MB/26MB, paused 1.129ms total 70.343ms
01-25 19:02:46.953: D/audio_hw_primary(196): disable_audio_route: reset and update mixer path: low-latency-playback
01-25 19:02:46.953: D/audio_hw_primary(196): disable_snd_device: snd_device(2: speaker)
01-25 19:03:03.251: D/WifiStateMachine(607): L2Connected CMD_START_SCAN source -2 41, 42 -> obsolete
01-25 19:03:03.787: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:14.835: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:29.947: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:41.038: E/(193): invalid crash request of size 4 (from pid=4794 uid=0)
01-25 19:03:41.165: E/Diag_Lib(4962): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:03:41.166: E/Sensors(4962): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:03:41.166: E/Sensors(4962): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:03:41.198: W/Sensors(4962): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6f34a08
01-25 19:03:41.261: W/Sensors(4962): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:03:41.272: E/Sensors(4962): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:03:44.187: I/Keyboard.Facilitator.LanguageModelFlusher(1004): run()
01-25 19:03:44.188: I/Keyboard.Facilitator(1004): flushDynamicLanguageModels()
01-25 19:03:44.237: I/ConfigService(1203): onCreate
01-25 19:03:49.340: I/ConfigService(1203): onDestroy
01-25 19:03:54.819: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:04:09.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:04:57.794: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:05:12.826: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:05:13.472: E/(193): invalid crash request of size 4 (from pid=4962 uid=0)
01-25 19:05:13.615: E/Diag_Lib(4977): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:05:13.615: E/Sensors(4977): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:05:13.616: E/Sensors(4977): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:05:13.648: W/Sensors(4977): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6fc4a08
01-25 19:05:13.713: W/Sensors(4977): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:05:13.726: E/Sensors(4977): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:06:00.771: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:06:15.788: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:06:45.928: E/(193): invalid crash request of size 4 (from pid=4977 uid=0)
01-25 19:06:46.091: E/Diag_Lib(4991): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:06:46.091: E/Sensors(4991): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:06:46.092: E/Sensors(4991): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:06:46.119: W/Sensors(4991): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6f2ea08
01-25 19:06:46.185: W/Sensors(4991): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:06:46.200: E/Sensors(4991): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:07:00.446: I/UsageStatsService(607): User[0] Flushing usage stats to disk
01-25 19:07:06.820: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:07:21.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:08:09.795: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:08:18.400: E/(193): invalid crash request of size 4 (from pid=4991 uid=0)
01-25 19:08:18.715: E/Diag_Lib(5008): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:08:18.717: E/Sensors(5008): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:08:18.718: E/Sensors(5008): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:08:18.748: W/Sensors(5008): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6ffca08
01-25 19:08:18.808: W/Sensors(5008): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:08:18.819: E/Sensors(5008): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:08:24.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:09:12.771: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
What could probably be happening is that mServiceConn instance of ServiceConnection connection class takes some time to connect, and until the connection is established, mService remains null.
To fix this, please try the following code:
public class AvailableCards extends Activity {
IInAppBillingService mService;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_available_cards);
String packagename = this.getPackageName();
TextView priceView = (TextView)findViewById(R.id.availablePrice);
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
new GetItemList(packagename, priceView).execute();
}
};
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.available_cards, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class GetItemList extends AsyncTask<Integer, Integer, Long> {
private String pName;
private TextView pView;
GetItemList(String packagename, TextView priceView){
pName = packagename;
pView = priceView;
}
#Override
protected Long doInBackground(Integer... params) {
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("i001");
skuList.add("i002");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = null;
try {
skuDetails = mService.getSkuDetails(3, pName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object;
object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
String mFirstIntermediate;
String mSecondIntermediate;
if (sku.equals("i001")) mFirstIntermediate = price;
else if (sku.equals("i002")) mSecondIntermediate = price;
pView.setText(sku + ": " + price);
}
}
} catch (NullPointerException ne) {
Log.d("Synch Billing", "Error Null Pointer: " + ne.getMessage());
ne.printStackTrace();
}
catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error Remote: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException je) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error JSON: " + je.getMessage());
je.printStackTrace();
}
return null;
}
}
So I have an app that uses a surface view that runs a separate thread for the UI. It was taken almost directly from the Lunar Landing sample app. The app also uses Bluetooth service on another thread but I am sure that this is not related to the problem because I can disable bluetooth all together and it still happens.
The problem in my app is that the app when closed and then reopened does not start running the UI thread afterthread.start() except it throws an error. In the Lunar example they have thread.start() in the onSurfaceCreated method. The problem is when I restart my app (it calls onPause then onSurfaceDestroy) the thread is already running and I get an error when I try to start it. My code for onSurfaceCreated, onPause, onResume and onSurfaceDestroyed is all the same as the example. I know I can use if (this.getState() == Thread.State.NEW) { but that seems like it will mask some of my other issues. I want to master the activity life cycle.
My question is how does the Lunar Lander stop the thread? And why is mine not stopping with the same code and running at the onSurfaceCreated method. Obviously I am missing something. As far as I know in the Lunar example the only thing that is called on the thread on a destroy is thread.join().
Edit 3: Here is the Lunar Lander Example Code if needed.
So these are the three override methods in my surfaceview...
#Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
Log.d(TAG, "surfaceCreated");
// start the bluetooth service
thread.startBluetoothService();
// start the game
//if (this.getState() == Thread.State.NEW) {
Log.d(TAG, "thread start");
// start running the thread
this.start();
//}
Log.d(TAG, "running to true");
// release the thread lock
setRunning(true);
}
// surfaceChanged is called at least once after surfaceCreated
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.d(TAG, "surfaceChanged");
// reset the surface size
thread.setSurfaceSize(width, height);
}
#Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
Log.d(TAG, "surfaceDestroyed");
// make sure to shut down the thread cleanly
boolean retry = true;
// stop the running thread
thread.setRunning(false);
// continuously try to shut down the thread
while (retry){
try{
// blocks calling thread until termination
thread.join();
// stop the bluetooth service
//thread.stopBluetoothService();
retry = false;
}catch(InterruptedException e){
//try to shut it down again
}
}
}
I am really pretty lost with all of this. Any help would be very appreciated, thanks!
Edit:
So I did a little more testing. When the user hits home(which exits the app completely) onPause, then onSurfaceDestroy like I said before. Then when it restarts I get onResume followed by onSurfaceCreated. I think my issue is that it is not calling onCreate when you reenter the app.
Some more questions...
What distinguishes the difference between a onPause and a onDestroy? I think my problem is that since onCreate is not being called I don't have a newly created UI thread which seems like it is still running.
Should the thread be stopped even on a onPause? Because then I am not garenteed to run onCreate which re instantiates the thread. Here is the onCreate code...
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wobble);
// get view and thread
wobbleView = (WobbleView) findViewById(R.id.wobble);
wobbleThread = wobbleView.getThread();
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// If the adapter is null, then Bluetooth is not supported
if (mBluetoothAdapter == null) {
// alert the user of bluetooth failure
Toast.makeText(this, "Bluetooth is not available, using internal devices sensors", Toast.LENGTH_LONG).show();
// set the data source to internal sensors - so we'll just use the devices accel
wobbleThread.setDataSource(WobbleThread.INTERNAL_SENSORS);
// bluetooth is supported so make sure its enabled and
}else{
// make sure bluetooth is enabled on the device
if (!mBluetoothAdapter.isEnabled()) {
Log.d(TAG, "starting request to enable bluetooth");
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
// all is well with bluetooth - use bluetooth
Log.d(TAG, "setting bluetooth to bluetooth");
wobbleThread.setDataSource(WobbleThread.BLUETOOTH);
}
// give the LunarView a handle to the TextView used for messages
wobbleView.setTextView(
(TextView) findViewById(R.id.text_accel),
(TextView) findViewById(R.id.game_msg),
(TextView) findViewById(R.id.text_score),
(TextView) findViewById(R.id.bluetooth_status)
);
if (savedInstanceState == null) {
// we were just launched: set up a new game
//wobbleThread.setState(wobbleThread.STATE_READY);
} else {
//wobbleThread.setRunning(true);
// we are being restored: resume a previous game
//wobbleThread.restoreState(savedInstanceState);
}
}
Edit 2:
Some logcat output
So this is what I get when the thread.start() is called after reopening the app.
11-18 22:50:44.104 4868-4868/com.bme.shawn.wobble E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalThreadStateException: Thread already started
at java.lang.Thread.checkNotStarted(Thread.java:871)
at java.lang.Thread.start(Thread.java:1025)
at com.bme.shawn.wobble.WobbleThread.startGame(WobbleThread.java:213)
at com.bme.shawn.wobble.WobbleView.surfaceCreated(WobbleView.java:94)
at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:240)
at android.view.View.dispatchWindowVisibilityChanged(View.java:7903)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1071)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1071)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1071)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1071)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1289)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1050)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5750)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5406)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
And if I use the thread.getState check and bypass the error I get this when I close then reopen the app. (logs in basically everything) In this case when the app reopens the thread is not drawing at all. Which is very weird since without the check I get an error saying that the thread is already running.
11-18 22:59:13.444 5345-5345/com.bme.shawn.wobble D/WobbleActivity﹕ onPause
11-18 22:59:13.584 5345-5345/com.bme.shawn.wobble D/WobbleView﹕ surfaceDestroyed
11-18 22:59:17.794 5345-5345/com.bme.shawn.wobble D/WobbleActivity﹕ onResume
11-18 22:59:17.804 5345-5345/com.bme.shawn.wobble D/WobbleView﹕ surfaceCreated
11-18 22:59:17.804 5345-5345/com.bme.shawn.wobble D/WobbleThread﹕ running to true
11-18 22:59:17.804 5345-5345/com.bme.shawn.wobble D/WobbleView﹕ surfaceChanged
11-18 22:59:17.804 5345-5345/com.bme.shawn.wobble D/WobbleThread﹕ setting surface sizes
11-18 22:59:17.824 5345-5345/com.bme.shawn.wobble D/dalvikvm﹕ GC_FOR_ALLOC freed 3343K, 2% free 6585K/6668K, paused 13ms, total 13ms
11-18 22:59:17.844 5345-5345/com.bme.shawn.wobble E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 44
11-18 22:59:17.854 5345-5345/com.bme.shawn.wobble E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50
Create a new instance of the thread in surfaceCreated() and start it. And call thread.join() in surfaceDestroyed()to destroy it.