hey guys,
I started learning android development and I've built a simple app that suppose to display a background and a few buttons that do nothing (for now). but I cant seem to get this app to work on the emulator w/o crashing. I've tried to look for an error for hours, but nothing came up.
I was hoping you could help me trace my problem. here's the code:
package com.reflecti0n.imri;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class MainMenu extends Activity implements View.OnClickListener {
ImageButton bStartGame, bHowToPlay, bQuitGame;
MediaPlayer soundtrack;
int counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setVar();
soundtrack = MediaPlayer.create(MainMenu.this, R.raw.soundtrack);
soundtrack.start();
bStartGame.setOnClickListener(this);
bHowToPlay.setOnClickListener(this);
bQuitGame.setOnClickListener(this);
}
public void setVar(){
bStartGame = (ImageButton) findViewById(R.id.bStart);
bHowToPlay = (ImageButton) findViewById(R.id.bHowTo);
bQuitGame = (ImageButton) findViewById(R.id.bQuit);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
}
}
Click to expand...
Click to collapse
the code is updated in the manifest as the 2nd activity class to work after the splash.
splash code:
package com.reflecti0n.imri;
import android.os.Bundle;
import android.content.Intent;
import android.app.Activity;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle Reflection) {
// TODO Auto-generated method stub
super.onCreate(Reflection);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent ourIntent = new Intent("com.reflecti0n.imri.MAINMENU");
startActivity(ourIntent);
}
}
};
timer.run();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
Click to expand...
Click to collapse
thanks alot!
Before digging into the code you need to be sure that your development environment was installed correctly by running Hello, World program (developer.android.com/resources/tutorials/hello-world.html).
So have you tried it first?
Sent from my GT-I9003 using Tapatalk
eduCoder said:
Before digging into the code you need to be sure that your development environment was installed correctly by running Hello, World program (developer.android.com/resources/tutorials/hello-world.html).
So have you tried it first?
Sent from my GT-I9003 using Tapatalk
Click to expand...
Click to collapse
Yes, I have tried it. I've been running several programs on my environment before I started writing this app...
The thing is according to Eclipse there's nothing wrong with the syntax, But when I try to run it, it crashes.
I've tried to isolate the problem, and when I remove the StartActivity to the MainMenu from the splash it runs the slash app w/o a problem.
I also double-checked the Manifest to make sure it's set correctly (splash is LAUNCHER/MAIN, mainmenu is DEFAULT/SPLASH).
Related
Hi All! I'm trying to create an always-op-top button/clickable-image which stays on top of all the windows all the time. The proof of concept is here http://www.appbrain.com/app/smart-taskbar-(sidebar)/com.smart.taskbar and here http://forum.xda-developers.com/showthread.php?t=865525 I'm following this example code http://android.git.kernel.org/?p=pl...6429aaa5ccf6ecf311dfb3af0f3ccbf5f8d29;hb=HEAD
I have been successful and have a running service now. The service displays some text on top left corner of screen all the time while user can freely interact with rest of apps in normal manner. What I'm doing is subclass ViewGroup and add it to root window manager with flag TYPE_SYSTEM_OVERLAY. Now I want to add a button/clickable-image in place of this text which can receive touch events on itself. I tried overriding "onTouchEvent" for the whole ViewGroup but it does not receive any event. How can I receive events only on certain parts of my always-on-top view group? Kindly suggest.
Code:
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class HUD extends Service {
HUDView mView;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_LONG).show();
mView = new HUDView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0,
// WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
// | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(getBaseContext(),"onDestroy", Toast.LENGTH_LONG).show();
if(mView != null)
{
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView);
mView = null;
}
}
}
class HUDView extends ViewGroup {
private Paint mLoadPaint;
public HUDView(Context context) {
super(context);
Toast.makeText(getContext(),"HUDView", Toast.LENGTH_LONG).show();
mLoadPaint = new Paint();
mLoadPaint.setAntiAlias(true);
mLoadPaint.setTextSize(10);
mLoadPaint.setARGB(255, 255, 0, 0);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText("Hello World", 5, 15, mLoadPaint);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//return super.onTouchEvent(event);
Toast.makeText(getContext(),"onTouchEvent", Toast.LENGTH_LONG).show();
return true;
}
}
Hello.
I am fighting with this,unfortunately it FC's for me,while using same code.
Can you please help me to solve the problem?
TomasNM said:
Hello.
I am fighting with this,unfortunately it FC's for me,while using same code.
Can you please help me to solve the problem?
Click to expand...
Click to collapse
Nevermind man.
After 3 weeks of waiting for some help,I did it myself.
Thank you...
TomasNM said:
Nevermind man.
After 3 weeks of waiting for some help,I did it myself.
Thank you...
Click to expand...
Click to collapse
How did you solve that problem???
I modified this:
http://www.pocketmagic.net/android-overlay-cursor/
Unfortunately,I didn't made it clickable(movable around the screen),so all dimensions and positions are hardcoded.
I can modify it for myself anytime and noone use my app.
Hello XDA,
So I've not found anyone properly discussing this. If they do, please link me to the page and don't flame
I've been making an app for my school and so far, I've been doing alright. But now I have run into a problem which seems to be very hard to solve for me alone.
Namely, I have an EditText and a Button in one Activity and a WebView as a different Activity.
I'm trying to get the EditText String into the WebView URL (String being variable, Button initiating the WebView), but get a lot of errors, some not even related to that.
I would really appreciate it if someone could have a look at the code and help me with this
MyWebView.java:
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebView extends Activity {
WebView mWebView;
EditText mEtxtStudentNum;
static String StudentNumFromHome = bas.sie.Antonius.Home.StudentNum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://carmelcollegegouda.nl/site_ant/roosters/standaardroosters/Lee1_" + StudentNumFromHome + ".htm");
}
}
Home.java (Homescreen):
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Home extends Activity {
Button mBtnStSchedule;
static EditText mEtxtStudentNum;
static final String StudentNum = mEtxtStudentNum.getText().toString();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.BtnStSchedule);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), MyWebView.class);
startActivityForResult(myIntent, 0);
}
});
// TODO Auto-generated method stub
}
}
AntoniusActivity.java (Main):
Code:
package bas.sie.Antonius;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
public class AntoniusActivity extends TabActivity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Home.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, External.class);
spec = tabHost.newTabSpec("external").setIndicator("External",
res.getDrawable(R.drawable.ic_tab_external))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Contact.class);
spec = tabHost.newTabSpec("contact").setIndicator("Contact",
res.getDrawable(R.drawable.ic_tab_contact))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
In AntoniusActivity, the private class HelloWebViewClient is underlined with yellow (never used), specifically the bit "HelloWebViewClient".
It's also throwing FC's at startup, and errors in LogCat, but I'll post those later on, as it's 10.30 PM here, and school goes on
Thanks in advance,
bassie1995
No suggestions yet?
How you doin'? Greetings from my GT-I9000!
I just started developing apps and I've come across the error: Void is an invalid type for the variable button1Click. I got the error on the following line of code
public void button1Click; {
It's in my java class, I'm trying to open an activity from another. This is my entire code looks like this
package trial.play;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
public class Food extends Activity implements View.OnClickListener {
Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.singer);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
public void button1Click; {
startActivity(new Intent("android.intent.action.TESTMENUACTIVITY"));}
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.button1:
button1Click: break;
}
}
public void Enter(View view) {
Intent openTestMenuActivity = (new Intent(
"trial.play.TESTMENUACTIVITY"));
startActivity(openTestMenuActivity);
}
}
I'm still new to development so be specific and show me what you mean if you can.
Thanks
Hi all, ive just started lookin up to Java and creating app, i know i should start and improove slowly, but i need quickly some helps with makin a Translator.apk using Bing API translator, cause google one are now only aviable if u pay them.
i saw a litle exemple where i downloaded the Jar file(which i put it in /libs and mine came out like this:
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
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;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
EditText in, out;
Button trns;
String inPut;
@Override
protected void onCreate() {
// TODO Auto-generated method stub
Translate.setClientId("hidden");
Translate.setClientSecret("hidden");
super.onCreate();
setContentView(R.layout.activity_main);
trns = (Button) findViewById(R.id.button1);
in = (EditText) findViewById(R.id.editText1);
out = (EditText) findViewById(R.id.editText2);
inPut = in.getText().toString();
trns.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
String translatedText = Translate.execute(inPut, Language.GERMAN,
Language.FRENCH);
out.setText(translatedText);
} catch (Exception e) {
e.printStackTrace();
}
}
}
problaby its all wrong i know, thats why i need help
Guess i have to add Internet permission to the manifest(how ? and do i have to make some controll after?)
I studied at school some basic C# so im used to the grouBox which i didnt find with eclipse. What's the nearest thing with it where i can put a list of all selectable language to translate?
Hope somebody could help me, ty
I'm developing a simple chat app and it just stops after transmitting the message. The Server shows the message that means that it is sent successfully but my app crashes after that. This is the Client code :
Code:
package com.example.androidpc;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Chat extends Activity {
Socket socket;
EditText msg_txt;
TextView chatfield_tv;
Button send_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
msg_txt = (EditText) findViewById(R.id.msg_txt);
chatfield_tv = (TextView) findViewById(R.id.chatfield_tv);
send_btn = (Button) findViewById(R.id.send_btn);
socket = SocketWrapper.getSocket();
send_btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new chatIO().execute();
}
});
}
private class chatIO extends AsyncTask<String,String,String>{
PrintStream ps;
Scanner scan;
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try {
ps = new PrintStream(socket.getOutputStream());
ps.println(msg_txt.getText().toString());
publishProgress("you");
scan = new Scanner(socket.getInputStream());
publishProgress("i");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(String... values) {
// TODO Auto-generated method stub
if(values[0].equals("you"))
{
chatfield_tv.append("You : "+msg_txt.getText().toString());
msg_txt.setText("");
}
else
{
chatfield_tv.append("Server : "+scan.nextLine());
}
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
ps.flush();
scan.close();
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.chat, 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);
}
}
I don't have a logcat since i don't test on an emulator or adb