Thursday, 3 October 2013

how to resolve this in eclipse "org.apache.subversion.javahl.ClientException: No such host is known. "?

how to resolve this in eclipse
"org.apache.subversion.javahl.ClientException: No such host is known. "?

i want to compare with the latest from repository but i am facing this
type of exception in eclipse.
org.apache.subversion.javahl.ClientException: No such host is known.
svn: Unable to connect to a repository at URL
'svn://srv-svn/aman/trunk/workspace/module-web/src/main/java/com/abcdsystems/amanda/jems/web/viewmodel'
svn: Unknown hostname 'srv-svn'
so anybody can tell me how can resolve this issue in my eclipse ?
thanks

Wednesday, 2 October 2013

Negation bar meaning?

Negation bar meaning?

I know that the horizontal bar on top means it's a negation. But I've
never encountered one over more than one term like this one:
$\overline{\bar{x} + \bar{y}x}(y + \overline{xy})$
Is that equivalent to:
($\neg{(\bar{x} + \bar{y}x))}(y + \overline{xy})$ (the 2 first terms are
negated then they are multiplied by the two last terms)
or
$\neg{\bar{x}} + (\neg{\bar{y}x)}(y + \overline{xy})$ (the first two terms
are negated, but only the second term is multiplied by the two last terms)
or just.. something else?
Thanks!

on click doesn't work for element that has class added by jquery

on click doesn't work for element that has class added by jquery

I have a element that when a check box is checked a class is added and
removed from the element.. Now when the checkbox is checked the class is
added to correctly, however, the .on('click') handler for that element
with the class added to it is ignored. If I manually add the class to the
element then the .on('click') element is not ignored..
For instance..
When the checkbox is activated it adds the .delete class to the , however,
when the is clicked after the class was added through jquery..the below
code is never executed. However, it will work if the class was hard coded
in
$('a.delete').on('click',function(e){
e.preventDefault();
console.log('delete clicked');
});
Is it just not possible to put a on click event for a element with a class
that is added through addClass()? I feel like this is a simple problem ..

update progress bar using ajax request seconds

update progress bar using ajax request seconds

Basicaly, I'm performing an AJAX request for an external login system, how
can I update the progress bar based on the length of the request?
For example, the request takes between 1.30s to 1.40s to complete, how can
I update an progress bar based on certain intervals, like update it 10%
every 10ms or something, here's the HTML layout for the progress bar
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar" aria-valuenow="65"
aria-valuemin="0" aria-valuemax="100" style="width: 65%">
<span class="sr-only">65% Complete</span>
</div>
</div>
The length of the progress bar is determined using the width: 65% attribute
The idea is to basically get it to look like it's updating based on the
request so when the request is complete the percentage bar is full

Tuesday, 1 October 2013

Slider Puzzle problems

Slider Puzzle problems

This is my slider puzzle game. So far it can only do 3x3 games. When I try
and pass the variables l and w (length and width) of the board it doesn't
work. It only works when i set the variables ROWS and COLS as finals. When
I try and change it I get errors. I'm not sure what to do, any help would
be appreciated.
Currently the user can input values that can't do anything at the moment.
When the game is started, a 3x3 board is generated. The user can restart
the game with a different scrambled board but the buttons that solve the
board and the buttons that reset the board to the original state do not
work yet.
public class SlidePuzzle {
public static void main(String[] args)
{
JFrame window = new JFrame("Slide Puzzle");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String length = JOptionPane.showInputDialog("Length");
String width = JOptionPane.showInputDialog("Width");
int l = Integer.parseInt(length);
int w = Integer.parseInt(width);
window.setContentPane(new SlidePuzzleGUI());
window.pack();
window.show();
window.setResizable(false);
}
}
public class SlidePuzzleGUI extends JPanel
{
private GraphicsPanel _puzzleGraphics;
private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel();
This class contains the GUI for the Slider Puzzle
public SlidePuzzleGUI() {
JButton newGameButton = new JButton("New Game");
JButton resetButton = new JButton("Reset");
JButton solveButton = new JButton("I GIVE UP :(");
resetButton.addActionListener(new ResetAction());
newGameButton.addActionListener(new NewGameAction());
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.add(newGameButton);
controlPanel.add(resetButton);
controlPanel.add(solveButton);
_puzzleGraphics = new GraphicsPanel();
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.NORTH);
this.add(_puzzleGraphics, BorderLayout.CENTER);
}
This is the graphics panel
class GraphicsPanel extends JPanel implements MouseListener {
private static final int ROWS = 3;
private static final int COLS = 3;
private static final int CELL_SIZE = 80;
private Font _biggerFont;
public GraphicsPanel() {
_biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2);
this.setPreferredSize(
new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS));
this.setBackground(Color.black);
this.addMouseListener(this);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
int x = c * CELL_SIZE;
int y = r * CELL_SIZE;
String text = _puzzleModel.getFace(r, c);
if (text != null) {
g.setColor(Color.gray);
g.fillRect(x+2, y+2, CELL_SIZE-4, CELL_SIZE-4);
g.setColor(Color.black);
g.setFont(_biggerFont);
g.drawString(text, x+20, y+(3*CELL_SIZE)/4);
}
}
}
}
public void mousePressed(MouseEvent e) {
int col = e.getX()/CELL_SIZE;
int row = e.getY()/CELL_SIZE;
if (!_puzzleModel.moveTile(row, col)) {
Toolkit.getDefaultToolkit().beep();
}
this.repaint();
}
public void mouseClicked (MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
}
public class NewGameAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
_puzzleModel.reset();
_puzzleGraphics.repaint();
}
}
public class ResetAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
_puzzleModel.tryAgain();
_puzzleGraphics.repaint();
}
}
public class solveAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
_puzzleModel.solve();
_puzzleGraphics.repaint();
}
}
}
public class SlidePuzzleModel {
private static final int ROWS = 3;
private static final int COLS = 3;
private Tile[][] _contents;
private Tile[][] _solved;
private Tile _emptyTile;
public SlidePuzzleModel() {
_contents = new Tile[ROWS][COLS];
reset();
}
String getFace(int row, int col) {
return _contents[row][col].getFace();
}
public void reset() {
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
_contents[r][c] = new Tile(r, c, "" + (r*COLS+c+1));
}
}
_emptyTile = _contents[ROWS-1][COLS-1];
_emptyTile.setFace(null);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
exchangeTiles(r, c, (int)(Math.random()*ROWS)
, (int)(Math.random()*COLS));
}
}
}
public void tryAgain()
{
}
public void solve()
{
for (int i = 1; i < ROWS+1;i++)
{
for(int j = 1; j < COLS+1;j++)
{
exchangeTiles(i, j, i, j);
}
}
}
public boolean moveTile(int r, int c) {
return checkEmpty(r, c, -1, 0) || checkEmpty(r, c, 1, 0)
|| checkEmpty(r, c, 0, -1) || checkEmpty(r, c, 0, 1);
}
private boolean checkEmpty(int r, int c, int rdelta, int cdelta) {
int rNeighbor = r + rdelta;
int cNeighbor = c + cdelta;
if (isLegalRowCol(rNeighbor, cNeighbor)
&& _contents[rNeighbor][cNeighbor] == _emptyTile) {
exchangeTiles(r, c, rNeighbor, cNeighbor);
return true;
}
return false;
}
public boolean isLegalRowCol(int r, int c) {
return r>=0 && r<ROWS && c>=0 && c<COLS;
}
private void exchangeTiles(int r1, int c1, int r2, int c2) {
Tile temp = _contents[r1][c1];
_contents[r1][c1] = _contents[r2][c2];
_contents[r2][c2] = temp;
}
public boolean isGameOver() {
for (int r=0; r<ROWS; r++) {
for (int c=0; c<ROWS; c++) {
Tile trc = _contents[r][c];
return trc.isInFinalPosition(r, c);
}
}
return true;
}
}
class Tile {
private int _row;
private int _col;
private String _face;
public Tile(int row, int col, String face) {
_row = row;
_col = col;
_face = face;
}
public void setFace(String newFace) {
_face = newFace;
}
public String getFace() {
return _face;
}
public boolean isInFinalPosition(int r, int c) {
return r==_row && c==_col;
}
}
How would I make it so that the user can specify dimensions of the game
board?
EDIT public class SlidePuzzle {
public static void main(String[] args)
{
JFrame window = new JFrame("Slide Puzzle");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String length = JOptionPane.showInputDialog("Length");
String width = JOptionPane.showInputDialog("Width");
int l = Integer.parseInt(length);
int w = Integer.parseInt(width);
window.setContentPane(new SlidePuzzleGUI());
window.pack();
window.show();
window.setResizable(false);
}
} public class SlidePuzzleGUI extends JPanel {
private GraphicsPanel _puzzleGraphics;
private SlidePuzzleModel _puzzleModel = new SlidePuzzleModel();
public SlidePuzzleGUI(int l, int w) {
JButton newGameButton = new JButton("New Game");
JButton resetButton = new JButton("Reset");
JButton solveButton = new JButton("I GIVE UP :(");
resetButton.addActionListener(new ResetAction());
newGameButton.addActionListener(new NewGameAction());
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.add(newGameButton);
controlPanel.add(resetButton);
controlPanel.add(solveButton);
_puzzleGraphics = new GraphicsPanel(l,w);
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.NORTH);
this.add(_puzzleGraphics, BorderLayout.CENTER);
}
class GraphicsPanel extends JPanel implements MouseListener {
private int ROWS;
private int COLS;
private static final int CELL_SIZE = 80;
private Font _biggerFont;
public GraphicsPanel(int l, int w) {
_biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE/2);
this.setPreferredSize(
new Dimension(CELL_SIZE * COLS, CELL_SIZE*ROWS));
this.setBackground(Color.black);
this.addMouseListener(this);
ROWS = l;
COLS = w;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int r=0; r<ROWS; r++) {
for (int c=0; c<COLS; c++) {
int x = c * CELL_SIZE;
int y = r * CELL_SIZE;
String text = _puzzleModel.getFace(r, c);
if (text != null) {
g.setColor(Color.gray);
g.fillRect(x+2, y+2, CELL_SIZE-4, CELL_SIZE-4);
g.setColor(Color.black);
g.setFont(_biggerFont);
g.drawString(text, x+20, y+(3*CELL_SIZE)/4);
}
}
}
}
public void mousePressed(MouseEvent e) {
int col = e.getX()/CELL_SIZE;
int row = e.getY()/CELL_SIZE;
if (!_puzzleModel.moveTile(row, col)) {
Toolkit.getDefaultToolkit().beep();
}
this.repaint();
}
public void mouseClicked (MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited (MouseEvent e) {}
}
public class NewGameAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
_puzzleModel.reset();
_puzzleGraphics.repaint();
}
}
public class ResetAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
_puzzleModel.tryAgain();
_puzzleGraphics.repaint();
}
}
public class solveAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
_puzzleModel.solve();
_puzzleGraphics.repaint();
}
}
}

Overriding a pandas DataFrame column with dictionary values, where the dictionary keys match a non-index column?

Overriding a pandas DataFrame column with dictionary values, where the
dictionary keys match a non-index column?

I have a DataFrame df, and a dict d, like so:
>>> df
a b
0 5 10
1 6 11
2 7 12
3 8 13
4 9 14
>>> d = {6: 22, 8: 26}
For every key/val pair in the dictionary, I'd like to find the row where
column a matches the key, and override its b column with the value. For
example, in this particular case, the value of b in row 1 will change to
22, and its value on row 3 will change to 26.
How should I do that?

Support of ubuntu 13.04 [duplicate]

Support of ubuntu 13.04 [duplicate]

This question already has an answer here:
How does Ubuntu support work 4 answers
Ubuntu 13.04 receives 9 months of support. What's this SUPPORT? I mean is
it disadvantageous to use Ubuntu 13.04 then, & rather use the older Ubuntu
12.04??

getting connectivity error while deploying SSAS solution

getting connectivity error while deploying SSAS solution

Getting the error while deploying the solutions: The project could not be
deployed to the 'localhost' server because of the following connectivity
problems : A connection cannot be made. Ensure that the server is running.
To verify or update the name of the target server, right-click on the
project in Solution Explorer, select Project Properties, click on the
Deployment tab, and then enter the name of the server.
I have tried all the four impersonation options. My database is on network
and I'm deploying the soutions on my local machine.

Monday, 30 September 2013

Not able to wget to ftp server

Not able to wget to ftp server

I am trying to wget a ftp server from a remote machine. The command is not
getting past 'Logging in as anonymous'. This is what i am getting.
wget ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/chromosomes/chr1.fa.gz
--2013-09-29
22:07:53--
ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/chromosomes/chr1.fa.gz
=> 'chr1.fa.gz'
Resolving proxy.x.y.z... *.*.*.*
Connecting to proxy.x.y.z|*.*.*.*|:3128... connected.
Logging in as anonymous ...
When i try accessing the site by firefox from the remote machine, it works
fine. I have set my ftp proxy like this
export ftp_proxy="ftp://a.user:password@proxy:3128
Can anyone help me fix this problem?
Thanks

CDF of Euclidean distance between two points.

CDF of Euclidean distance between two points.

2-D plane, a circle $\text{C}_0$ of radius $R$ centered at $A(0,0)$, $N$
random points $D_i(x_i,y_i),i=1\dots N$ are independently uniformly
distributed in $\text{C}_0$.
Choose the point $D_s$ from $D_i$ which has the smallest Euclidean
distance to point $A$, i.e., $$s = \mathop{\arg\min}_{i=1\dots
N}\sqrt{x_i^2+y_i^2},\\ d_s=\min_{i=1\dots N}\sqrt{x_i^2+y_i^2}. $$
I know that the CDF of $d_s$ is
$$F_{d_s}(r)=1-\left(1-\frac{r^2}{R^2}\right)^N,0\leq r\leq R.$$
If there is another point $P(a,0),a>R$, the Euclidean distance from $D_s$
to $P$ is $$d_{sp}=\sqrt{(x_s-a)^2+y_s^2}.$$
How can I find the CDF or PDF of $d_{sp}$ ?
Thanks a lot!

How to compress/decompress strings in a userscript?

How to compress/decompress strings in a userscript?

I've been trying to figure out why a userscript I'm working on is slow in
Firefox yet blazing in Chrome and Safari. One reason I've identified
(though maybe not the only reason) is that the large file size of the
userscript is having a big effect. The script has ten book length strings
in it, for a file size of 3.8 MB. If I remove the strings the script gets
fast again---basically everything in the browser grinds to a halt while
the file loads (right at the time for a typical user input interaction).
So I was thinking it might help to precompress the strings, then
uncompress as needed during the run. Anyone have a strategy for doing this
within a userscript?

MDX Get last non empty value for EACH month

MDX Get last non empty value for EACH month

I need to get the last non empty value of Total Cost for EACH month.
M,P,R are parcel types, B is also a parcel type which i don't want to see.
I tried all kinds of codes, here is what i have now:
SELECT { [Measures].[Total Cost Price] } ON COLUMNS,
NON EMPTY {TAIL(NonEmptyCrossJoin([TimeDim].[Date].AllMembers,1),1) *
[Parcel Type].[Parcel Type ID].[Parcel Type ID].ALLMEMBERS ) } ON ROWS
FROM ( SELECT (-{ [Parcel Type].[Parcel Type ID].&[B] } ) ON COLUMNS
FROM [SomeDB])
It gives the following result:

Which is exactly what i need for September, 22/9/2013 is the last date in
September which holds data and the value is correct. But i need this for
each month, August etc.
Can anyone please suggest a solution? I use sql 2008

Sunday, 29 September 2013

When to use mutable vs immutable classes in Scala

When to use mutable vs immutable classes in Scala

Much is written about the advantages of immutable state, but are there
common cases in Scala where it makes sense to prefer mutable classes?
(This is a Scala newbie question from someone with a background in
"classic" OOP design using mutable classes.)
For something trivial like a 3-dimensional Point class, I get the
advantages of immutability. But what about something like a Motor class,
which exposes a variety of control variables and/or sensor readings? Would
a seasoned Scala developer typically write such a class to be immutable?
In that case, would 'speed' be represented internally as a 'val' instead
of a 'var', and the 'setSpeed' method return a new instance of the class?
Similarly, would every new reading from a sensor describing the motor's
internal state cause a new instance of Motor to be instantiated?
The "old way" of doing OOP in Java or C# using classes to encapsulate
mutable state seems to fit the Motor example very well. So I'm curious to
know if once you gain experience using the immutable-state paradigm, you
would even design a class like Motor to be immutable.

sql order by hardcoded values

sql order by hardcoded values

I have the following query:
select 'junior' as type, value
from mytable
union
select 'intermediate' as type, value
from mytable
union
select 'senior' as type, value
from mytable
Which returns the following data:
type value
Intermediate 10
Junior 5
Senior 1
I just need to reorder it so it looks like this
Junior 5
Intermediate 10
Senior 1
I can't figure out which order by clause to use to achieve ordering by
custom specific values, how would I achieve this?

Find a file Age In php

Find a file Age In php

I need to find the age of a file using php
for eg : i have abc.txt. I need to find how many days old.
ans: abc.txt is 20 day's old...
i have tried below code but i need only day's output
function humanTiming ($time)
{
// to get the time since that moment
$time = time() - $time;
// time unit constants
$timeUnits = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
// iterate over time contants to build a human
$humanTiming;
foreach ($timeUnits as $unit => $text)
{
if ($time < $unit)
continue;
$numberOfUnits = floor($time / $unit);
var_dump($humanTiming);
// human readable token for current time unit
$humanTiming = $humanTiming.' '.$numberOfUnits.'
'.$text.(($numberOfUnits>1)?'s':'');
// compute remaining time for next loop iteration
$time -= $unit*$numberOfUnits;
}
return $humanTiming;
}
$filename = 'H:\xampp\htdocs\doc\index.php';
if (file_exists($filename))
{
$time = strtotime('2010-04-28 17:25:43');
$time = filemtime($filename);
echo '<br/>File age is '.humanTiming($time).'.';
$elapsedTime = time()-filemtime($filename);
}

Query for distinct instance of model + one other field

Query for distinct instance of model + one other field

I have a model called Evaluation. When an evaluation is created, an
eval_number is created with it. There are many evaluations with the same
eval_number.
Here's an example:
- !ruby/object:Evaluation
attributes:
id: 2023
score: 3
created_at: 2013-09-08 13:10:53.000000000 Z
updated_at: 2013-09-08 13:10:53.000000000 Z
student_id: 26
goal_id: 50
eval_number: 33
- !ruby/object:Evaluation
attributes:
id: 2099
score: 4
created_at: 2013-09-08 13:19:12.000000000 Z
updated_at: 2013-09-08 13:19:12.000000000 Z
student_id: 26
goal_id: 36
eval_number: 34
- !ruby/object:Evaluation
attributes:
id: 2100
score: 3
created_at: 2013-09-08 13:19:12.000000000 Z
updated_at: 2013-09-08 13:19:12.000000000 Z
student_id: 26
goal_id: 37
eval_number: 34
- !ruby/object:Evaluation
attributes:
id: 2101
score: 4
created_at: 2013-09-08 13:19:12.000000000 Z
updated_at: 2013-09-08 13:19:12.000000000 Z
student_id: 26
goal_id: 38
eval_number: 34
In a view, I want to show the date that a given evaluation was created in
a table header. It should look like this:
date_1 | date_2 | date_3 | date_4 | etc..
To do this, I need to get distinct evaluation_numbers + the created_at
dates that go with them. I thought that this would help, but it's
returning more than one record per eval_number with this code:
def eval_date(i)
evals = self.goals.first.evaluations
eval = evals.select("distinct(eval_number), created_at").all[i]
eval.created_at.to_date
end
It seems like distinct eval_numbers are being selected, but also distinct
created_at columns (which of course are all different). This makes the
.all[i] basically useless as it's finding the [0], [1], [2], etc element
correctly - but there are far more than whatever the given number of i is
in the returned array.
I want to find a distinct eval_number and load only the created_date that
goes with it. I think I could load the whole record with all attributes,
but I don't need them, so I'd rather not.

Saturday, 28 September 2013

Difficulty in applying search optimization

Difficulty in applying search optimization

I have a 3D data vector and I need to do optimization such that I get the
minimum among all the data. Let the data be Z =
0.3 0.1 0.9
1.2 0.84 0.3
9.312 0.18 1.9
and so on. Z is generated by a function Z = f(a,b,c) ie by putting the
values of a,b,c into some equation. Then, for a particular set of (a,b,c)
Z is calculated. So, the way the algo works is that
Iteration 1 : I found out the L2 norm of Z and did random search. The
minima value along with the a,b,c which gave them are recorded.
At iteration 2: Another new set of a,b,c are used and Z is recalculated.
This continues till all a,b,c have been substituted in Z.
This process of random search takes a lot of computation time if the array
size is huge (5000 data points). Therefore, I wanted to apply Newton's
method On Z but I just cannot understand how to do it as there is no
functional form or equation representation. Can somebody please explain
with code how to apply optimization so that the search process is
optimized and a global single minima across all dimension is obtained.

How do I instantiate an object with fields from the parent class?

How do I instantiate an object with fields from the parent class?

I am trying to get an understanding of object oriented programming in Java
and I have this problem.
Say for example, I have a a parent class like this:
public class Shape {
private int location;
private Color color;
// methods such as getLocation() and getColor()
public Shape(int initialLocation, Color initialColor) {
location = initialLocation;
color = initialColor;
}
}
How do I make my child class so that I can construct, say, a rectangle
with an initial location and an initial color in a main method? Do I
create a constructor in the Rectangle class? I can't because location and
color are private fields. Do I create accessor methods for location and
color and just set the location and color after instantiation? I guess,
but is there a way to do this without accessors?
public class Rectangle extends Shape {
public Rectangle(int initialLocation, Color initialColor) {
super();
}
}
I just can't wrap my head around this fundamental concept. Any help?

Software for a small Library

Software for a small Library

Library Details a) Books (all books are single authored ones) b) Users –
faculty, staff, students
Book record format: · bookid, bookname, publisher, edition, author,
issued_to, date_of_issue User record format: · uid, uname, utype, gender,
contact
Operations on Books · issuance of a given book · renewal of a given book ·
books that are overdue (should display the bookids and the total number of
books overdue). · check status of a given book (available ? or issued, If
so to whom?) · deleting a given book (no further issuance is possible)
for issuing book: ISSUE BOOKID, USERID

unfortunately First App has stopped android-

unfortunately First App has stopped android-

i'm new in android and this is my first application i don't know why it
stoped ?? i use Nexus 4 emulator i think the problem in onClick but don't
know why when i delete in no problem accure
activity_main.xml
<LinearLayout 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:orientation="horizontal"
>
<EditText
android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="SendMessage"
/>
</LinearLayout>
MainActivity.java
package com.newthinktank.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE
="com.newthanktank.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sendMessage(View view){
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
LogCat:
09-28 10:52:31.686: E/AndroidRuntime(1584): FATAL EXCEPTION: main
09-28 10:52:31.686: E/AndroidRuntime(1584):
java.lang.IllegalStateException: Could not find a method SendMessage(View)
in the activity class com.newthinktank.myfirstapp.MainActivity for onClick
handler on view class android.widget.Button
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.view.View$1.onClick(View.java:3578)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.view.View.performClick(View.java:4084)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.view.View$PerformClick.run(View.java:16966)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.os.Handler.handleCallback(Handler.java:615)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.os.Handler.dispatchMessage(Handler.java:92)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.os.Looper.loop(Looper.java:137)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.app.ActivityThread.main(ActivityThread.java:4745)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
java.lang.reflect.Method.invokeNative(Native Method)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
java.lang.reflect.Method.invoke(Method.java:511)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
dalvik.system.NativeStart.main(Native Method)
09-28 10:52:31.686: E/AndroidRuntime(1584): Caused by:
java.lang.NoSuchMethodException: SendMessage [class android.view.View]
09-28 10:52:31.686: E/AndroidRuntime(1584): at
java.lang.Class.getConstructorOrMethod(Class.java:460)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
java.lang.Class.getMethod(Class.java:915)
09-28 10:52:31.686: E/AndroidRuntime(1584): at
android.view.View$1.onClick(View.java:3571)
09-28 10:52:31.686: E/AndroidRuntime(1584): ... 11 more