我有一个问题,我正在处理三天,我试图阅读不同的答案,但它没有帮助。 也有人可以帮助我! 我将Ancdroid应用程序作为客户端编写为一个安静的Web服务。我可以从数据库中获取数据而没有问题,但我的问题是我使用的2个活动来处理来自数据库的这个文件。
主要活动
public class MainActivity extends Activity {
private static final String SERVICE_URL = "http://10.0.2.2:8080/.....";
private static final String TAG = "AndroidRESTClientActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void retrieveSampleData(View vw) {
EditText idTxt = (EditText) findViewById(R.id.id_textfield);
String id = idTxt.getText().toString();
String sampleURL = SERVICE_URL +"daten/"+id ;
Log.d("getrespond()", "service calling");
String url =sampleURL;
RestClient client = new RestClient(url);
try{
client.Execute(RestClient.RequestMethod.GET,this.getApplicationContext());
}
catch (Exception e) {
String error = String.valueOf(e);
Log.d("**********client.Execute(RequestMethod.GET);***********",error);
}
try {
if(client.getResponseCode() == 200) {
Log.d("Response is 200", String.valueOf(client.getResponse().length()));
System.out.println(this.getFilesDir().getPath().toString());
File daten= client.getResponse();
System.out.println(daten.getName());
Toast.makeText(this.getApplicationContext(), "Responce is "+String.valueOf(client.getResponseCode()), 2000).show();
} else {
String error = String.valueOf(client.getResponse());
Log.d("Response*********** not 200 ************", String.valueOf(client.getResponse()));
}
}catch (Exception e) {
e.printStackTrace();
Log.d("EXCEPTIONI IS 3", e.toString());
// TODO: handle exception
}
startActivity(new Intent("android.intent.action.LINEGRAPH"));
我从主要开始的另一项活动:
public class lineGraph extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_line_graph);
}
@Override
protected void onResume() {
super.onResume();
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
try {
mChartView = ChartFactory.getLineChartView(this, getDemoDataset(),
getDemoRenderer());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
layout.addView(mChartView, new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
} else {
mChartView.repaint();
}
}
的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.praktikum.androidcrestclient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.praktikum.androidcrestclient.LineGraph"
android:label="@string/title_activity_line_graph" >
<intent-filter>
<action android:name="android.intent.action.LINEGRAPH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="org.achartengine.GraphicalActivity"/>
</application>
</manifest>
这里是我的LogCat
10-08 09:23:10.140: D/AndroidRuntime(4706): Shutting down VM
10-08 09:23:10.140: W/dalvikvm(4706): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-08 09:23:10.161: E/AndroidRuntime(4706): FATAL EXCEPTION: main
10-08 09:23:10.161: E/AndroidRuntime(4706): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.praktikum.androidcrestclient/com.praktikum.androidcrestclient.LineGraph}: java.lang.ClassNotFoundException: com.praktikum.androidcrestclient.LineGraph in loader dalvik.system.PathClassLoader[/data/app/com.praktikum.androidcrestclient-1.apk]
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.os.Looper.loop(Looper.java:123)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-08 09:23:10.161: E/AndroidRuntime(4706): at java.lang.reflect.Method.invokeNative(Native Method)
10-08 09:23:10.161: E/AndroidRuntime(4706): at java.lang.reflect.Method.invoke(Method.java:507)
10-08 09:23:10.161: E/AndroidRuntime(4706): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-08 09:23:10.161: E/AndroidRuntime(4706): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-08 09:23:10.161: E/AndroidRuntime(4706): at dalvik.system.NativeStart.main(Native Method)
10-08 09:23:10.161: E/AndroidRuntime(4706): Caused by: java.lang.ClassNotFoundException: com.praktikum.androidcrestclient.LineGraph in loader dalvik.system.PathClassLoader[/data/app/com.praktikum.androidcrestclient-1.apk]
10-08 09:23:10.161: E/AndroidRuntime(4706): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-08 09:23:10.161: E/AndroidRuntime(4706): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-08 09:23:10.161: E/AndroidRuntime(4706): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-08 09:23:10.161: E/AndroidRuntime(4706): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
10-08 09:23:10.161: E/AndroidRuntime(4706): ... 11 more
10-08 09:23:10.180: W/ActivityManager(89): Force finishing activity com.praktikum.androidcrestclient/.LineGraph
10-08 09:23:10.180: W/ActivityManager(89): Force finishing activity com.praktikum.androidcrestclient/.MainActivity
10-08 09:23:10.690: W/ActivityManager(89): Activity pause timeout for HistoryRecord{4094eea0 com.praktikum.androidcrestclient/.LineGraph}
10-08 09:23:12.330: I/Process(4706): Sending signal. PID: 4706 SIG: 9
10-08 09:23:12.350: I/ActivityManager(89): Process com.praktikum.androidcrestclient (pid 4706) has died.
10-08 09:23:12.360: E/InputDispatcher(89): channel '4065ae98 com.praktikum.androidcrestclient/com.praktikum.androidcrestclient.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
10-08 09:23:12.360: E/InputDispatcher(89): channel '4065ae98 com.praktikum.androidcrestclient/com.praktikum.androidcrestclient.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
10-08 09:23:12.490: I/WindowManager(89): WIN DEATH: Window{4065ae98 com.praktikum.androidcrestclient/com.praktikum.androidcrestclient.MainActivity paused=true}
10-08 09:23:12.500: I/WindowManager(89): WIN DEATH: Window{406c1140 Toast paused=false}
10-08 09:23:12.600: W/InputManagerService(89): Got RemoteException sending setActive(false) notification to pid 4706 uid 10034
10-08 09:23:12.660: E/InputDispatcher(89): Received spurious receive callback for unknown input channel. fd=168, events=0x8
10-08 09:23:16.820: D/dalvikvm(396): GC_EXPLICIT freed 7K, 54% free 2537K/5511K, external 1625K/2137K, paused 43ms
10-08 09:23:21.626: W/ActivityManager(89): Activity destroy timeout for HistoryRecord{4094e768 com.praktikum.androidcrestclient/.MainActivity}
10-08 09:23:21.626: W/ActivityManager(89): Activity destroy timeout for HistoryRecord{4094eea0 com.praktikum.androidcrestclient/.LineGraph}
10-08 09:23:21.900: D/dalvikvm(299): GC_EXPLICIT freed 12K, 55% free 2589K/5703K, external 1625K/2137K, paused 73ms
10-08 09:23:26.950: D/dalvikvm(407): GC_EXPLICIT freed 4K, 55% free 2532K/5511K, external 1625K/2137K, paused 57ms
10-08 09:24:54.097: D/SntpClient(89): request time failed: java.net.SocketException: Address family not supported by protocol
10-08 09:29:54.106: D/SntpClient(89): request time failed: java.net.SocketException: Address family not supported by protocol
10-08 09:34:54.130: D/SntpClient(89): request time failed: java.net.SocketException: Address family not supported by protocol
你能帮我找一下为什么它找不到这个其他的活动。
谢谢
答案 0 :(得分:4)
在此声明中将班级名称更改为“LineGraph”而不是“lineGraph”:
public class LineGraph extends Activity{
答案 1 :(得分:4)
更改清单文件中的活动声明。
<Activity name="com.praktikum.androidcrestclient.LineGraph">
^^^^^^^^^
答案 2 :(得分:0)
停止即时运行解决了我的问题