Tetris has stopped working - java

I'm making tetris in Android via eclipse (I use an emulator of eclipse). The program worked untill I added a bunch of stuff (maybe wasn't so smart, but nothing visual was changed so) I didn't run the progam in a while. Now I can go to my first activity, but as soon as I click the button to go to my next one, the program stops working :(
Here is my code:
MainActivity.java http://pastebin.com/P9AAJ90n (button towards Tetris.java)
Tetris.java http://pastebin.com/WEsXshPh (probably contains error)
TetrisView.java http://pastebin.com/ejUJjLMk
I think that's the code the problem is located in, but do ask for more if required...
(I think the problem is located in the onCreate() method of Tetris.java
Now the LogCat Debug text:
http://pastebin.com/MSCxHdsr
Thanks in advance
PS: If I remove the whole onCreate() of Tetris.java except the first 2 lines, I can run the program.
-----------------------------------------------EDIT-----------------------------------------------
I removed one of the setContentView(), still stops working. Also looked into DroppedTiles, thought I fixed it but didn't :(
Logcat: http://pastebin.com/JHu7n1uA
DroppedTiles: http://pastebin.com/tyKLuxVd
Block: http://pastebin.com/zmPa7cv7
I commented the DroppedTiles in Tetris.java...
Tried reading the debug log but most of it I do not understand sadly

you're setting content view twice
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tetris);
// Intent intent = getIntent();
// Add mTetrisView to this
mTetrisView = new TetrisView(this, null);
setContentView(mTetrisView);
mTetrisView.init();
figure out which is the correct one (probably the first) and remove the other.

Related

SyncResultReceiver$TimeoutException crashing Android a lot

I've disabled all autofill with View.AUTOFILL_TYPE_NONE
com.android.internal.util.SyncResultReceiver$TimeoutException:
at com.android.internal.util.SyncResultReceiver.waitResult (SyncResultReceiver.java:60)
at com.android.internal.util.SyncResultReceiver.getIntResult (SyncResultReceiver.java:68)
at android.view.autofill.AutofillManager.ensureServiceClientAddedIfNeededLocked (AutofillManager.java:1831)
at android.view.autofill.AutofillManager.notifyViewEnteredLocked (AutofillManager.java:956)
at android.view.autofill.AutofillManager.notifyViewEntered (AutofillManager.java:940)
at android.view.autofill.AutofillManager.notifyViewEntered (AutofillManager.java:897)
at android.view.View.notifyEnterOrExitForAutoFillIfNeeded (View.java:7972)
at android.view.View.onFocusChanged (View.java:7934)
at android.widget.TextView.onFocusChanged (TextView.java:10801)
at android.view.View.handleFocusGainInternal (View.java:7597)
at android.view.View.requestFocusNoSearch (View.java:12962)
at android.view.View.requestFocus (View.java:12936)
at android.view.View.requestFocus (View.java:12903)
at android.view.View.requestFocus (View.java:12845)
at android.view.View.onTouchEvent (View.java:15336)
I am not sure what is wrong.
It only happens to Android 10 devices.
This happens when I click on an EditText the app crashes and restarts.
I've solved my problem with similar crash on click on edittext, by rename of variable named "userId"
I'm still not shure why this magic works, but try to rename such variables with common names

How to fix Couchbase ForestDB "File handle is busy" when deleting view?

When deleting from couchbase, screen freezes.
I am deleting like so
resetViews1(db)
resetViews2(db)
resetViews3(db)
resetViews4(db)
resetViews5(db)
resetViews6(db)
resetViews7(db)
resetViews8(db)
resetViews9(db)
Where each resetViews method is calling
database.getView(view_id).delete()
I have pinpointed the freeze to come from resetViews7 method. Inspecting logcat it shows
`com.couchbase.cbforest.ForestException: file handle is busy'.
I have tried removing the 7th call and if removed the screen does not freeze up. Unsure why this is causing a screen freeze.

Yelp API on Android Studio

Been a lurker on this site to help find answers to some of my problems before, but I am currently stuck on this and could not find a recent solution. The closest answers I found to my problem were Yelp API Android Integration and Yelp Integration in Android
I tried following the steps in the 2nd link but they are a bit outdated. I have registered for an API, downloaded the jar files from the github and synced them, and made the YelpAPI.java and TwoStepOAuth.java files and removed the main method from YelpAPI. I am stuck on step 4 on the search part. I tried to call the queryAPI method from inside an onClick method I made for a button
public void getRandom(View view) {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
YelpAPI.YelpAPICLI yelpApiCli = new YelpAPI.YelpAPICLI();
new JCommander(yelpApiCli);
YelpAPI yelpApi = new YelpAPI(CONSUMER_KEY, CONSUMER_SECRET, TOKEN, TOKEN_SECRET);
try {
YelpAPI.queryAPI(yelpApi, yelpApiCli);
} catch (JSONException e) {
e.printStackTrace();
}
}
Basically what I want this to do is, when the button is pressed, I want it to go to a second screen that will display what I query Yelp for. I haven't worked on that part yet, right now I just want to get a result back from Yelp. Keep in mind I am a complete noob at Android Studio and at most intermediate at Java.
Any help is greatly appreciated, it seems like its a really simple problem but its taking me forever to figure out on my own.
You can't do blocking task like downloading or image loading in android's Main thread (UI Thread). You can't block UI for more than 5 seconds. If you try it to block for more than 5 seconds than your app will stop working and display "Unfornutaley your app has stopped working" because of error too much work on main thread. So you need to make use of async task.

Robotium - Trying to click home button in app

I'm new to robotium and i'm trying to write a quick and dirty script to run through all screens in an app.
The problem i have mainly with the 'home button' in the app. I've tried lots of options but i cant seem to get it to click there except with index, which is not what i want.
When i check out the button with the hierarchyviewer it looks like this:
Link
However when i try for example:
assertTrue(
"Wait for text (id: myapp.R.id.home) failed.",
solo.waitForImageById("myapp.R.id.home", 20000));
solo.clickOnImage((ImageView) solo.findViewById("myapp.R.id.home"));
solo.waitForActivity("MenuActivity");
It fails at the waitForImageByID line. Ive tried multiple options like waitForImageButton etc, but i just cant seem to get it clicked. What am i missing here?
junit.framework.AssertionFailedError: View with id: '0' is not found!
at com.jayway.android.robotium.solo.Solo.getView(Solo.java:1990)
at com.jayway.android.robotium.solo.Solo.getView(Solo.java:1970)
at com.bitbar.recorder.extensions.OtherUtils.a(OtherUtils.java:246)
at com.bitbar.recorder.extensions.OtherUtils.b(OtherUtils.java:241)
at com.bitbar.recorder.extensions.v.a(Waiter.java:71)
at com.bitbar.recorder.extensions.ExtSolo.waitForImageButtonById(ExtSolo.java:4176)
at com.example.android.apis.test.Test.testRecorded(Test.java:137)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1740)
Use the following line to press the home button in the action bar
solo.clickOnActionBarHomeButton();
The issue is that the id that it is referring is not in your application, it is in androids default R file, try android.R.id.home and it should work fine. It is worth noting though that if your application uses action bar sherlock to support the action bar pre 4.0 that this will have a different ID there and you will have to handle this in your test.
You can see this for yourself looking at: http://developer.android.com/reference/android/R.id.html
When you are using ActionBarSherlock there are two different Ids you have to check, android.R.id.home for API-Level>11 and abs__home for lower levels (provided by ActionBarSherlock):
View homeButton = activity.findViewById(android.R.id.home);
if (homeButton == null) {
homeButton = activity.findViewById(R.id.abs__home);
}
What about this code:
ArrayList<LinearLayout> ll = solo.getCurrentViews(LinearLayout.class);
//You can change 1 with the ordinal number of LinearLayout you want to click.
solo.clickOnView(ll.get(1));
or also
ArrayList<ImageView> iv = solo.getCurrentViews(ImageView.class);
//You can change 0 with the ordinal number of Image you want to click.
solo.clickOnView(iv.get(0));
I think if you identify the correct id for view or linear layout or image view it should work.
Dave C's answer was working only partially for me. The button was clicked but before the preceding screen was loaded assertions had started and thus were always false. The solution is to run "home click" on the main thread (Robotium 5.2.1):
getInstrumentation().runOnMainSync(new Runnable() {
#Override
public void run() {
solo.clickOnActionBarHomeButton();
}
});
From your question I can see that it is an image view. You can click on any view using the following piece of code.
View view = solo.getView("View_name_from_hierachy_viewer");
solo.clickOnView(view);
View_name_from_hierachy_viewer in your case will be "home".
Let me know if this does not work.

Hiding and showing Eclipse view programmatically

I am showing and hiding Eclipse view with code below. It works perfectly with Eclipse 3.3, but with Eclipse Juno (version 4.3) it's not showing the first time but showing when I fire the event for the second time.
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
page.showView(UserView.ID);
page.hideView(page.findView(UserView.ID));
Is somebody come across with this situation before?
I am not sure why you are not getting it the first time. Check to see if you dont have null pointer errors when you fire it the first time.
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
can return a null if the workbench is not yet loaded.
I faced the same issue with the minimized state, so I tried chaging the view's state forcing it to appear after page.showView(UserView.ID);
this piece of code got my viewPart to show :
page.showView(UserView.ID);
IWorkbenchPartReference ref = page.getReference(searchResultUI);
page.setPartState(ref,IWorkbenchPage.STATE_RESTORED); //or STATE_MAXIMIZED

Categories