[Android studio] App keeps crashing when I click on the background

Learn Programming - 14 hours 23 min ago

Hello, I just got started into app development and here's a simple app I made which involves pure java

I'm trying to change the text in textView to " hey I'm scrolling " or " hey Im flinging " when the respective gesture is done, however my app keeps crashing when I click on the background. What's the reason?

Here's the code:

package com.example.zeeman.gestureaftermids; import; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.view.MotionEvent; import android.view.GestureDetector; import; import android.widget.RelativeLayout; import; public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener { private GestureDetectorCompat gestureDetector; public TextView myTxt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout screen = new RelativeLayout(this); screen.setBackgroundColor(Color.GREEN); Button btn = new Button(this); btn.setText("Click me"); btn.setBackgroundColor(Color.BLUE); btn.setTextColor(Color.WHITE); btn.setId(2); myTxt = new TextView(this); myTxt.setText("hello moto"); myTxt.setTextSize(30); myTxt.setId(1); myTxt.setTextColor(Color.RED); RelativeLayout.LayoutParams buttonDetails = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); RelativeLayout.LayoutParams txtDetails = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); txtDetails.addRule(RelativeLayout.CENTER_HORIZONTAL); txtDetails.addRule(RelativeLayout.ABOVE, btn.getId()); txtDetails.setMargins(0,0,0,100); buttonDetails.addRule(RelativeLayout.CENTER_HORIZONTAL); buttonDetails.addRule(RelativeLayout.CENTER_VERTICAL); screen.addView(btn, buttonDetails); screen.addView(myTxt, txtDetails); //event handlers btn.setOnClickListener( new View.OnClickListener() { public void onClick(View view){ myTxt.setText("Hello world"); } } ); setContentView(screen); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onDoubleTap(MotionEvent e) { return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return true; } @Override public boolean onDown(MotionEvent e) { return true; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return true; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return true; } // used to detect whether gesture or not. @Override public boolean onTouchEvent(MotionEvent event) { this.gestureDetector.onTouchEvent(event); return super.onTouchEvent(event); } } submitted by /u/Neoguy396
[link] [comments]

Rails DB migration is causing weird text in my development.sqlite3 file. What is causing this -

Learn Programming - 14 hours 56 min ago

Here is a sample of what is showing up in the file -

SQLite format 3@ .� ��;�!� ?�

Usually this file is just rows and columns of numbers. What is causing it to act this way? Has anyone ever seen this?

Let me know if I can be more specific on this issue. Any help is appreciated.

submitted by /u/learning2code101
[link] [comments]

Are there any places to just read through well commented and organized code for various different programs?

Learn Programming - 15 hours 4 min ago

I'm learning Python and I occasionally find myself with medial amount of motivation where I don't want to sit down and write code or study new concepts, but I would like to read code that's been well documented and is writen using good practices.

Are there any decent collections with code that has been more or less vetted?

submitted by /u/Math-Code-Love
[link] [comments]

[HTML] how to disable body scrolling when modal is showing?

Learn Programming - 15 hours 19 min ago

In my Angular 5 project I have a modal and it is open, when I scroll (up and down) the body of the html scrolls also.

If I set the css of boday and html to:

html,body{ overflow: hidden; }

Then I cant scroll at all even when no modal is showing.

I know in Angular you can only change the css properties for its related HTML template not the root (html, body).

What I really need is to set overflow-y: hidden on the html and body tags only when a modal is open.

How can I do this while keeping to best practices in Angular 5?

submitted by /u/ghi3578934dgdfgdg
[link] [comments]

Having trouble seeing projects/reading resources through to completion

Learn Programming - 15 hours 24 min ago

The title is pretty self-explanatory. I cannot for the life of me stay motivated to stick with a book for it's entire duration or see a project through to completion.

All my projects grow in complexity beyond what I can manage without writing disorganized and sloppy code, (which happens very, very, very quickly) so I decided to look into Test Driven Development.

I began to read a book about Test Driven Development but it uses Django for the majority of it's examples, which reminded me that I wanted to learn how to use Static Site Generators before I learned how to do dynamic sites.

When I sit down to learn Pelican I can't help but be reminded that I still need to finish reading Automate the Boring Stuff with Python and when I sit down to read Automate the Boring Stuff I can't help but wonder if I should have saw CS50 through to the end and when I think about CS50 I'm reminded of the fact that I'm a self-taught programmer who might not ever have a programming related job and wonder if I should be dedicating my time to a more realistic goal.

submitted by /u/airikWarren
[link] [comments]

How Do I Control My Blend Shapes in Unity3d

Learn Programming - 15 hours 31 min ago

how do I control my blend shapes? I want them to be set to a random number after a button is pressed. I know I have to use public void SetBlendShapeWeight(int index, float value); but I dont know how to use it or how to have it set for multiple blend shapes on a single mesh.

submitted by /u/Degleewana007
[link] [comments]

MongoDB Schema Design help

Learn Programming - 15 hours 41 min ago

I'm coding a news website, it will have articles categorized into: blog, news, reviews etc.

I have to display all the 3 on the landing page, somewhat like:


(articles go here)


(articles go here)


(articles go here)

How should the database design be? Should I create a separate collection for each: one for news, one for reviews... or should I create one for all of them, and sort them with a "category" property?

submitted by /u/epic_within
[link] [comments]

I'm interested in learning coding to do projects on the side of going to school, making a bit of extra income.

Learn Programming - 15 hours 42 min ago

What "field(s)" of coding am I looking at if I want to make some money while going to school (for other things), but without the intention of making it my career. Also, aside from Codeacademy and Khan Academy, what are other free resources I should be taking advantage of? Thanks so much to those who take the time to answer one or both of my questions.

submitted by /u/grungebobsquarepants
[link] [comments]

[MIPS] Any resources for learning MIPS relatively quickly?

Learn Programming - 15 hours 53 min ago

I am at university, taking our senior level compilers course. I transferred from another college, and I took assembly there instead of at my current university. When I took assembly (years ago, might I add), I was taught x86. My current University teaches MIPS, and the compilers course also uses MIPS when you generate your code. I don't know any MIPS at all, but need some sort of crash course. Does anyone have any good resources for this? I am planning on visiting office hours frequently when using MIPS comes around, but I would like to learn about it until then.

Thank you for your time.

submitted by /u/AtomicGreenBean
[link] [comments]

I want to be job ready in a few months. How to go about this?

Learn Programming - 15 hours 53 min ago

So I decided to move home and focus on building my coding ability and skills. I'm basically starting from scratch using online programs, and hoping to possibly jump into a boot camp to expedite the learning process. I'm hoping to be job ready in a couple of months even if it's just a $20/h gig to start. I'm 28, just finished my bachelors in Linguistics/Philosophy and I'm in the NYC area so I'm looking into some boot camps in the city and I'll probably use FreeCodeCamp, Odin Project along with some other MOOCs.

I just want to know what worked for you guys in being able to learn on your own? Did you use notebooks to write notes? Did you buy supplementary texts? Overall, how much time did you spend on this everyday. I tried following FCC a year ago and I got nowhere because it was easy to breeze through it without taking care to fully integrate the knowledge.

submitted by /u/shadesofzen
[link] [comments]

[Typescript] Using type definitions from @types in code

Learn Programming - 16 hours 4 min ago

I'm writing a script to work with MP3 files in Typescript, and I've run into a problem with using types. Specifically, I've written a function that uses musicmetadata to read in the MP3 tags and return a promise that resolves once the callback is completed, so I can use async/await with it. Here's my example code:

import * as fs from 'fs'; import * as mm from 'musicmetadata'; function readMetadata(path: string): Promise<any> { return new Promise<any>((resolve, reject) => { const stream = fs.createReadStream(path) mm(stream, {duration: true}, (err, metadata) => { // Ignore errors for example stream.close() resolve(metadata) }) }) } readMetadata('music.mp3').then((metadata) => { console.log(metadata) })

This works, but I need to specify the function return type as Promise<any>. I would rather specify it as Promise<Metadata> as it's actually returning, not to mention I'll be using the Metadata interface elsewhere as well. The problem I have is, how do I get the Metadata interface specified in the @types definition? Typescript refuses to compile if I try to directly import @types/musicmetadata, and the error implies I can simply import musicmetadata instead. But I can't find any way of importing any of the declared interfaces from the musicmetadata module.

I'm familiar with ES6+, but I'm still very new to Typescript, so I'm probably missing something obvious here. Currently my solution is to simply copy & paste the interfaces from the @types definition into my own code, but I'm sure there's a better way.

submitted by /u/BitLooter
[link] [comments]

Wondering how c# programming works in the general sense of games...

Learn Programming - Mon, 01/15/2018 - 23:59

Now to everyone That knows a lot about code, this may sound somewhat dumb or you dont get what I mean. Let me explain:

I’m looking at the language of C#, I see syntax and thats all I get about it... How do I use that to have visual pictures for some kind of software or game? I tried googling about how this part of the programming works with no luck. If somebody could explain to me how code is used for software or game (kinda like you use this kind of code to do this) I think that having this side of programming explained to me can help me understand c# better. Also, where can I go to learn c#? Any good tutorials you guys suggest? Anyways I appreciate any help I can get with my questions. And if I’m missing something important about something let me know

submitted by /u/zmandarocks
[link] [comments]

I just got some IDEs from Jetbrain using student credentials. Just a few quick questions

Learn Programming - Mon, 01/15/2018 - 23:56

Will I be able to keep the software forever?

Will I get free/any updates?

submitted by /u/captaindarshan
[link] [comments]

How to think about using bitwise operators?

Learn Programming - Mon, 01/15/2018 - 23:55

I just came across a questions:

Given an array where all ints have a pair except one. Find the int that is unique.

The most optimal solution was to use XOR. I went though a few examples and couldn't believe that worked. I want to get better at apply bitwise operators, but I'm not sure how to think about when to apply it. I'm aware of what each operator does, but not when to use it.

submitted by /u/forgiveangel
[link] [comments]