gpt4 book ai didi

java - Android 中的 Onclick 功能

转载 作者:行者123 更新时间:2023-12-01 14:04:13 26 4
gpt4 key购买 nike

我正在尝试通过单击一个选项卡 Activity 来启动新的选项卡 Activity

我能够将内容加载到第一个 Activity ......但是照片按钮的 onclick 如其中一个类所示,出现错误,如日志中所示猫....

如何解决这个问题

任何想法

AndroidTabRestaurantDescListView.java

public class AndroidTabRestaurantDescListView extends TabActivity {

// TabSpec Names
private static final String INBOX_SPEC = "Rating";
private static final String OUTBOX_SPEC = "Price";
private static final String PROFILE_SPEC = "Distance";

Button Photos;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Photos=(Button) findViewById(R.id.PhotoButton);

TabHost tabHost = getTabHost();

// Inbox Tab
TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
Intent inboxIntent = new Intent(this, MainActivity.class);
inboxSpec.setIndicator(INBOX_SPEC);
// Tab Content
inboxSpec.setContent(inboxIntent);

// Outbox Tab
TabSpec PriceSpec = tabHost.newTabSpec(OUTBOX_SPEC);
Intent PriceIntent = new Intent(this, PriceDescriptionActivity.class);
PriceSpec .setIndicator(OUTBOX_SPEC);
PriceSpec.setContent(PriceIntent);

// Profile Tab
TabSpec DistanceSpec = tabHost.newTabSpec(PROFILE_SPEC);
Intent DistanceIntent = new Intent(this, DistanceDiscriptionActivity.class);
DistanceSpec .setIndicator(PROFILE_SPEC);
DistanceSpec.setContent(DistanceIntent);

// Adding all TabSpec to TabHost
tabHost.addTab(inboxSpec);
tabHost.addTab(PriceSpec);
tabHost.addTab(DistanceSpec);

//Set the current value tab to default first tab
tabHost.setCurrentTab(0);

//Setting custom height for the tabs
final int height = 45;
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;




Photos.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

Intent PhotoIntent=new Intent(AndroidTabRestaurantDescListView.this,AndroidTabRestaurantDescImageListView.class);
startActivity(PhotoIntent);

}
});

}

}

list

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbegin.jsonparsetutorial"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.project.findmybuffet.AndroidTabRestaurantDescListView" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.project.findmybuffet.SingleItemView" >
</activity>


<activity
android:name="com.project.findmybuffet.RestaurantDesc"
android:label="@string/app_name" >
</activity>

<activity
android:name="com.project.findmybuffet.RestaurantPhotos"
android:label="@string/app_name" >
</activity>


<activity
android:name="com.project.findmybuffet.DistanceDiscriptionActivity">
</activity>

<activity
android:name="com.project.findmybuffet.PriceDescriptionActivity">
</activity>

<activity
android:name="com.project.findmybuffet.MainActivity">
</activity>

<activity
android:name="com.project.findmybuffet.AndroidTabRestaurantDescImageListView">
</activity>

<activity
android:name="com.project.findmybuffet.DistanceDiscriptionOnlyImageActivity">
</activity>

<activity
android:name="com.project.findmybuffet.PriceDescriptionOnlyImageActivity">
</activity>

</application>

</manifest>

日志::

09-28 12:12:40.415: I/MemoryCache(1222): MemoryCache will use up to 8.0MB
09-28 12:12:40.875: D/dalvikvm(1222): GC_EXTERNAL_ALLOC freed 313K, 50% free 2967K/5895K, external 2130K/2137K, paused 119ms
09-28 12:12:40.925: I/MemoryCache(1222): cache size=47000 length=1
09-28 12:12:41.105: I/MemoryCache(1222): cache size=111500 length=2
09-28 12:12:41.245: I/MemoryCache(1222): cache size=179940 length=3
09-28 12:12:41.285: I/MemoryCache(1222): cache size=237060 length=4
09-28 12:12:48.255: D/AndroidRuntime(1222): Shutting down VM
09-28 12:12:48.255: W/dalvikvm(1222): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-28 12:12:48.287: E/AndroidRuntime(1222): FATAL EXCEPTION: main
09-28 12:12:48.287: E/AndroidRuntime(1222): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbegin.jsonparsetutorial/com.project.findmybuffet.AndroidTabRestaurantDescImageListView}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidbegin.jsonparsetutorial/com.project.findmybuffet.RatingDescriptionOnlyImageActivity}; have you declared this activity in your AndroidManifest.xml?
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.os.Looper.loop(Looper.java:123)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-28 12:12:48.287: E/AndroidRuntime(1222): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 12:12:48.287: E/AndroidRuntime(1222): at java.lang.reflect.Method.invoke(Method.java:507)
09-28 12:12:48.287: E/AndroidRuntime(1222): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-28 12:12:48.287: E/AndroidRuntime(1222): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-28 12:12:48.287: E/AndroidRuntime(1222): at dalvik.system.NativeStart.main(Native Method)
09-28 12:12:48.287: E/AndroidRuntime(1222): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidbegin.jsonparsetutorial/com.project.findmybuffet.RatingDescriptionOnlyImageActivity}; have you declared this activity in your AndroidManifest.xml?
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1457)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.widget.TabHost.setCurrentTab(TabHost.java:326)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.widget.TabHost.addTab(TabHost.java:216)
09-28 12:12:48.287: E/AndroidRuntime(1222): at com.project.findmybuffet.AndroidTabRestaurantDescImageListView.onCreate(AndroidTabRestaurantDescImageListView.java:44)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-28 12:12:48.287: E/AndroidRuntime(1222): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-28 12:12:48.287: E/AndroidRuntime(1222): ... 11 more

最佳答案

错误消息非常具有描述性:

Unable to find explicit activity class {com.androidbegin.jsonparsetutorial/com.project.findmybuffet.RatingDescriptionOnlyImageActivity}; have you declared this activity in your AndroidManifest.xml?

答案是:不,您尚未在 list 中声明该 Activity 。您的 list 中还有很多其他 Activity ,但没有那个 Activity 。

除了通过将 Activity 添加到 list 中来简单地解决此问题之外,我建议您退后一步,思考如何自己解决这个问题。您仔细阅读日志文件了吗?您是否错过了我引用的错误消息? (始终寻找“原因”异常消息。)学习如何自己诊断问题非常重要 - 所以看看你是否能找出这次没有完全达到目标的原因,以便你下次可以改进。

关于java - Android 中的 Onclick 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19064213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com