View Single Post
  #82  
Old November 16th 18, 05:08 AM posted to comp.mobile.android,alt.comp.freeware,microsoft.public.windowsxp.general
arlen michael holder
external usenet poster
 
Posts: 48
Default Report: My first "hello world" using Android Studio freeware on Windows worked just fine (in about an hour)

On Sat, 10 Nov 2018 10:43:10 +0000, Bill wrote:

I have now got through the text based button and message build, which
works, and am starting on the first Butterfield video.


Hi Bill,

Heads up!

I just finished the last Butterfield video (number 4 of 4).
Do NOT do it!

It's completely different in character from the previous 3.
Don't even _think_ of doing it. Really.

I don't think _anyone_ (at our stage) can be successful with it.
You need to set up a SQL server which he doesn't cover at all!
And he skips steps like you can't believe!
He never even scrolls through the final code so you can check for errors.

It's just not worth the effort.
I wish I knew that before I went through every step, but I know that now.

Everything below is simply detail on the information above.
Don't do that fourth Butterfield product. Let's find another that's better.
================================================== ==========================
o Android Studio For Beginners Part 1, 2, 3, 4 by Bill Butterfield,
Published on Jun 13, 2017
https://youtu.be/dFlPARW5IX8 (part 1) a simple adder
https://youtu.be/6ow3L39Wxmg (part 2) call a program outside the app
https://youtu.be/rdGpT1pIJlw (part 3) grocery list
https://youtu.be/bu5Y3uZ6LLM (part 4) mysql grocery list
================================================== ==========================
The first three videos are fantastic, but the fourth is almost impossible.
o You need to set up an sql server and database on port 3306
o You need to obtain & set up oracle mysql workbench
o You need to add .NET Framework & Visual C++ runtimes if you don't have them
o His video is mysql version 3 but the current version is version 8
o You need to import the java connector jar file library as a module
o He cuts and pastes entire files during the video without scrolling!
o That's critical since you can't follow easily what he's doing.

This last video is NOTHING like the prior 3 videos in terms of handholding!
================================================== ==========================
Some of the software you need will be:
================================================== ==========================
JDBC Driver for MySQL (Connector/J)
https://dev.mysql.com/downloads/connector/j/
Hit "Platform Independent" in the selector.
That gives a tar ball and a zip archive.
Obviously get the zip archive.
Platform Independent (Architecture Independent), ZIP Archive 8.0.13 6.4M
Download (mysql-connector-java-8.0.13.zip)
MD5: a106e8c50a616b93ce28a6f7cb991586

https://dev.mysql.com/downloads/file/?id=480292
Begin Your Download
mysql-connector-java-8.0.13.zip
https://cdn.mysql.com//Downloads/Con...ava-8.0.13.zip
================================================== ==========================
Unzip and move the mysql-connector-java-8.0.13 folder to
C:\app\editor\android\sql\mysql-connector-java-8.0.13\

Make a note of the path (as you'll need it later):
C:\app\editor\android\sql\mysql-connector-java-8.0.13\mysql-connector-java-8.0.13.jar
================================================== ==========================
My Sequel Workbench
https://dev.mysql.com/downloads/workbench/
Windows (x86, 64-bit), MSI Installer 8.0.13 33.6M
Download
(mysql-workbench-community-8.0.13-winx64.msi)
MD5: 298f374a2a032bf5148fc4909a2dcab1 | Signature

https://dev.mysql.com/downloads/file/?id=480542
https://cdn.mysql.com//Downloads/MyS....13-winx64.msi

Requires:
o Microsoft .NET Framework 4.5
https://www.microsoft.com/en-us/down....aspx?id=30653
https://download.microsoft.com/downl...Full_setup.exe
o Visual C++ Redistributable for Visual Studio 2015
https://www.microsoft.com/en-us/down....aspx?id=48145
https://download.microsoft.com/downl...redist.x64.exe
https://download.microsoft.com/downl...redist.x86.exe
================================================== ==========================
Importing the jar file is pretty easy though:
AndroidStudio321: Right click on app new module import JAR/.AAR Package
C:\app\editor\android\sql\mysql-connector-java-8.0.13\mysql-connector-java-8.0.13.jar
================================================== ==========================
Even if you get the program to work, you _still_ need to set up a SQL server!
================================================== ==========================
Here are the main files at the point that I gave up (after about 2 hours).

o C:\tmp\android\app07\app\src\main\AndroidManifest. xml
o C:\tmp\android\app07\app\src\main\java\com\kiss\ap p07\mainActivity.java
o C:\tmp\android\app07\app\src\main\java\com\kiss\ap p07\ItemAdapter.java
o C:\tmp\android\app07\app\src\main\java\com\kiss\ap p07\DbStrings.java
o C:\tmp\android\app07\app\build.gradle
o C:\tmp\android\app07\app\src\main\res\layout\item_ layout.xml
o C:\tmp\android\app07\app\src\main\res\layout\activ ity_main.xml
================================================== ==========================
C:\tmp\android\app07\app\src\main\AndroidManifest. xml

?xml version="1.0" encoding="utf-8"?
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kiss.app07"

uses-permission android:name="android.permission.INTERNET" /

application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
activity android:name=".MainActivity"
intent-filter
action android:name="android.intent.action.MAIN" /

category android:name="android.intent.category.LAUNCHER" /
/intent-filter
/activity
/application

/manifest
================================================== ==========================
C:\tmp\android\app07\app\src\main\java\com\kiss\ap p07\mainActivity.java

package com.kiss.app07;

import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextClock;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

ItemAdapter itemAdapter;
Context thisContext;
ListView myListView;
TextView progressTextView;
MapString, Double fruitsMap = new LinkedHashMapString, Double();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Resources res = getResources();
myListView = (ListView) findViewById(R.id.myListView);
progressTextView = (TextView) findViewById(R.id.progressTextView);
thisContext = this;

progressTextView.setText("");
Button btn = (Button) findViewById(R.id.getDataButton);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GetData retrieveData = new GetData();
retrieveData.execute("");
}
});
}
};
}

private class GetData extends AsyncTaskString, String, String {
String msg = "";
// JDBC drivr name and database URL
static final String JDBC_DRIVER = "com.kill.app07.Driver";
// Example: 10.20.30.40:3306
static final String DB_URL = "jdbc:mysql://" +
DbStrings.DATABASE_URL + "/" +
DbStrings.DATABASE_NAME;

@Override
protected void onPreExecute() {
progressTextView.setText("Connecting to database...");
}

@Override
protected String doInBackground(String...params) {

Connection conn = null;
Statement stmt = null;

try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, DbStrings.USERNAME, DbStrings.PASSWORD);

stmt = conn.createStatement();
String sql = "SELECT * FROM fruits";
ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {
String name = rs.getString("name");
double price = rs.getDouble("price");

fruitsMap.put(name, price);
}

msg = "Process complete.";

rs.close();
stmt.close();
conn.close();

} catch (SQLException connError) {
msg = "An exception was thorn for JDBC.";
connError.printStackTrace();
;
} catch (ClassNotFoundException e) {
msg = "A class not found exception was thrown.";
e.printStackTrace();
} finally {

try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

}

return null;
}

@Override
protected void onPostExexute (String msg){

progressTextView.setText(this.msg);

if (fruitsMap.size() 0) {

itemAdapter = new ItemAdapter(thisContext, fruitsMap);
myListView.setAdapter(itemAdapter);
}

}

} //End of MainActivity
================================================== ==========================
C:\tmp\android\app07\app\src\main\java\com\kiss\ap p07\ItemAdapter.java

package com.kiss.app07;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kiss.app07.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Created by Example on 11/15/2018.
*/

public class ItemAdapter extends BaseAdapter {

LayoutInflater mInflator;
MapString, Double map;
ListString names;
ListDouble prices;

public ItemAdapter(Context c, Map m) {
mInflator = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
map = m;
names = new ArrayListString(map.keySet());
prices = new ArrayListDouble(map.values());
}

@Override
public int getCount() {
return map.size();
}

@Override
public Object getItem(int i) {
return names.get(i);
}

@Override
public long getItemId(int i) {
return i;
}

@Override
public View getView(int i, View convertView, ViewGroup parent) {

View v = mInflator.inflate(R.layout.item_layout, null);
TextView nameTextView = (TextView) v.findViewById(R.id.nameTextView);
TextView priceTextView = (TextView) v.findViewById(R.id.priceTextView);

nameTextView.setText(names.get(i));
priceTextView.setText("$" + prices.get(i).toString());

return v;
}
}
================================================== ==========================
C:\tmp\android\app07\app\src\main\java\com\kiss\ap p07\DbStrings.java

package com.kiss.app07;

public class DbStrings {

static final String DATABASE_URL = "129.0.0.1:3306";
static final String DATABASE_NAME = "mhs_example";
static final String USERNAME = "some_user";
static final String PASSWORD = "your_password";
}
================================================== ==========================
C:\tmp\android\app07\app\build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.kiss.app07"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunne r"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-co3.0.2'

compile project (':mysql-connector-java-8.0.13')
}
================================================== ==========================
C:\tmp\android\app07\app\src\main\res\layout\item_ layout.xml

?xml version="1.0" encoding="utf-8"?
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"

TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="24dp"
android:layout_marginTop="35dp"
android:layout_marginBottom="35dp"
android:text="Name" /

TextView
android:id="@+id/priceTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/nameTextView"
android:layout_alignParentEnd="true"
android:layout_marginEnd="63dp"
android:text="Price" /
/RelativeLayout
================================================== ==========================
C:\tmp\android\app07\app\src\main\res\layout\activ ity_main.xml

?xml version="1.0" encoding="utf-8"?
android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"

Button
android:id="@+id/getDataButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Get Data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /

TextView
android:id="@+id/progressTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Progress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/getDataButton" /

ListView
android:id="@+id/myListView"
android:layout_width="368dp"
android:layout_height="412dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /
/android.support.constraint.ConstraintLayout
================================================== ==========================
================================================== ==========================
Ads