| Autor |
Mensagem |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 22/01/2012 13:03:53
|
Durbano
What is classpath?
Membro desde: 22/01/2012 12:47:51
Mensagens: 5
Offline
|
Boa tarde,
Estou começando praticamente hoje a tentar desenvolver para Android. E preciso muito da ajuda de vocês.
Meu objetivo ainda está sendo entender sobre a plataforma de desenvolvimento e como funcionado a forma
procedural e declarativa.
Criei um textfield e 3 botões mas uso apenas 1, o objetivo é apenas digitar algo no textfield clicar no botão e aparecer um dialog com o título do valor do textfield, apenas isso.
Mas está ocorrendo um erro na aplicação.
CLASSE
public class AndroidProjectActivity extends Activity{
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
public void MostraMensagem() {
final EditText input1 = (EditText) findViewById(R.id.txtteste);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(input1.getText())
.setCancelable(false)
.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
}
}
MAIN.XML
<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/titulo"
/>
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/play_label"
android:onClick="MostraMensagem"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sobre_label"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sair_label"
/>
<EditText
android:id="@+id/txtteste"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
LOGCAT
01-22 16:45:30.233: W/KeyCharacterMap(213): No keyboard for id 0
01-22 16:45:30.243: W/KeyCharacterMap(213): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-22 16:46:06.583: D/AndroidRuntime(213): Shutting down VM
01-22 16:46:06.583: W/dalvikvm(213): threadid=3: thread exiting with uncaught exception (group=0x4001b18
01-22 16:46:06.583: E/AndroidRuntime(213): Uncaught handler: thread main exiting due to uncaught exception
01-22 16:46:06.614: E/AndroidRuntime(213): java.lang.IllegalStateException: Could not find a method MostraMensagem(View) in the activity
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.View$1.onClick(View.java:2020)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.View.performClick(View.java:2364)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.View.onTouchEvent(View.java:4179)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.widget.TextView.onTouchEvent(TextView.java:6541)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.View.dispatchTouchEvent(View.java:3709)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-22 16:46:06.614: E/AndroidRuntime(213): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-22 16:46:06.614: E/AndroidRuntime(213): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-22 16:46:06.614: E/AndroidRuntime(213): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.os.Looper.loop(Looper.java:123)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-22 16:46:06.614: E/AndroidRuntime(213): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 16:46:06.614: E/AndroidRuntime(213): at java.lang.reflect.Method.invoke(Method.java:521)
01-22 16:46:06.614: E/AndroidRuntime(213): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-22 16:46:06.614: E/AndroidRuntime(213): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:61
01-22 16:46:06.614: E/AndroidRuntime(213): at dalvik.system.NativeStart.main(Native Method)
01-22 16:46:06.614: E/AndroidRuntime(213): Caused by: java.lang.NoSuchMethodException: MostraMensagem
01-22 16:46:06.614: E/AndroidRuntime(213): at java.lang.ClassCache.findMethodByName(ClassCache.java:30
01-22 16:46:06.614: E/AndroidRuntime(213): at java.lang.Class.getMethod(Class.java:1014)
01-22 16:46:06.614: E/AndroidRuntime(213): at android.view.View$1.onClick(View.java:2017)
01-22 16:46:06.614: E/AndroidRuntime(213): ... 21 more
01-22 16:46:06.653: I/dalvikvm(213): threadid=7: reacting to signal 3
01-22 16:46:06.653: E/dalvikvm(213): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
|
|
|
 |
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 22/01/2012 14:35:36
|
abmpicoli
JavaTeenager
Membro desde: 27/07/2011 09:11:25
Mensagens: 164
Offline
|
Cara, num manjo nada de android (ainda), mas só de olhar o erro dá pra ver que o seu método aparentemente está com um erro de assinatura:
ava.lang.IllegalStateException: Could not find a method MostraMensagem(View) in the activity
Enquanto que o seu código é sem argumentos...
|
.x. |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 22/01/2012 15:01:28
|
fernandopaiva
GUJ Ranger
![[Avatar]](/images/avatar/3391f7714552ccfd36c887e27dee4842.jpg)
Membro desde: 20/03/2007 00:00:57
Mensagens: 974
Offline
|
coloque seus codigos entre a tag code
veja aqui.
Um exemplo simples, mas da pra vc ver como funciona..
t+ e boa sorte.
|
www.iguanasistemas.com.br
J2SE Developer
Acessem o canal de Java no Brasil
irc.freenode.net
#java-br
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 22/01/2012 15:05:49
|
fernandopaiva
GUJ Ranger
![[Avatar]](/images/avatar/3391f7714552ccfd36c887e27dee4842.jpg)
Membro desde: 20/03/2007 00:00:57
Mensagens: 974
Offline
|
aqui um exemplo do AlertDialog.
Outro exemplo simples tbm, mas da pra vc testar e ir assimilando como tudo funciona
t+ e boa sorte.
|
www.iguanasistemas.com.br
J2SE Developer
Acessem o canal de Java no Brasil
irc.freenode.net
#java-br
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 24/01/2012 22:31:19
|
Durbano
What is classpath?
Membro desde: 22/01/2012 12:47:51
Mensagens: 5
Offline
|
Tentei executar os exemplos acima mas ocorreu o mesmo problema...
ERRO
SORRY!
The application AndroidPrimeiroPrograma (process android.App) has stopped unexpectedly. Please try again
CLASSE
package android.App;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class AndroidProjectActivity extends Activity {
/** Called when the activity is first created. */
EditText txtteste;
EditText resultado;
Button btnPlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnPlay = (Button)findViewById(R.id.btnPlay);
txtteste = (EditText)findViewById(R.id.txtteste);
resultado = (EditText)findViewById(R.id.txtresultado);
btnPlay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
resultado.setText(txtteste.getText());
}
});
}
}
LAYOUT
<?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">
<EditText
android:id="@+id/txtresultado"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/btnPlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="MostraMensagem"
android:text="@string/play_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sobre_label"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sair_label"
/>
<EditText
android:id="@+id/txtteste"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
STRING
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, PrimeiroPrograma!</string>
<string name="play_label">Play</string>
<string name="sobre_label">About</string>
<string name="sair_label">Leave</string>
<string name="app_name">AndroidPrimeiroPrograma</string>
</resources>
LOG CAT
01-25 02:23:38.818: D/AndroidRuntime(271): Shutting down VM
01-25 02:23:38.818: W/dalvikvm(271): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-25 02:23:38.858: E/AndroidRuntime(271): FATAL EXCEPTION: main
01-25 02:23:38.858: E/AndroidRuntime(271): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.App/android.App.AndroidProjectActivity}: java.lang.ClassCastException: android.widget.EditText
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.os.Looper.loop(Looper.java:123)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-25 02:23:38.858: E/AndroidRuntime(271): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 02:23:38.858: E/AndroidRuntime(271): at java.lang.reflect.Method.invoke(Method.java:521)
01-25 02:23:38.858: E/AndroidRuntime(271): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:86
01-25 02:23:38.858: E/AndroidRuntime(271): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-25 02:23:38.858: E/AndroidRuntime(271): at dalvik.system.NativeStart.main(Native Method)
01-25 02:23:38.858: E/AndroidRuntime(271): Caused by: java.lang.ClassCastException: android.widget.EditText
01-25 02:23:38.858: E/AndroidRuntime(271): at android.App.AndroidProjectActivity.onCreate(AndroidProjectActivity.java:19)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-25 02:23:38.858: E/AndroidRuntime(271): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-25 02:23:38.858: E/AndroidRuntime(271): ... 11 more
01-25 02:26:13.908: I/Process(271): Sending signal. PID: 271 SIG: 9
This message was edited 1 time. Last update was at 24/01/2012 22:32:32
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 26/01/2012 06:24:49
|
A H Gusukuma
Thread.start()
Membro desde: 18/08/2011 18:36:18
Mensagens: 35
Offline
|
Olá.
Defina o seu MostraMensagem assim:
public void MostraMensagem(View v) {
...
}
|
Blog: http://agorandroid.blogspot.com.br/ |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 27/01/2012 22:55:41
|
Durbano
What is classpath?
Membro desde: 22/01/2012 12:47:51
Mensagens: 5
Offline
|
Deletei o método MostrarMensagem, agora estou tentando digitar algo em um textField, clicar em um botão e passar o valor para outro textfield. Não consigo nem isso !!! Alguém me ajuda
ERRO
SORRY!
The application AndroidPrimeiroPrograma (process android.App) has stopped unexpectedly. Please try again
CLASSE
package android.App;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class AndroidProjectActivity extends Activity {
/** Called when the activity is first created. */
EditText txtteste;
EditText resultado;
Button btnPlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnPlay = (Button)findViewById(R.id.btnPlay);
txtteste = (EditText)findViewById(R.id.txtteste);
resultado = (EditText)findViewById(R.id.txtresultado);
btnPlay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
resultado.setText(txtteste.getText());
}
});
}
}
MAIN.XML
<?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">
<EditText
android:id="@+id/txtresultado"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/btnPlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/play_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sobre_label"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sair_label"
/>
<EditText
android:id="@+id/txtteste"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
STRING.XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, PrimeiroPrograma!</string>
<string name="play_label">Play</string>
<string name="sobre_label">About</string>
<string name="sair_label">Leave</string>
<string name="app_name">AndroidPrimeiroPrograma</string>
</resources>
LOGCAT
01-28 02:46:39.397: D/AndroidRuntime(276): Shutting down VM
01-28 02:46:39.397: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-28 02:46:39.428: E/AndroidRuntime(276): FATAL EXCEPTION: main
01-28 02:46:39.428: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.App/android.App.AndroidProjectActivity}: java.lang.ClassCastException: android.widget.EditText
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-28 02:46:39.428: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 02:46:39.428: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
01-28 02:46:39.428: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:86
01-28 02:46:39.428: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-28 02:46:39.428: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)
01-28 02:46:39.428: E/AndroidRuntime(276): Caused by: java.lang.ClassCastException: android.widget.EditText
01-28 02:46:39.428: E/AndroidRuntime(276): at android.App.AndroidProjectActivity.onCreate(AndroidProjectActivity.java:19)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-28 02:46:39.428: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-28 02:46:39.428: E/AndroidRuntime(276): ... 11 more
This message was edited 1 time. Last update was at 27/01/2012 22:56:45
|
|
|
 |
|
|