I'm having a simple problem with starting an intent on the click of a button. Unfortunately, i can't find a way out of this problem.
MY first activity java file is :
package com.android.SamsungMIv3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SamsungMIv3Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(SamsungMIv3Activity.this, currentlocation.class);
SamsungMIv3Activity.this.startActivity(i);
}
});
}
}
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"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:padding="10dp"
>
<Button
android:text="MY LOCATION"
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:padding="10dp"
>
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ENTER TEXT"
android:id="@+id/textView2">
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:padding="10dp"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/editText1"
android:inputType="textMultiLine">
<requestFocus></requestFocus>
</EditText>
</ScrollView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:padding="10dp"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="fill_parent"
android:paddingRight="20dp"
>
<Button
android:text="Camera"
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="fill_parent"
>
<Button
android:text="Search Location"
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:padding="10dp"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="fill_parent"
android:paddingRight="20dp"
>
<Button
android:text="Facebook"
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="fill_parent"
android:paddingRight="20dp"
>
<Button
android:text="Twitter"
android:id="@+id/button5"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Second activity java file :
package com.android.SamsungMIv3;
import android.os.Bundle;
import android.widget.TextView;
import com.google.android.maps.MapActivity;
public class currentlocation extends MapActivity {
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.currentlocation);
// TextView t = new TextView(this);
//t.setText("New Activity started");
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
second activity xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This works"
android:id="@+id/textView1"></TextView>
</LinearLayout>
manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.SamsungMIv3"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SamsungMIv3Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".currentlocation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Log Cat :
07-09 14:26:31.352: DEBUG/AndroidRuntime(821): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-09 14:26:31.362: DEBUG/AndroidRuntime(821): CheckJNI is ON
07-09 14:26:31.932: DEBUG/AndroidRuntime(821): --- registering native functions ---
07-09 14:26:32.852: DEBUG/ddm-heap(821): Got feature list request
07-09 14:26:33.912: DEBUG/PackageParser(58): Scanning package: /data/app/vmdl72937.tmp
07-09 14:26:33.942: WARN/PackageParser(58): No actions in intent filter at /data/app/vmdl72937.tmp Binary XML file line #20
07-09 14:26:34.202: INFO/PackageManager(58): Removing non-system package:com.android.SamsungMIv3
07-09 14:26:34.202: DEBUG/PackageManager(58): Removing package com.android.SamsungMIv3
07-09 14:26:34.222: DEBUG/PackageManager(58): Activities: com.android.SamsungMIv3.SamsungMIv3Activity com.android.SamsungMIv3.currentlocation
07-09 14:26:34.402: DEBUG/PackageManager(58): Scanning package com.android.SamsungMIv3
07-09 14:26:34.422: INFO/PackageManager(58): /data/app/vmdl72937.tmp changed; unpacking
07-09 14:26:34.452: DEBUG/installd(31): DexInv: --- BEGIN '/data/app/vmdl72937.tmp' ---
07-09 14:26:35.012: DEBUG/dalvikvm(827): DexOpt: load 91ms, verify 109ms, opt 8ms
07-09 14:26:35.062: DEBUG/installd(31): DexInv: --- END '/data/app/vmdl72937.tmp' (success) ---
07-09 14:26:35.072: DEBUG/PackageManager(58): Activities: com.android.SamsungMIv3.SamsungMIv3Activity com.android.SamsungMIv3.currentlocation
07-09 14:26:35.083: DEBUG/ActivityManager(58): Uninstalling process com.android.SamsungMIv3
07-09 14:26:35.332: INFO/installd(31): move /data/dalvik-cache/data@app@vmdl72937.tmp@classes.dex -> /data/dalvik-cache/data@app@com.android.SamsungMIv3.apk@classes.dex
07-09 14:26:35.358: DEBUG/PackageManager(58): New package installed in /data/app/com.android.SamsungMIv3.apk
07-09 14:26:35.562: DEBUG/AndroidRuntime(821): Shutting down VM
07-09 14:26:35.582: DEBUG/dalvikvm(821): DestroyJavaVM waiting for non-daemon threads to exit
07-09 14:26:35.605: DEBUG/dalvikvm(821): DestroyJavaVM shutting VM down
07-09 14:26:35.605: DEBUG/dalvikvm(821): HeapWorker thread shutting down
07-09 14:26:35.622: DEBUG/dalvikvm(821): HeapWorker thread has shut down
07-09 14:26:35.642: DEBUG/jdwp(821): JDWP shutting down net...
07-09 14:26:35.642: INFO/dalvikvm(821): Debugger has detached; object registry had 1 entries
07-09 14:26:35.662: DEBUG/dalvikvm(821): VM cleaning up
07-09 14:26:35.673: ERROR/AndroidRuntime(821): ERROR: thread attach failed
07-09 14:26:35.732: DEBUG/ActivityManager(58): Uninstalling process com.android.SamsungMIv3
07-09 14:26:35.842: DEBUG/dalvikvm(821): LinearAlloc 0x0 used 623012 of 5242880 (11%)
07-09 14:26:36.272: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f0700e5
07-09 14:26:36.286: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f020031
07-09 14:26:36.293: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f020030
07-09 14:26:36.302: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f050000
07-09 14:26:36.432: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f060001
07-09 14:26:36.602: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f060000
07-09 14:26:36.922: DEBUG/dalvikvm(105): GC freed 44 objects / 1752 bytes in 693ms
07-09 14:26:37.482: DEBUG/dalvikvm(58): GC freed 19390 objects / 1061480 bytes in 676ms
07-09 14:26:38.292: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f0700e5
07-09 14:26:38.312: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f020031
07-09 14:26:38.312: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f020030
07-09 14:26:38.322: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f050000
07-09 14:26:38.552: INFO/ActivityManager(58): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=833 uid=10019 gids={}
07-09 14:26:39.573: DEBUG/dalvikvm(58): GC freed 3548 objects / 181408 bytes in 1007ms
07-09 14:26:39.662: DEBUG/AndroidRuntime(832): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-09 14:26:39.712: DEBUG/AndroidRuntime(832): CheckJNI is ON
07-09 14:26:39.792: DEBUG/ddm-heap(833): Got feature list request
07-09 14:26:40.354: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f060001
07-09 14:26:40.722: WARN/ResourceType(58): Resources don't contain package for resource number 0x7f060000
07-09 14:26:41.133: DEBUG/AndroidRuntime(832): --- registering native functions ---
07-09 14:26:44.233: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.android.SamsungMIv3/.SamsungMIv3Activity }
07-09 14:26:44.372: DEBUG/AndroidRuntime(832): Shutting down VM
07-09 14:26:44.372: DEBUG/dalvikvm(832): DestroyJavaVM waiting for non-daemon threads to exit
07-09 14:26:44.393: DEBUG/dalvikvm(832): DestroyJavaVM shutting VM down
07-09 14:26:44.412: DEBUG/dalvikvm(832): HeapWorker thread shutting down
07-09 14:26:44.412: DEBUG/dalvikvm(832): HeapWorker thread has shut down
07-09 14:26:44.412: DEBUG/jdwp(832): JDWP shutting down net...
07-09 14:26:44.412: INFO/dalvikvm(832): Debugger has detached; object registry had 1 entries
07-09 14:26:44.432: DEBUG/dalvikvm(832): VM cleaning up
07-09 14:26:44.492: ERROR/AndroidRuntime(832): ERROR: thread attach failed
07-09 14:26:44.842: DEBUG/dalvikvm(832): LinearAlloc 0x0 used 637524 of 5242880 (12%)
07-09 14:26:45.762: DEBUG/ddm-heap(845): Got feature list request
07-09 14:26:45.963: INFO/ActivityManager(58): Start proc com.android.SamsungMIv3 for activity com.android.SamsungMIv3/.SamsungMIv3Activity: pid=845 uid=10032 gids={}
07-09 14:26:47.083: WARN/dalvikvm(845): Unable to resolve superclass of Lcom/android/SamsungMIv3/currentlocation; (17)
07-09 14:26:47.092: WARN/dalvikvm(845): Link of class 'Lcom/android/SamsungMIv3/currentlocation;' failed
07-09 14:26:47.102: ERROR/dalvikvm(845): Could not find class 'com.android.SamsungMIv3.currentlocation', referenced from method com.android.SamsungMIv3.SamsungMIv3Activity$1.onClick
07-09 14:26:47.112: WARN/dalvikvm(845): VFY: unable to resolve const-class 16 (Lcom/android/SamsungMIv3/currentlocation;) in Lcom/android/SamsungMIv3/SamsungMIv3Activity$1;
07-09 14:26:47.112: DEBUG/dalvikvm(845): VFY: replacing opcode 0x1c at 0x0004
07-09 14:26:47.112: DEBUG/dalvikvm(845): Making a copy of Lcom/android/SamsungMIv3/SamsungMIv3Activity$1;.onClick code (48 bytes)
07-09 14:26:47.752: INFO/ActivityManager(58): Displayed activity com.android.SamsungMIv3/.SamsungMIv3Activity: 3402 ms (total 3402 ms)
07-09 14:26:48.102: ERROR/gralloc(58): [unregister] handle 0x4a92b8 still locked (state=40000001)
07-09 14:26:51.414: DEBUG/AndroidRuntime(845): Shutting down VM
07-09 14:26:51.422: WARN/dalvikvm(845): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
07-09 14:26:51.432: ERROR/AndroidRuntime(845): Uncaught handler: thread main exiting due to uncaught exception
07-09 14:26:51.472: ERROR/AndroidRuntime(845): java.lang.NoClassDefFoundError: com.android.SamsungMIv3.currentlocation
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at com.android.SamsungMIv3.SamsungMIv3Activity$1.onClick(SamsungMIv3Activity.java:21)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.View.performClick(View.java:2364)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.View.onTouchEvent(View.java:4179)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.widget.TextView.onTouchEvent(TextView.java:6540)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.View.dispatchTouchEvent(View.java:3709)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.ViewGroup.dispatchTouchEvent(V开发者_运维百科iewGroup.java:884)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.os.Looper.loop(Looper.java:123)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at java.lang.reflect.Method.invoke(Method.java:521)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-09 14:26:51.472: ERROR/AndroidRuntime(845): at dalvik.system.NativeStart.main(Native Method)
07-09 14:26:51.542: INFO/Process(58): Sending signal. PID: 845 SIG: 3
07-09 14:26:51.553: INFO/dalvikvm(845): threadid=7: reacting to signal 3
07-09 14:26:51.602: INFO/dalvikvm(845): Wrote stack trace to '/data/anr/traces.txt'
07-09 14:26:53.502: DEBUG/dalvikvm(105): GC freed 2414 objects / 140960 bytes in 312ms
07-09 14:26:57.862: INFO/Process(845): Sending signal. PID: 845 SIG: 9
07-09 14:26:58.053: INFO/ActivityManager(58): Process com.android.SamsungMIv3 (pid 845) has died.
07-09 14:26:58.073: INFO/WindowManager(58): WIN DEATH: Window{44d6f5c0 com.android.SamsungMIv3/com.android.SamsungMIv3.SamsungMIv3Activity paused=false}
07-09 14:26:58.292: INFO/UsageStats(58): Unexpected resume of com.android.launcher while already resumed in com.android.SamsungMIv3
07-09 14:26:58.532: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 845 uid 10032
I understand that the loc cat points to an error at the line
Intent i = new Intent(...);
But I'm not able to find a way to resolve this problem
Your activity depends on MapActivity
, but you have not included these dependent classes in your app. See: "Unable to resolve superclass of Lcom/android/SamsungMIv3/currentlocation"
It seems that you manifest need too clarify that you'll use map lib
<uses-library android:name="com.google.android.maps" />
Try removing the following from your manifest.xml in the currentLocation activity:
<category android:name="android.intent.category.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /
There should only be one main and one launcher class. Perhaps that's it.
If you are using android studio try ./gradlew clean && ./gradlew build
Look for build.gradle in your application directory //build.gradle n check under dependencies whether ur file is included or not e.g dependencies { compile 'com.android.support:support-v13:18.0.0' }
I wanted to add support v-13 files so I added the same in compile path and same files
should be there in support library of SDK. e.g.
sdk/extras/android/support/v13/android-support-v13.jar
In eclipse, I think you have to look under JAVA-BUILD
path.
精彩评论