Save button failing to upload data to Parse - android

I'm having trouble getting past the basics of having my app communicate with a server to store data.
I'm attempting to use Parse (https://parse.com/) as the backend of the Android app I'm working on. I got the basic "Quick Start" Parse app going fine, and was able to upload data from the app on my phone to my Parse account using the onCreate() method. Then I tried to create an app which would upload some data when a button is pressed. I can install and run the app, but when I press the button nothing seems to happen, and when I then check my Parse account no data has been uploaded. I included the Parse libs and added them to the build path.
Here is the app code-
package greg.mariani.saveLoad;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.parse.Parse;
import com.parse.ParseObject;
public class SaveLoad1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
Parse.initialize(this, "private_app_token1", "private_app_token2");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void saveUpdates(View view) {
ParseObject updates = new ParseObject("Updates");
updates.put("court", "Brentwood Rec");
updates.put("update", "Game On");
updates.saveInBackground();
}
}
Here is the layout xml-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save"
android:onClick="saveUpdates"/>
</LinearLayout>
Can anyone see what I'm doing wrong?

have you added internet permission to your manifest file?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Related

Trouble with ID in AIDE

I'm writing a simple Android App using AIDE (Android IDE). I gave one of my layout elements an ID, but when I try to access the element using findViewById(), I get an error tht says: "Unknown member 'id' of 'com.mycompany.mailscomunes.R'. I haven't seen this error outside of AIDE.
This is the Java code:
package com.mycompany.mailscomunes;
import android.app.*;
import android.os.*;
import android.content.Intent;
import android.provider.ContactsContract;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.one);
}
}
And this is the relevant XML:
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/one"/>
Remove these lines:
import android.app.*;
import android.os.*;
You're literally importing the entire Android framework, which includes layout files, which has ID's in them.
And you're not including your own ID file (called "R.java").
So remove those two lines, and include this one:
import com.mycompany.mailscomunes.R;
The root of an activity xml should be of Layout type.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Text"/>
</LinearLayout>
Goto your project and delete the build folder and do a rebuild. I had the same problem and is fixed

Can't access the main window/layout from my Activity

This is the start of a simple app to initially display some TextViews and Buttons.
I want to avoid using layout managers by getting the dimensions of the main window/layout and using that to hard-code the components any way I want.
But my main Activity can't get non-zero data about the main window/layout.
I don't know if it's supposed to be this way or if I'm doing something dumb, and would appreciate some help.
This is a command line project using Ant under win10 and outputting to a USB'd phone.
I've updated the SDK Manager to Android 6.0 (API 23) with Android Tools 24.4.1 and installed v23.2 of the Android Support Lib, although Ant seems to think differently as you can see in my previous message which has the Ant output:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2.
I don't know if that makes a difference, but not in this case I think.
The next two files are complete as far as they go.
I would have included more but the way the website mangles my code doesn't encourage uploading to it.
It might have helped if I could have comprehended the 'How to Format' but (A) I didn't even see it before my first post and (B) I don't understand it now.
There are far too many instructions and too much jargon; e.g. what is a backtick?
Can't there be a simple format that will take everything you throw at it?
main.xml
========
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
package="com.Chatterton.Peter.ChessClock"
android:id="#+id/main_window"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/time_text_view_left"
android:text="top_left"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:layout_alignParentBottom="true"
...
There are a total of 4 components, one per corner, with the same layout_width and height.
ChessClockActivity.java
=======================
package com.Chatterton.Peter.ChessClock;
import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Color;
import android.widget.TextView;
import android.util.Log;
public class ChessClockActivity extends Activity
{
public int winOriginX=10, winOriginY=20, winWidth=44, winHeight=66;
#Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout mainLayout = (RelativeLayout)findViewById( R.id.main_window );
int mainWidth = mainLayout.getWidth();
int mainHeight = mainLayout.getHeight();
Log.d( "clox", "mainLayout=" + mainLayout );
Log.d( "clox", "main W/H=" + mainWidth + "/" + mainWidth );
...
Screen Results:
It shows the last component displayed -- full-size -- with its text.
logcat results:
===============
D:\Android\ChessClock>adb shell
shell#android:/ $ logcat clox:D *:S
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/clox (27214): mainLayout=android.widget.RelativeLayout#41755b80
D/clox (27214): main W/H=0/0
**
They have no size at this point of the initialization process.
Click here to an answer that will let you access the sizes of your components after they have been displayed.
Or perhaps you can get the window size and figure the placement of your components by that value......
Answer here

choosing resource type during xml file creating in Eclipse

When I want to create a XML file in Android SDK installed ECLIPSE for the purpose of SharedPreferences Activity layout... I do not see that dialog box to appear where I can choose from.
Following are my files.
MainActivity.java
package com.preferences_activity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
}
}
Preferences.java
package com.preferences_activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Preferences extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:text="#string/button1" />
</RelativeLayout>
preferences_activity.xml
<?xml version="1.0" encoding="UTF-8"?>
In the preferences_activity.xml, this is what I get when I create a xml file.
But I wanted to choose a type called preferences while creating a xml file. preferences layout is one of the type of resource available in the dialog box. Others are like: Layout, Values, Menu, AppWidget Provider Searchable, Animation.
If I had a option to choose a preferences layout option while creating a xml file I would be getting the following code:
<?xml version="1.0" encoding="UTF-8"?>
<PreferencesScreen
xmlns:android="http://schemas.android.com/apk/res/android">
</PreferenceScreen>
My Question is again: Where can I get that dialog box from while creating xml file where I can choose the resource type?
I am sorry if this question sounds funny. But I am struggling with it for few days in a row.
Thank you all.
For future Visitors:
I was struggling because I was using eclipse app instead of the one that was under adt-bundle. If you use the app under the adt-bundle, that has a logo with {} and light green background than you will have an options to choose a layout or any sorts of resources while creating an xml file. Pls, one more thing to note, I was having hard time to find a wizard for creating a xml file ( I could do it manually with right clicking the project and other and choosing xml file).. but I m talking about the wizard on the menu bar, you should be able to see it if you use this app under adt-bundle instead of regular eclipse. My answer may not be that likable, but sharing for future android beginners.

How can I solve R.layout.main cannot be resolved in my android apps?

Im new as a developer of Android apps. I find a problem. that is R.layout.main cannot be resolved. How can I solve my problem. my code is here. please solve my problem.
package com.android;
import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class HelloActivity extends Activity {
/** Called when the activity is first created. */
Button bt;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt=(Button)findViewById(R.id.ButtonOk);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Toast.makeText(getBaseContext(), "Welcome Android World", 3000).show();
Intent intent = new Intent(HelloActivity.this, DisplayActivity.class);
startActivity(intent);
}
});
}
}
*
and my xml code is here:
*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:id="#+id/ButtonOk" android:height="50dp" android:width="100dp"></Button>
</LinearLayout>
Step 1 : Remove import android.R;
Step 2 : Clean And Rebuild (It should work)
If not
Then close the project exits eclipse and open again. Follow the steps it should work.
If not
Change your package
From
import android.R;
To
import yourpackage.R;
It Should work
Remove the line import android.R from the header.
and do a Ctrl + Shift + O
If android.R appears again, then manually write
import <yourpackagename>.R
Looks like you used the package name as com.android.R. Ideally speaking, avoid using package names like com.android. Try to maintain it like
com.companyname.appname
So you get into that habit, and don't have the pain of changing the package name in all the folders once you are about to publish.
Import com.android.R not android.R because your package name is com.android
Try to Clean and Rebuild your application and this should solve the issue.
my friend,
check that whether name of your xml file is "main" because we always write setContentView(R.layout.your_xml_file_name);
If you find my solution worthy then please like it
I also encountered this problem on IntelliJ IDEA and this is how I was able to solve the problem, but first I noticed the following:
this problem did not hinder the execution of the application
the resource file (R.java) located in the out/production/my/package/name directory is automatically updated, but the resource file (R.java) located in the gen/my.package.name directory is not updated automatically
IntelliJ IDEA uses the non-updated R.java for intellisence
So, I copied the layout class that was generated in R.java file in out/production/my/package/name directory, as below
public static final class layout {
public static final int main = 2130903040;
public layout() {
}
}
and I pasted this into the R.java file in gen/my.package.name directory
NOTE:
Please, and please, don't modify the auto-generated resource file R.java file in out/production/my/package/name

Get code string in Android

Ex: I have a project with UI contains a button..
Activity:
package android.tuanshaker.myproject.com;
import android.app.Activity;
import android.os.Bundle;
public class MyProjectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
And file main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</LinearLayout>
I want to display code and xml of my project by textview..How do i can to get them?
Copy the xml, js code files to res/raw. Use Context.getResources().openRawResource() to read them.
In addition, you can use jHighlight to format those source codes (in a web view).

Categories

Resources