Does anyone know how to create a button which will help me to switch between tabs?
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {{
// Perform action on click
if (v.getId() == R.id.button1) {
setContentView(R.layout.tab3);
}
else if (v.getId() == R.id.button1) {
setContentView(R.layout.main);
}
}
}
});
}}
this is the code in my tab 1, this next code is the button in my tab.xml. i want to press the buy button below and i want it to go to another tab, is this possible?
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageButton1"
android:text="Buy"
android:onClick="tab3" />
this is my logcat file
01-05 16:04:20.903: D/dalvikvm(215): GC freed 806 objects / 70928 bytes in 96ms
01-05 15:30:29.072: D/AndroidRuntime(213): Shutting down VM
01-05 15:30:29.082: W/dalvikvm(213): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-05 15:30:29.082: E/AndroidRuntime(213): Uncaught handler: thread main exiting due to uncaught exception
01-05 15:30:29.132: E/AndroidRuntime(213): java.lang.IllegalStateException: Could not find a method tab3(View) in the activity
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View$1.onClick(View.java:2020)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View.performClick(View.java:2364)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View.onTouchEvent(View.java:4179)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.widget.TextView.onTouchEvent(TextView.java:6541)
01-05 15:30:29.132: E/AndroidRuntime(213): at android.view.View.dispatchTouchEvent(View.java:3709)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.os.Looper.loop(Looper.java:123)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.reflect.Method.invoke(Method.java:521)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-05 16:04:25.693: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-05 16:04:25.693: E/AndroidRuntime(215): at dalvik.system.NativeStart.main(Native Method)
01-05 16:04:25.693: E/AndroidRuntime(215): Caused by: java.lang.NoSuchMethodException: Tab3
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
01-05 16:04:25.693: E/AndroidRuntime(215): at java.lang.Class.getMethod(Class.java:1014)
01-05 16:04:25.693: E/AndroidRuntime(215): at android.view.View$1.onClick(View.java:2017)
01-05 16:04:25.693: E/AndroidRuntime(215): ... 25 more
01-05 16:04:25.733: I/dalvikvm(215): threadid=7: reacting to signal 3
01-05 16:04:25.733: I/dalvikvm(215): Wrote stack trace to '/data/anr/traces.txt'
01-05 16:04:27.505: I/Process(215): Sending signal. PID: 215 SIG: 9
+1 Midoalageb and +1 Mark Gjol have given you exactly what you need to switch the tab. What they are leaving out is the code for the event you are trying to do. What you need to do is set up a button on TAB1 that will have an onClick() listener that will call either getTabHost().setCurrentTabByTag(TAB2); or getTabHost().setCurrentTab(1);. Either one of those will work fine, just depends on how you want to do it.
Do you know how to do buttons and onClick() listeners? If not, google has some great examples. Just create a button in your tabView then set the onClick and then put your code in there for switching to the tab you want.
Another post that is very similar to this one that may help you out.
getTabHost().setCurrentTabByTag(TAB2);
This will look for the tab labeled "TAB2" and change to that tab.
getTabHost().setCurrentTab(1);
This will look for the tab with the index of "1" and change to that tab.
In regards to your xml
The xml files are mainly used to abstract defining your Views from the implementation of your Views. This allows you or other developers to provide different views to your code if needed. It helps provide a way to use the MVC pattern. However, this pattern is a little different in Android, but the xml file is most commonly considered the View in that pattern.
So Yes, if you are going to have multiple buttons they will need to be defined in your xml and implemented in your code.
In regards to your button dilema
The API for Button from google actually provides you with an example of this on the very front page. Keep in mind that Android is maturing very fast as a development platform and A LOT of this stuff is actually well documented already on line. The API documentation is also very good and gives great examples. Go by there and read it and you will most likely solve a lot of the more easy problems there.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is Tab1");
setContentView(textview);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
// perform the switch to tab event here for instance...
getTabHost().setCurrentTabByTag("TAB2");
}
});
}
When you create your tabs you give them a tag, let's store one such tag in the variable TAB_1. So in your onClick() method, you select that tab by:
getTabHost().setCurrentTabByTag(TAB_1);
Or, as midoalageb wrote, by index:
getTabHost().setCurrentTab(index);
Here is an explanation of Tab example :
Create a master Activity:
public class HelloTabWidget extends TabActivity
And create an Activity for each Tab:
public class ArtistsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview); // you replace this with your layout for each view
}
}
In the master Activity (HelloTabWidget), initiate a TabHost:
TabHost tabHost = getTabHost();
And add TabSpecs for each Tab you have:
intent = new Intent().setClass(this, ArtistsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
Select which Tab you need to be the default one:
tabHost.setCurrentTab(int index);
And finally your Button's onClickListener should be set in the Activity of the Tab containing the Button to:
intent = new Intent().setClass(this, ArtistsActivity.class);
startActivity(intent);
This Button should be present in all Tabs if you want it to switch between them.
Related
I downloaded a library called Android Maps Extensions from Github.
I can run the demo of this library in debugging mode, on my Samsung Note (GT-N7000) which runs Android 4.0.4.
If I click a button inside app, the app will stop and the screen will become black and after several seconds, and a dialog appears saying:
Unfortunately, Android Maps Extensions has stopped.
I am not sure what is happening. The logcat output can be seen below:
01-05 01:09:17.118: I/Process(24896): Sending signal. PID: 24896 SIG: 9
01-05 01:26:43.328: D/CLIPBOARD(27226): Hide Clipboard dialog at Starting input: finished by someone else... !
01-05 01:27:09.043: D/dalvikvm(27226): GC_CONCURRENT freed 56K, 2% free 14452K/14663K, paused 2ms+3ms
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.053: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.058: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.063: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.063: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.078: W/GooglePlayServicesUtil(27226): Certificate is not yet valid.
01-05 01:27:09.078: W/GooglePlayServicesUtil(27226): Google Play Store signature invalid.
01-05 01:27:09.078: D/AndroidRuntime(27226): Shutting down VM
01-05 01:27:09.078: W/dalvikvm(27226): threadid=1: thread exiting with uncaught exception (group=0x40c4f1f8)
01-05 01:27:09.083: E/AndroidRuntime(27226): FATAL EXCEPTION: main
01-05 01:27:09.083: E/AndroidRuntime(27226): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.mg6.android.maps.extensions.demo/pl.mg6.android.maps.extensions.demo.DemoActivity}: java.lang.NullPointerException
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.os.Looper.loop(Looper.java:137)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.main(ActivityThread.java:4511)
01-05 01:27:09.083: E/AndroidRuntime(27226): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 01:27:09.083: E/AndroidRuntime(27226): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 01:27:09.083: E/AndroidRuntime(27226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-05 01:27:09.083: E/AndroidRuntime(27226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-05 01:27:09.083: E/AndroidRuntime(27226): at dalvik.system.NativeStart.main(Native Method)
01-05 01:27:09.083: E/AndroidRuntime(27226): Caused by: java.lang.NullPointerException
01-05 01:27:09.083: E/AndroidRuntime(27226): at pl.mg6.android.maps.extensions.demo.DemoActivity.addCircles(DemoActivity.java:220)
01-05 01:27:09.083: E/AndroidRuntime(27226): at pl.mg6.android.maps.extensions.demo.DemoActivity.onCreate(DemoActivity.java:84)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.Activity.performCreate(Activity.java:4470)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-05 01:27:09.083: E/AndroidRuntime(27226): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-05 01:27:09.083: E/AndroidRuntime(27226): ... 11 more
When I run my android UIAutomator code, it shows following error.
INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=com.android.ui.testing
INSTRUMENTATION_CODE: 0
I just ran the sample code given in developer.android.com
How to solve this error?
Log attached below:
01-05 01:07:53.559: D/AndroidRuntime(5712): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-05 01:07:53.559: D/AndroidRuntime(5712): CheckJNI is ON
01-05 01:07:53.559: E/AndroidRuntime(5712): cannot open customer xml file
01-05 01:07:53.559: E/AndroidRuntime(5712): /system/csc/customer.xml can't open file
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: start
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: already setted!!
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: end
01-05 01:07:53.589: D/dalvikvm(5712): Trying to load lib libjavacore.so 0x0
01-05 01:07:53.599: D/dalvikvm(5712): Added shared lib libjavacore.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Trying to load lib libnativehelper.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Added shared lib libnativehelper.so 0x0
01-05 01:07:53.664: I/dalvikvm(5712): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
01-05 01:07:53.874: D/dalvikvm(5712): Note: class Landroid/app/ActivityManagerNative; has 152 unimplemented (abstract) methods
01-05 01:07:53.924: D/AndroidRuntime(5712): Calling main entry com.android.commands.uiautomator.Launcher
01-05 01:07:53.934: D/AndroidRuntime(5712): Shutting down VM
01-05 01:07:53.934: W/dalvikvm(5712): threadid=1: thread exiting with uncaught exception (group=0x40ffa2a0)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): uncaught exception
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): java.lang.RuntimeException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:95)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:82)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at dalvik.system.NativeStart.main(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): Caused by: java.lang.ClassNotFoundException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:71)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.TestCaseCollector.addTestClasses(TestCaseCollector.java:52)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:92)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): ... 6 more
01-05 01:07:53.944: I/AndroidRuntime(5712): VM exiting with result code -1.
If you get a ClassNotFindException while running your uiautomator tests :
Some of us my get this error because their ROM puts the folder /data/dalvik-cache in read-only mode. That happened to me with Cyanogen for a S3.
In that case type, in bash :
adb shell
su
chmod 777 /data/dalvik-cache
exit
rerun your tests and that should work. As dalvik-cache is locked for apps, uiautomator can't ask dalvik to unzip the jar of your tests and dalvik won't find the its classes.
See if removing the #UiThreadTest annotation or removing the runOnUiThread() call or re-factoring your tests work. But without a logcat, difficult to understand where it's coming from.
Had the same problem. Most demos I've seen indicate to install the jar to /data/local/tmp/. I've seen others indicate to try and install it to your sd card (/storage/sdcard0). After doing that it worked. Seems to be a problem with read permissions.
I solved this error by using"ant build" to create my jar.If u use export in eclipse to create a jar file, there might be some errors in the resulting class file, hence the above class not found error.
I am trying to write my first Android app, and I'm having trouble. I wrote a simple Java program to find the factors of a number provided by the user, and I'd like to port it over to Java. I have an XML file for the interface, which seemed to run OK until I added the first Java class. Now it won't run, and log.cat says that there's a null pointer exception. So far, I only have stubs, but it seems like it should run OK with what I've done to this point. I'm including the log.cat text, but I'm too new it this to make much sense out of it.
There may be more than one problem. After adding the Java file I began to get run-time errors right away, but I don't think they were null pointer exceptions. I think that started when I made changes to fix what was already causing problems.
Any help is appreciated.
Here is the Java file:
import android.app.Activity; <br>
import android.os.Bundle; <br>
import android.widget.Button; <br>
import android.widget.EditText; <br>
import android.widget.TextView; <br>
public class AndroidFactoringActivity extends Activity {
// Instance Variables
EditText userNumber;
Button factorButton;
TextView resultsField;
int factorResults;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
factorButton = (Button) findViewById(R.id.factorButton);
userNumber = (EditText) findViewById(R.id.userNumber);
factorResults = 1;
resultsField.setText(String.valueOf(factorResults));
}
}
Here is 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" >
<TextView
android:id="#+id/askField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/ask"
android:textSize="24dp" />
<EditText
android:id="#+id/userNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/factorButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/click" />
<TextView
android:id="#+id/resultsField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/tell"
android:textSize="24dp" />
</LinearLayout>
Here are the log.cat results:
03-31 23:58:53.579: D/AndroidRuntime(2804): Shutting down VM
03-31 23:58:53.589: W/dalvikvm(2804): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-31 23:58:53.589: E/AndroidRuntime(2804): Uncaught handler: thread main exiting due to uncaught exception
03-31 23:58:53.650: E/AndroidRuntime(2804): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.dave_b.factoring/net.dave_b.factoring.AndroidFactoringActivity}: java.lang.NullPointerException
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.os.Handler.dispatchMessage(Handler.java:99)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.os.Looper.loop(Looper.java:123)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-31 23:58:53.650: E/AndroidRuntime(2804): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 23:58:53.650: E/AndroidRuntime(2804): at java.lang.reflect.Method.invoke(Method.java:521)
03-31 23:58:53.650: E/AndroidRuntime(2804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-31 23:58:53.650: E/AndroidRuntime(2804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-31 23:58:53.650: E/AndroidRuntime(2804): at dalvik.system.NativeStart.main(Native Method)
03-31 23:58:53.650: E/AndroidRuntime(2804): Caused by: java.lang.NullPointerException
03-31 23:58:53.650: E/AndroidRuntime(2804): at net.dave_b.factoring.AndroidFactoringActivity.onCreate(AndroidFactoringActivity.java:26)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-31 23:58:53.650: E/AndroidRuntime(2804): ... 11 more
03-31 23:58:53.679: I/dalvikvm(2804): threadid=7: reacting to signal 3
03-31 23:58:53.679: E/dalvikvm(2804): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
03-31 23:59:57.629: I/Process(2804): Sending signal. PID: 2804 SIG: 9
04-01 00:07:36.129: D/AndroidRuntime(3040): Shutting down VM
04-01 00:07:36.129: W/dalvikvm(3040): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-01 00:07:36.139: E/AndroidRuntime(3040): Uncaught handler: thread main exiting due to uncaught exception
04-01 00:07:36.159: E/AndroidRuntime(3040): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.dave_b.factoring/net.dave_b.factoring.AndroidFactoringActivity}: java.lang.NullPointerException
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.os.Looper.loop(Looper.java:123)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-01 00:07:36.159: E/AndroidRuntime(3040): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 00:07:36.159: E/AndroidRuntime(3040): at java.lang.reflect.Method.invoke(Method.java:521)
04-01 00:07:36.159: E/AndroidRuntime(3040): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-01 00:07:36.159: E/AndroidRuntime(3040): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-01 00:07:36.159: E/AndroidRuntime(3040): at dalvik.system.NativeStart.main(Native Method)
04-01 00:07:36.159: E/AndroidRuntime(3040): Caused by: java.lang.NullPointerException
04-01 00:07:36.159: E/AndroidRuntime(3040): at net.dave_b.factoring.AndroidFactoringActivity.onCreate(AndroidFactoringActivity.java:26)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-01 00:07:36.159: E/AndroidRuntime(3040): ... 11 more
04-01 00:07:36.199: I/dalvikvm(3040): threadid=7: reacting to signal 3
04-01 00:07:36.199: E/dalvikvm(3040): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
04-01 00:07:40.329: I/Process(3040): Sending signal. PID: 3040 SIG: 9
resultsField.setText(String.valueOf(factorResults));
resultsField is null and you are trying to set value on null.
resultsField= (TextView ) findViewById(R.id.userNumber);
Get textview instance before setting value, otherwise resultsField will be null and all operations on null reference results in NullPointerException.
You got a null pointer because you didnt intialise the variable resultsField (you just declared it) .
As you used
userNumber = (EditText) findViewById(R.id.userNumber);
you must even initialise the reference resultsField.
This can be done using
resultsField= (TextView ) findViewById(R.id.resultsField);
in the onCreate() after the statement setContentView()
You need to initialize the userNumer and resultsFiled as follows
userNumber = (EditText) findViewById(R.id.userNumber);
resultsField= (TextView ) findViewById(R.id.resultsField);
Two days ago, when my android project in eclipse still worked, I added "android SDK 4.0.3" to my SDKs (in addition to android SDK 2.1).
From that moment on, I have a trouble with slf4j-android library; here's the exception:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1479)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at it.cefriel.swa.urbanopoly.client.game.UrbanopolyActivity.<clinit>(UrbanopolyActivity.java:11)
The JAR I use is slf4j-android-1.5.8.jar. The build path seems correctly setted. I also tried to create another project using slf4j and I got the same error..
Any Ideas?
Thanks in advance
Try adding the slf4j-api-1.5.8.jar or latest version as well with the current slf4j-android-1.5.8.jar
I coded a Dialog that shows up with 2 textviews and 2 buttons.
I googled for that Problem as well but I didn't find anything that mathced my issue.
Here is some Code:
case R.id.open:
openDialog=new Dialog(this);
openDialog.setContentView(R.layout.open_dialog);
openDialog.setTitle(head);
openDialog.setCancelable(true);
Button open_cancel=(Button)findViewById(R.id.open_cancel);
open_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
openDialog.cancel();
}
});
but I can't show the dialog up with the buttons.
If I call it without these Lines there is no Problem:
Button open_cancel=(Button)findViewById(R.id.open_cancel);
open_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
openDialog.cancel();
}
});
This is the XML File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/open_dialog"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<EditText android:id="#+id/open_head"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="ojfpojew ojr pojr"
/>
<EditText android:id="#+id/open_note"
android:layout_width="fill_parent"
android:text="oijpojepojpotjpotejpe ojtpojtpo ewpoj tpojt pp jpojtpoj etpoj poj poj t"
android:layout_height="150dp"
/>
<Button android:id="#+id/open_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="edit"
/>
<Button android:id="#+id/open_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cancel"
/>
</LinearLayout>
I really do not understand why this not works...
here is the error log, if it helps:
01-05 16:43:51.004: D/dalvikvm(2336): GC freed 1010 objects / 70136 bytes in 75ms
01-05 16:43:51.204: D/dalvikvm(2336): GC freed 91 objects / 3664 bytes in 53ms
01-05 16:43:51.494: D/dalvikvm(2336): GC freed 132 objects / 6240 bytes in 62ms
01-05 16:43:51.674: D/dalvikvm(2336): GC freed 58 objects / 2312 bytes in 56ms
01-05 16:43:51.944: D/dalvikvm(2336): GC freed 147 objects / 9128 bytes in 63ms
01-05 16:43:52.383: D/ViewFlipper(2336): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
01-05 16:44:00.973: D/dalvikvm(2336): GC freed 25495 objects / 1393728 bytes in 88ms
01-05 16:44:02.644: D/dalvikvm(2336): GC freed 45722 objects / 2044568 bytes in 102ms
01-05 16:44:04.424: I/Resources(2336): Loaded time zone names for en in 1591ms.
01-05 16:44:06.834: D/dalvikvm(2336): GC freed 36788 objects / 1674624 bytes in 102ms
01-05 16:44:11.243: D/AndroidRuntime(2336): Shutting down VM
01-05 16:44:11.263: W/dalvikvm(2336): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-05 16:44:11.263: E/AndroidRuntime(2336): Uncaught handler: thread main exiting due to uncaught exception
01-05 16:44:11.273: E/AndroidRuntime(2336): java.lang.NullPointerException
01-05 16:44:11.273: E/AndroidRuntime(2336): at producteev.push.Producteev_pushActivity.onContextItemSelected(Producteev_pushActivity.java:247)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.app.Activity.onMenuItemSelected(Activity.java:2174)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2731)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:129)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:884)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.widget.ListView.performItemClick(ListView.java)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.os.Handler.handleCallback(Handler.java:587)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.os.Looper.loop(Looper.java:123)
01-05 16:44:11.273: E/AndroidRuntime(2336): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-05 16:44:11.273: E/AndroidRuntime(2336): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 16:44:11.273: E/AndroidRuntime(2336): at java.lang.reflect.Method.invoke(Method.java:521)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-05 16:44:11.273: E/AndroidRuntime(2336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-05 16:44:11.273: E/AndroidRuntime(2336): at dalvik.system.NativeStart.main(Native Method)
01-05 16:44:11.293: I/dalvikvm(2336): threadid=7: reacting to signal 3
01-05 16:44:11.323: I/dalvikvm(2336): Wrote stack trace to '/data/anr/traces.txt'
01-05 16:44:13.383: I/Process(2336): Sending signal. PID: 2336 SIG: 9
Try this,
Button open_cancel=(Button)openDialog.findViewById(R.id.open_cancel);